Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -20,11 +20,11 @@ ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.537 2009/05/06 18:42:21 drh Exp $ +** $Id: build.c,v 1.538 2009/05/11 20:53:29 drh Exp $ */ #include "sqliteInt.h" /* ** This routine is called when a new SQL statement is beginning to @@ -340,10 +340,11 @@ /* ** Reclaim the memory used by an index */ static void freeIndex(Index *p){ sqlite3 *db = p->pTable->dbMem; + testcase( db==0 ); sqlite3DbFree(db, p->zColAff); sqlite3DbFree(db, p); } /* @@ -468,10 +469,11 @@ */ static void sqliteResetColumnNames(Table *pTable){ int i; Column *pCol; sqlite3 *db = pTable->dbMem; + testcase( db==0 ); assert( pTable!=0 ); if( (pCol = pTable->aCol)!=0 ){ for(i=0; inCol; i++, pCol++){ sqlite3DbFree(db, pCol->zName); sqlite3ExprDelete(db, pCol->pDflt); @@ -498,10 +500,11 @@ FKey *pFKey, *pNextFKey; sqlite3 *db; if( pTable==0 ) return; db = pTable->dbMem; + testcase( db==0 ); /* Do not delete the table until the reference count reaches zero. */ pTable->nRef--; if( pTable->nRef>0 ){ return; @@ -652,11 +655,11 @@ Token **pUnqual /* Write the unqualified object name here */ ){ int iDb; /* Database holding the object */ sqlite3 *db = pParse->db; - if( pName2 && pName2->n>0 ){ + if( ALWAYS(pName2!=0) && pName2->n>0 ){ if( db->init.busy ) { sqlite3ErrorMsg(pParse, "corrupt database"); pParse->nErr++; return -1; } @@ -817,12 +820,12 @@ } pTable->zName = zName; pTable->iPKey = -1; pTable->pSchema = db->aDb[iDb].pSchema; pTable->nRef = 1; - pTable->dbMem = db->lookaside.bEnabled ? db : 0; - if( pParse->pNewTable ) sqlite3DeleteTable(pParse->pNewTable); + pTable->dbMem = 0; + assert( pParse->pNewTable==0 ); pParse->pNewTable = pTable; /* If this is the magic sqlite_sequence table used by autoincrement, ** then record a pointer to this table in the main database structure ** so that INSERT can find the table easily. @@ -974,14 +977,13 @@ ** been seen on a column. This routine sets the notNull flag on ** the column currently under construction. */ void sqlite3AddNotNull(Parse *pParse, int onError){ Table *p; - int i; - if( (p = pParse->pNewTable)==0 ) return; - i = p->nCol-1; - if( i>=0 ) p->aCol[i].notNull = (u8)onError; + p = pParse->pNewTable; + if( p==0 || NEVER(p->nCol<1) ) return; + p->aCol[p->nCol-1].notNull = (u8)onError; } /* ** Scan the column type name zType (length nType) and return the ** associated affinity type. @@ -1054,21 +1056,17 @@ ** that contains the typename of the column and store that string ** in zType. */ void sqlite3AddColumnType(Parse *pParse, Token *pType){ Table *p; - int i; Column *pCol; - sqlite3 *db; - - if( (p = pParse->pNewTable)==0 ) return; - i = p->nCol-1; - if( i<0 ) return; - pCol = &p->aCol[i]; - db = pParse->db; - sqlite3DbFree(db, pCol->zType); - pCol->zType = sqlite3NameFromToken(db, pType); + + p = pParse->pNewTable; + if( p==0 || NEVER(p->nCol<1) ) return; + pCol = &p->aCol[p->nCol-1]; + assert( pCol->zType==0 ); + pCol->zType = sqlite3NameFromToken(pParse->db, pType); pCol->affinity = sqlite3AffinityType(pType); } /* ** The expression is the default value for the most recently added column @@ -1082,11 +1080,12 @@ */ void sqlite3AddDefaultValue(Parse *pParse, Expr *pExpr){ Table *p; Column *pCol; sqlite3 *db = pParse->db; - if( (p = pParse->pNewTable)!=0 ){ + p = pParse->pNewTable; + if( p!=0 ){ pCol = &(p->aCol[p->nCol-1]); if( !sqlite3ExprIsConstantOrFunction(pExpr) ){ sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", pCol->zName); }else{ @@ -1211,11 +1210,11 @@ i = p->nCol-1; db = pParse->db; zColl = sqlite3NameFromToken(db, pToken); if( !zColl ) return; - if( sqlite3LocateCollSeq(pParse, zColl, -1) ){ + if( sqlite3LocateCollSeq(pParse, zColl) ){ Index *pIdx; p->aCol[i].zColl = zColl; /* If the column is declared as " PRIMARY KEY COLLATE ", ** then an index may have been created on this column before the @@ -1247,25 +1246,24 @@ ** pParse. ** ** This routine is a wrapper around sqlite3FindCollSeq(). This routine ** invokes the collation factory if the named collation cannot be found ** and generates an error message. +** +** See also: sqlite3FindCollSeq(), sqlite3GetCollSeq() */ -CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){ +CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName){ sqlite3 *db = pParse->db; u8 enc = ENC(db); u8 initbusy = db->init.busy; CollSeq *pColl; - pColl = sqlite3FindCollSeq(db, enc, zName, nName, initbusy); + pColl = sqlite3FindCollSeq(db, enc, zName, initbusy); if( !initbusy && (!pColl || !pColl->xCmp) ){ - pColl = sqlite3GetCollSeq(db, pColl, zName, nName); + pColl = sqlite3GetCollSeq(db, pColl, zName); if( !pColl ){ - if( nName<0 ){ - nName = sqlite3Strlen30(zName); - } - sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", nName, zName); + sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName); pColl = 0; } } return pColl; @@ -1311,65 +1309,10 @@ if( *z=='"' ){ n++; } } return n + 2; } -/* -** This function is a wrapper around sqlite3GetToken() used by -** isValidDimension(). This function differs from sqlite3GetToken() in -** that: -** -** * Whitespace is ignored, and -** * The output variable *peToken is set to 0 if the end of the -** nul-terminated input string is reached. -*/ -static int getTokenNoSpace(unsigned char *z, int *peToken){ - int n = 0; - while( sqlite3Isspace(z[n]) ) n++; - if( !z[n] ){ - *peToken = 0; - return 0; - } - return n + sqlite3GetToken(&z[n], peToken); -} - -/* -** Parameter z points to a nul-terminated string. Return true if, when -** whitespace is ignored, the contents of this string matches one of -** the following patterns: -** -** "" -** "(number)" -** "(number,number)" -*/ -static int isValidDimension(unsigned char *z){ - int eToken; - int n = 0; - n += getTokenNoSpace(&z[n], &eToken); - if( eToken ){ - if( eToken!=TK_LP ) return 0; - n += getTokenNoSpace(&z[n], &eToken); - if( eToken==TK_PLUS || eToken==TK_MINUS ){ - n += getTokenNoSpace(&z[n], &eToken); - } - if( eToken!=TK_INTEGER && eToken!=TK_FLOAT ) return 0; - n += getTokenNoSpace(&z[n], &eToken); - if( eToken==TK_COMMA ){ - n += getTokenNoSpace(&z[n], &eToken); - if( eToken==TK_PLUS || eToken==TK_MINUS ){ - n += getTokenNoSpace(&z[n], &eToken); - } - if( eToken!=TK_INTEGER && eToken!=TK_FLOAT ) return 0; - n += getTokenNoSpace(&z[n], &eToken); - } - if( eToken!=TK_RP ) return 0; - getTokenNoSpace(&z[n], &eToken); - } - if( eToken ) return 0; - return 1; -} - /* ** The first parameter is a pointer to an output buffer. The second ** parameter is a pointer to an integer that contains the offset at ** which to write into the output buffer. This function copies the ** nul-terminated string pointed to by the third parameter, zSignedIdent, @@ -1379,35 +1322,21 @@ ** If the string zSignedIdent consists entirely of alpha-numeric ** characters, does not begin with a digit and is not an SQL keyword, ** then it is copied to the output buffer exactly as it is. Otherwise, ** it is quoted using double-quotes. */ -static void identPut(char *z, int *pIdx, char *zSignedIdent, int isTypename){ +static void identPut(char *z, int *pIdx, char *zSignedIdent){ unsigned char *zIdent = (unsigned char*)zSignedIdent; int i, j, needQuote; i = *pIdx; for(j=0; zIdent[j]; j++){ if( !sqlite3Isalnum(zIdent[j]) && zIdent[j]!='_' ) break; } needQuote = sqlite3Isdigit(zIdent[0]) || sqlite3KeywordCode(zIdent, j)!=TK_ID; if( !needQuote ){ - if( isTypename ){ - /* If this is a type-name, allow a little more flexibility. In SQLite, - ** a type-name is specified as: - ** - ** ids [ids] [(number [, number])] - ** - ** where "ids" is either a quoted string or a simple identifier (in the - ** above notation, [] means optional). It is a bit tricky to check - ** for all cases, but it is good to avoid unnecessarily quoting common - ** typenames like VARCHAR(10). - */ - needQuote = !isValidDimension(&zIdent[j]); - }else{ - needQuote = zIdent[j]; - } + needQuote = zIdent[j]; } if( needQuote ) z[i++] = '"'; for(j=0; zIdent[j]; j++){ z[i++] = zIdent[j]; @@ -1424,22 +1353,18 @@ ** from sqliteMalloc() and must be freed by the calling function. */ static char *createTableStmt(sqlite3 *db, Table *p){ int i, k, n; char *zStmt; - char *zSep, *zSep2, *zEnd, *z; + char *zSep, *zSep2, *zEnd; Column *pCol; n = 0; for(pCol = p->aCol, i=0; inCol; i++, pCol++){ - n += identLength(pCol->zName); - z = pCol->zType; - if( z ){ - n += identLength(z); - } + n += identLength(pCol->zName) + 5; } n += identLength(p->zName); - if( n<50 ){ + if( n<50 ){ zSep = ""; zSep2 = ","; zEnd = ")"; }else{ zSep = "\n "; @@ -1452,22 +1377,48 @@ db->mallocFailed = 1; return 0; } sqlite3_snprintf(n, zStmt, "CREATE TABLE "); k = sqlite3Strlen30(zStmt); - identPut(zStmt, &k, p->zName, 0); + identPut(zStmt, &k, p->zName); zStmt[k++] = '('; for(pCol=p->aCol, i=0; inCol; i++, pCol++){ + static const char * const azType[] = { + /* SQLITE_AFF_TEXT */ " TEXT", + /* SQLITE_AFF_NONE */ "", + /* SQLITE_AFF_NUMERIC */ " NUM", + /* SQLITE_AFF_INTEGER */ " INT", + /* SQLITE_AFF_REAL */ " REAL" + }; + int len; + const char *zType; + sqlite3_snprintf(n-k, &zStmt[k], zSep); k += sqlite3Strlen30(&zStmt[k]); zSep = zSep2; - identPut(zStmt, &k, pCol->zName, 0); - if( (z = pCol->zType)!=0 ){ - zStmt[k++] = ' '; - assert( (int)(sqlite3Strlen30(z)+k+1)<=n ); - identPut(zStmt, &k, z, 1); + identPut(zStmt, &k, pCol->zName); + assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 ); + assert( pCol->affinity-SQLITE_AFF_TEXT < sizeof(azType)/sizeof(azType[0]) ); + testcase( pCol->affinity==SQLITE_AFF_TEXT ); + testcase( pCol->affinity==SQLITE_AFF_NONE ); + testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); + testcase( pCol->affinity==SQLITE_AFF_INTEGER ); + testcase( pCol->affinity==SQLITE_AFF_REAL ); + + zType = azType[pCol->affinity - SQLITE_AFF_TEXT]; + len = sqlite3Strlen30(zType); +#ifndef NDEBUG + if( pCol->affinity!=SQLITE_AFF_NONE ){ + Token typeToken; + typeToken.z = (u8*)zType; + typeToken.n = len; + assert( pCol->affinity==sqlite3AffinityType(&typeToken) ); } +#endif + memcpy(&zStmt[k], zType, len); + k += len; + assert( k<=n ); } sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd); return zStmt; } @@ -2645,11 +2596,11 @@ zColl = pTab->aCol[j].zColl; if( !zColl ){ zColl = db->pDfltColl->zName; } } - if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl, -1) ){ + if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){ goto exit_create_index; } pIndex->azColl[i] = zColl; requestedSortOrder = pListItem->sortOrder & sortOrderMask; pIndex->aSortOrder[i] = (u8)requestedSortOrder; @@ -3582,11 +3533,11 @@ }else if( pName2==0 || pName2->z==0 ){ char *zColl; assert( pName1->z ); zColl = sqlite3NameFromToken(pParse->db, pName1); if( !zColl ) return; - pColl = sqlite3FindCollSeq(db, ENC(db), zColl, -1, 0); + pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); if( pColl ){ if( zColl ){ reindexDatabases(pParse, zColl); sqlite3DbFree(db, zColl); } @@ -3638,11 +3589,11 @@ pKey->aSortOrder = (u8 *)&(pKey->aColl[nCol]); assert( &pKey->aSortOrder[nCol]==&(((u8 *)pKey)[nBytes]) ); for(i=0; iazColl[i]; assert( zColl ); - pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl, -1); + pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl); pKey->aSortOrder[i] = pIdx->aSortOrder[i]; } pKey->nField = (u16)nCol; } Index: src/callback.c ================================================================== --- src/callback.c +++ src/callback.c @@ -11,34 +11,33 @@ ************************************************************************* ** ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.39 2009/05/03 20:23:53 drh Exp $ +** $Id: callback.c,v 1.40 2009/05/11 20:53:29 drh Exp $ */ #include "sqliteInt.h" /* ** Invoke the 'collation needed' callback to request a collation sequence ** in the database text encoding of name zName, length nName. ** If the collation sequence */ -static void callCollNeeded(sqlite3 *db, const char *zName, int nName){ +static void callCollNeeded(sqlite3 *db, const char *zName){ assert( !db->xCollNeeded || !db->xCollNeeded16 ); - if( nName<0 ) nName = sqlite3Strlen30(zName); if( db->xCollNeeded ){ - char *zExternal = sqlite3DbStrNDup(db, zName, nName); + char *zExternal = sqlite3DbStrDup(db, zName); if( !zExternal ) return; db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal); sqlite3DbFree(db, zExternal); } #ifndef SQLITE_OMIT_UTF16 if( db->xCollNeeded16 ){ char const *zExternal; sqlite3_value *pTmp = sqlite3ValueNew(db); - sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC); + sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC); zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE); if( zExternal ){ db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal); } sqlite3ValueFree(pTmp); @@ -54,15 +53,14 @@ ** possible. */ static int synthCollSeq(sqlite3 *db, CollSeq *pColl){ CollSeq *pColl2; char *z = pColl->zName; - int n = sqlite3Strlen30(z); int i; static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 }; for(i=0; i<3; i++){ - pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0); + pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, 0); if( pColl2->xCmp!=0 ){ memcpy(pColl, pColl2, sizeof(CollSeq)); pColl->xDel = 0; /* Do not copy the destructor */ return SQLITE_OK; } @@ -80,29 +78,30 @@ ** collation sequence with name zName, length nName. ** ** The return value is either the collation sequence to be used in database ** db for collation type name zName, length nName, or NULL, if no collation ** sequence can be found. +** +** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq() */ CollSeq *sqlite3GetCollSeq( - sqlite3* db, - CollSeq *pColl, - const char *zName, - int nName + sqlite3* db, /* The database connection */ + CollSeq *pColl, /* Collating sequence with native encoding, or NULL */ + const char *zName /* Collating sequence name */ ){ CollSeq *p; p = pColl; if( !p ){ - p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0); + p = sqlite3FindCollSeq(db, ENC(db), zName, 0); } if( !p || !p->xCmp ){ /* No collation sequence of this type for this encoding is registered. ** Call the collation factory to see if it can supply us with one. */ - callCollNeeded(db, zName, nName); - p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0); + callCollNeeded(db, zName); + p = sqlite3FindCollSeq(db, ENC(db), zName, 0); } if( p && !p->xCmp && synthCollSeq(db, p) ){ p = 0; } assert( !p || p->xCmp ); @@ -121,11 +120,11 @@ ** from the main database is substituted, if one is available. */ int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){ if( pColl ){ const char *zName = pColl->zName; - CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName, -1); + CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName); if( !p ){ if( pParse->nErr==0 ){ sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName); } pParse->nErr++; @@ -150,17 +149,16 @@ ** Stored immediately after the three collation sequences is a copy of ** the collation sequence name. A pointer to this string is stored in ** each collation sequence structure. */ static CollSeq *findCollSeqEntry( - sqlite3 *db, - const char *zName, - int nName, - int create + sqlite3 *db, /* Database connection */ + const char *zName, /* Name of the collating sequence */ + int create /* Create a new entry if true */ ){ CollSeq *pColl; - if( nName<0 ) nName = sqlite3Strlen30(zName); + int nName = sqlite3Strlen30(zName); pColl = sqlite3HashFind(&db->aCollSeq, zName, nName); if( 0==pColl && create ){ pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 ); if( pColl ){ @@ -200,21 +198,22 @@ ** ** A separate function sqlite3LocateCollSeq() is a wrapper around ** this routine. sqlite3LocateCollSeq() invokes the collation factory ** if necessary and generates an error message if the collating sequence ** cannot be found. +** +** See also: sqlite3LocateCollSeq(), sqlite3GetCollSeq() */ CollSeq *sqlite3FindCollSeq( sqlite3 *db, u8 enc, const char *zName, - int nName, int create ){ CollSeq *pColl; if( zName ){ - pColl = findCollSeqEntry(db, zName, nName, create); + pColl = findCollSeqEntry(db, zName, create); }else{ pColl = db->pDfltColl; } assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE ); Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.433 2009/05/09 00:18:38 drh Exp $ +** $Id: expr.c,v 1.434 2009/05/11 20:53:29 drh Exp $ */ #include "sqliteInt.h" /* ** Return the 'affinity' of the expression pExpr if any. @@ -67,11 +67,11 @@ char *zColl = 0; /* Dequoted name of collation sequence */ CollSeq *pColl; sqlite3 *db = pParse->db; zColl = sqlite3NameFromToken(db, pCollName); if( pExpr && zColl ){ - pColl = sqlite3LocateCollSeq(pParse, zColl, -1); + pColl = sqlite3LocateCollSeq(pParse, zColl); if( pColl ){ pExpr->pColl = pColl; pExpr->flags |= EP_ExpCollate; } } @@ -97,11 +97,11 @@ const char *zColl; int j = p->iColumn; if( j>=0 ){ sqlite3 *db = pParse->db; zColl = p->pTab->aCol[j].zColl; - pColl = sqlite3FindCollSeq(db, ENC(db), zColl, -1, 0); + pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); pExpr->pColl = pColl; } break; } if( op!=TK_CAST && op!=TK_UPLUS ){ @@ -1375,11 +1375,11 @@ char aff = comparisonAffinity(pX); int affinity_ok = (pTab->aCol[iCol].affinity==aff||aff==SQLITE_AFF_NONE); for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){ if( (pIdx->aiColumn[0]==iCol) - && (pReq==sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], -1, 0)) + && (pReq==sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)) && (!mustBeUnique || (pIdx->nColumn==1 && pIdx->onError!=OE_None)) ){ int iMem = ++pParse->nMem; int iAddr; char *pKey; Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -12,11 +12,11 @@ ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.550 2009/05/09 18:59:42 drh Exp $ +** $Id: main.c,v 1.551 2009/05/11 20:53:29 drh Exp $ */ #include "sqliteInt.h" #ifdef SQLITE_ENABLE_FTS3 # include "fts3.h" @@ -1359,11 +1359,11 @@ int(*xCompare)(void*,int,const void*,int,const void*), void(*xDel)(void*) ){ CollSeq *pColl; int enc2; - int nName; + int nName = sqlite3Strlen30(zName); assert( sqlite3_mutex_held(db->mutex) ); /* If SQLITE_UTF16 is specified as the encoding type, transform this ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the @@ -1381,12 +1381,11 @@ /* Check if this call is removing or replacing an existing collation ** sequence. If so, and there are active VMs, return busy. If there ** are no active VMs, invalidate any pre-compiled statements. */ - nName = sqlite3Strlen30(zName); - pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, nName, 0); + pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0); if( pColl && pColl->xCmp ){ if( db->activeVdbeCnt ){ sqlite3Error(db, SQLITE_BUSY, "unable to delete/modify collation sequence due to active statements"); return SQLITE_BUSY; @@ -1412,11 +1411,11 @@ } } } } - pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, nName, 1); + pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1); if( pColl ){ pColl->xCmp = xCompare; pColl->pUser = pCtx; pColl->xDel = xDel; pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED)); @@ -1601,19 +1600,19 @@ createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0); createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0); if( db->mallocFailed ){ goto opendb_out; } - db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0); + db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0); assert( db->pDfltColl!=0 ); /* Also add a UTF-8 case-insensitive collation sequence. */ createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0); /* Set flags on the built-in collating sequences */ db->pDfltColl->type = SQLITE_COLL_BINARY; - pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 6, 0); + pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 0); if( pColl ){ pColl->type = SQLITE_COLL_NOCASE; } /* Open the backend database driver */ Index: src/prepare.c ================================================================== --- src/prepare.c +++ src/prepare.c @@ -11,11 +11,11 @@ ************************************************************************* ** This file contains the implementation of the sqlite3_prepare() ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.117 2009/04/20 17:43:03 drh Exp $ +** $Id: prepare.c,v 1.118 2009/05/11 20:53:29 drh Exp $ */ #include "sqliteInt.h" /* ** Fill the InitData structure with an error message that indicates @@ -256,11 +256,11 @@ */ if( meta[4] ){ /* text encoding */ if( iDb==0 ){ /* If opening the main database, set ENC(db). */ ENC(db) = (u8)meta[4]; - db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0); + db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0); }else{ /* If opening an attached database, the encoding much match ENC(db) */ if( meta[4]!=ENC(db) ){ sqlite3SetString(pzErrMsg, db, "attached databases must use the same" " text encoding as main database"); Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.512 2009/05/03 20:23:54 drh Exp $ +** $Id: select.c,v 1.513 2009/05/11 20:53:29 drh Exp $ */ #include "sqliteInt.h" /* @@ -1221,10 +1221,11 @@ a = pSelect->pEList->a; for(i=0, pCol=aCol; izType = sqlite3DbStrDup(db, columnType(&sNC, p, 0, 0, 0)); pCol->affinity = sqlite3ExprAffinity(p); + if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_NONE; pColl = sqlite3ExprCollSeq(pParse, p); if( pColl ){ pCol->zColl = sqlite3DbStrDup(db, pColl->zName); } } Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -9,11 +9,11 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.869 2009/05/07 14:11:52 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.870 2009/05/11 20:53:29 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* @@ -2639,12 +2639,12 @@ void sqlite3Error(sqlite3*, int, const char*,...); void *sqlite3HexToBlob(sqlite3*, const char *z, int n); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); const char *sqlite3ErrStr(int); int sqlite3ReadSchema(Parse *pParse); -CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int); -CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName); +CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); +CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *); int sqlite3CheckCollSeq(Parse *, CollSeq *); int sqlite3CheckObjectName(Parse *, const char *); void sqlite3VdbeSetChanges(sqlite3 *, int); @@ -2678,11 +2678,11 @@ void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); void sqlite3ColumnDefault(Vdbe *, Table *, int); void sqlite3AlterFinishAddColumn(Parse *, Token *); void sqlite3AlterBeginAddColumn(Parse *, SrcList *); -CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int); +CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char*); char sqlite3AffinityType(const Token*); void sqlite3Analyze(Parse*, Token*, Token*); int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); int sqlite3FindDbName(sqlite3 *, const char *); Index: test/table.test ================================================================== --- test/table.test +++ test/table.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # -# $Id: table.test,v 1.51 2009/04/28 15:43:45 drh Exp $ +# $Id: table.test,v 1.52 2009/05/11 20:53:29 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a basic table and verify it is added to sqlite_master @@ -335,17 +335,17 @@ do_test table-8.1.1 { execsql { SELECT sql FROM sqlite_master WHERE name='t2'; } } {{CREATE TABLE t2( - "desc" text, - "asc" text, - "key" int, - "14_vac" boolean, - fuzzy_dog_12 varchar(10), - "begin" blob, - "end" clob + "desc" TEXT, + "asc" TEXT, + "key" INT, + "14_vac" NUM, + fuzzy_dog_12 TEXT, + "begin", + "end" TEXT )}} do_test table-8.2 { execsql { CREATE TABLE "t3""xyz"(a,b,c); INSERT INTO [t3"xyz] VALUES(1,2,3); @@ -404,11 +404,11 @@ execsql { CREATE TABLE t10("col.1" [char.3]); CREATE TABLE t11 AS SELECT * FROM t10; SELECT sql FROM sqlite_master WHERE name = 't11'; } -} {{CREATE TABLE t11("col.1" "char.3")}} +} {{CREATE TABLE t11("col.1" TEXT)}} do_test table-8.10 { execsql { CREATE TABLE t12( a INTEGER, b VARCHAR(10), @@ -420,17 +420,17 @@ ); CREATE TABLE t13 AS SELECT * FROM t12; SELECT sql FROM sqlite_master WHERE name = 't13'; } } {{CREATE TABLE t13( - a INTEGER, - b VARCHAR(10), - c VARCHAR(1,10), - d VARCHAR(+1,-10), - e VARCHAR (+1,-10), - f "VARCHAR (+1,-10, 5)", - g "BIG INTEGER" + a INT, + b TEXT, + c TEXT, + d TEXT, + e TEXT, + f TEXT, + g INT )}} # Make sure we cannot have duplicate column names within a table. # do_test table-9.1 { @@ -583,11 +583,11 @@ } {} do_test table-12.2 { execsql { SELECT sql FROM sqlite_master WHERE tbl_name = 't8' } -} {{CREATE TABLE t8(b number(5,10),h,i integer,j BLOB)}} +} {{CREATE TABLE t8(b NUM,h,i INT,j)}} #-------------------------------------------------------------------- # Test cases table-13.* # # Test the ability to have default values of CURRENT_TIME, CURRENT_DATE