OLD | NEW |
1 /* | 1 /* |
2 ** 2005 May 23 | 2 ** 2005 May 23 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 /* | 68 /* |
69 ** This function is responsible for invoking the collation factory callback | 69 ** This function is responsible for invoking the collation factory callback |
70 ** or substituting a collation sequence of a different encoding when the | 70 ** or substituting a collation sequence of a different encoding when the |
71 ** requested collation sequence is not available in the desired encoding. | 71 ** requested collation sequence is not available in the desired encoding. |
72 ** | 72 ** |
73 ** If it is not NULL, then pColl must point to the database native encoding | 73 ** If it is not NULL, then pColl must point to the database native encoding |
74 ** collation sequence with name zName, length nName. | 74 ** collation sequence with name zName, length nName. |
75 ** | 75 ** |
76 ** The return value is either the collation sequence to be used in database | 76 ** The return value is either the collation sequence to be used in database |
77 ** db for collation type name zName, length nName, or NULL, if no collation | 77 ** db for collation type name zName, length nName, or NULL, if no collation |
78 ** sequence can be found. | 78 ** sequence can be found. If no collation is found, leave an error message. |
79 ** | 79 ** |
80 ** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq() | 80 ** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq() |
81 */ | 81 */ |
82 CollSeq *sqlite3GetCollSeq( | 82 CollSeq *sqlite3GetCollSeq( |
83 sqlite3* db, /* The database connection */ | 83 Parse *pParse, /* Parsing context */ |
84 u8 enc, /* The desired encoding for the collating sequence */ | 84 u8 enc, /* The desired encoding for the collating sequence */ |
85 CollSeq *pColl, /* Collating sequence with native encoding, or NULL */ | 85 CollSeq *pColl, /* Collating sequence with native encoding, or NULL */ |
86 const char *zName /* Collating sequence name */ | 86 const char *zName /* Collating sequence name */ |
87 ){ | 87 ){ |
88 CollSeq *p; | 88 CollSeq *p; |
| 89 sqlite3 *db = pParse->db; |
89 | 90 |
90 p = pColl; | 91 p = pColl; |
91 if( !p ){ | 92 if( !p ){ |
92 p = sqlite3FindCollSeq(db, enc, zName, 0); | 93 p = sqlite3FindCollSeq(db, enc, zName, 0); |
93 } | 94 } |
94 if( !p || !p->xCmp ){ | 95 if( !p || !p->xCmp ){ |
95 /* No collation sequence of this type for this encoding is registered. | 96 /* No collation sequence of this type for this encoding is registered. |
96 ** Call the collation factory to see if it can supply us with one. | 97 ** Call the collation factory to see if it can supply us with one. |
97 */ | 98 */ |
98 callCollNeeded(db, enc, zName); | 99 callCollNeeded(db, enc, zName); |
99 p = sqlite3FindCollSeq(db, enc, zName, 0); | 100 p = sqlite3FindCollSeq(db, enc, zName, 0); |
100 } | 101 } |
101 if( p && !p->xCmp && synthCollSeq(db, p) ){ | 102 if( p && !p->xCmp && synthCollSeq(db, p) ){ |
102 p = 0; | 103 p = 0; |
103 } | 104 } |
104 assert( !p || p->xCmp ); | 105 assert( !p || p->xCmp ); |
| 106 if( p==0 ){ |
| 107 sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName); |
| 108 } |
105 return p; | 109 return p; |
106 } | 110 } |
107 | 111 |
108 /* | 112 /* |
109 ** This routine is called on a collation sequence before it is used to | 113 ** This routine is called on a collation sequence before it is used to |
110 ** check that it is defined. An undefined collation sequence exists when | 114 ** check that it is defined. An undefined collation sequence exists when |
111 ** a database is loaded that contains references to collation sequences | 115 ** a database is loaded that contains references to collation sequences |
112 ** that have not been defined by sqlite3_create_collation() etc. | 116 ** that have not been defined by sqlite3_create_collation() etc. |
113 ** | 117 ** |
114 ** If required, this routine calls the 'collation needed' callback to | 118 ** If required, this routine calls the 'collation needed' callback to |
115 ** request a definition of the collating sequence. If this doesn't work, | 119 ** request a definition of the collating sequence. If this doesn't work, |
116 ** an equivalent collating sequence that uses a text encoding different | 120 ** an equivalent collating sequence that uses a text encoding different |
117 ** from the main database is substituted, if one is available. | 121 ** from the main database is substituted, if one is available. |
118 */ | 122 */ |
119 int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){ | 123 int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){ |
120 if( pColl ){ | 124 if( pColl ){ |
121 const char *zName = pColl->zName; | 125 const char *zName = pColl->zName; |
122 sqlite3 *db = pParse->db; | 126 sqlite3 *db = pParse->db; |
123 CollSeq *p = sqlite3GetCollSeq(db, ENC(db), pColl, zName); | 127 CollSeq *p = sqlite3GetCollSeq(pParse, ENC(db), pColl, zName); |
124 if( !p ){ | 128 if( !p ){ |
125 sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName); | |
126 pParse->nErr++; | |
127 return SQLITE_ERROR; | 129 return SQLITE_ERROR; |
128 } | 130 } |
129 assert( p==pColl ); | 131 assert( p==pColl ); |
130 } | 132 } |
131 return SQLITE_OK; | 133 return SQLITE_OK; |
132 } | 134 } |
133 | 135 |
134 | 136 |
135 | 137 |
136 /* | 138 /* |
137 ** Locate and return an entry from the db.aCollSeq hash table. If the entry | 139 ** Locate and return an entry from the db.aCollSeq hash table. If the entry |
138 ** specified by zName and nName is not found and parameter 'create' is | 140 ** specified by zName and nName is not found and parameter 'create' is |
139 ** true, then create a new entry. Otherwise return NULL. | 141 ** true, then create a new entry. Otherwise return NULL. |
140 ** | 142 ** |
141 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an | 143 ** Each pointer stored in the sqlite3.aCollSeq hash table contains an |
142 ** array of three CollSeq structures. The first is the collation sequence | 144 ** array of three CollSeq structures. The first is the collation sequence |
143 ** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be. | 145 ** preferred for UTF-8, the second UTF-16le, and the third UTF-16be. |
144 ** | 146 ** |
145 ** Stored immediately after the three collation sequences is a copy of | 147 ** Stored immediately after the three collation sequences is a copy of |
146 ** the collation sequence name. A pointer to this string is stored in | 148 ** the collation sequence name. A pointer to this string is stored in |
147 ** each collation sequence structure. | 149 ** each collation sequence structure. |
148 */ | 150 */ |
149 static CollSeq *findCollSeqEntry( | 151 static CollSeq *findCollSeqEntry( |
150 sqlite3 *db, /* Database connection */ | 152 sqlite3 *db, /* Database connection */ |
151 const char *zName, /* Name of the collating sequence */ | 153 const char *zName, /* Name of the collating sequence */ |
152 int create /* Create a new entry if true */ | 154 int create /* Create a new entry if true */ |
153 ){ | 155 ){ |
154 CollSeq *pColl; | 156 CollSeq *pColl; |
155 int nName = sqlite3Strlen30(zName); | 157 pColl = sqlite3HashFind(&db->aCollSeq, zName); |
156 pColl = sqlite3HashFind(&db->aCollSeq, zName, nName); | |
157 | 158 |
158 if( 0==pColl && create ){ | 159 if( 0==pColl && create ){ |
159 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 ); | 160 int nName = sqlite3Strlen30(zName); |
| 161 pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1); |
160 if( pColl ){ | 162 if( pColl ){ |
161 CollSeq *pDel = 0; | 163 CollSeq *pDel = 0; |
162 pColl[0].zName = (char*)&pColl[3]; | 164 pColl[0].zName = (char*)&pColl[3]; |
163 pColl[0].enc = SQLITE_UTF8; | 165 pColl[0].enc = SQLITE_UTF8; |
164 pColl[1].zName = (char*)&pColl[3]; | 166 pColl[1].zName = (char*)&pColl[3]; |
165 pColl[1].enc = SQLITE_UTF16LE; | 167 pColl[1].enc = SQLITE_UTF16LE; |
166 pColl[2].zName = (char*)&pColl[3]; | 168 pColl[2].zName = (char*)&pColl[3]; |
167 pColl[2].enc = SQLITE_UTF16BE; | 169 pColl[2].enc = SQLITE_UTF16BE; |
168 memcpy(pColl[0].zName, zName, nName); | 170 memcpy(pColl[0].zName, zName, nName); |
169 pColl[0].zName[nName] = 0; | 171 pColl[0].zName[nName] = 0; |
170 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl); | 172 pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl); |
171 | 173 |
172 /* If a malloc() failure occurred in sqlite3HashInsert(), it will | 174 /* If a malloc() failure occurred in sqlite3HashInsert(), it will |
173 ** return the pColl pointer to be deleted (because it wasn't added | 175 ** return the pColl pointer to be deleted (because it wasn't added |
174 ** to the hash table). | 176 ** to the hash table). |
175 */ | 177 */ |
176 assert( pDel==0 || pDel==pColl ); | 178 assert( pDel==0 || pDel==pColl ); |
177 if( pDel!=0 ){ | 179 if( pDel!=0 ){ |
178 db->mallocFailed = 1; | 180 db->mallocFailed = 1; |
179 sqlite3DbFree(db, pDel); | 181 sqlite3DbFree(db, pDel); |
180 pColl = 0; | 182 pColl = 0; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 if( pColl ) pColl += enc-1; | 218 if( pColl ) pColl += enc-1; |
217 return pColl; | 219 return pColl; |
218 } | 220 } |
219 | 221 |
220 /* During the search for the best function definition, this procedure | 222 /* During the search for the best function definition, this procedure |
221 ** is called to test how well the function passed as the first argument | 223 ** is called to test how well the function passed as the first argument |
222 ** matches the request for a function with nArg arguments in a system | 224 ** matches the request for a function with nArg arguments in a system |
223 ** that uses encoding enc. The value returned indicates how well the | 225 ** that uses encoding enc. The value returned indicates how well the |
224 ** request is matched. A higher value indicates a better match. | 226 ** request is matched. A higher value indicates a better match. |
225 ** | 227 ** |
| 228 ** If nArg is -1 that means to only return a match (non-zero) if p->nArg |
| 229 ** is also -1. In other words, we are searching for a function that |
| 230 ** takes a variable number of arguments. |
| 231 ** |
| 232 ** If nArg is -2 that means that we are searching for any function |
| 233 ** regardless of the number of arguments it uses, so return a positive |
| 234 ** match score for any |
| 235 ** |
226 ** The returned value is always between 0 and 6, as follows: | 236 ** The returned value is always between 0 and 6, as follows: |
227 ** | 237 ** |
228 ** 0: Not a match, or if nArg<0 and the function is has no implementation. | 238 ** 0: Not a match. |
229 ** 1: A variable arguments function that prefers UTF-8 when a UTF-16 | 239 ** 1: UTF8/16 conversion required and function takes any number of arguments. |
230 ** encoding is requested, or vice versa. | 240 ** 2: UTF16 byte order change required and function takes any number of args. |
231 ** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is | 241 ** 3: encoding matches and function takes any number of arguments |
232 ** requested, or vice versa. | 242 ** 4: UTF8/16 conversion required - argument count matches exactly |
233 ** 3: A variable arguments function using the same text encoding. | 243 ** 5: UTF16 byte order conversion required - argument count matches exactly |
234 ** 4: A function with the exact number of arguments requested that | 244 ** 6: Perfect match: encoding and argument count match exactly. |
235 ** prefers UTF-8 when a UTF-16 encoding is requested, or vice versa. | |
236 ** 5: A function with the exact number of arguments requested that | |
237 ** prefers UTF-16LE when UTF-16BE is requested, or vice versa. | |
238 ** 6: An exact match. | |
239 ** | 245 ** |
| 246 ** If nArg==(-2) then any function with a non-null xStep or xFunc is |
| 247 ** a perfect match and any function with both xStep and xFunc NULL is |
| 248 ** a non-match. |
240 */ | 249 */ |
241 static int matchQuality(FuncDef *p, int nArg, u8 enc){ | 250 #define FUNC_PERFECT_MATCH 6 /* The score for a perfect match */ |
242 int match = 0; | 251 static int matchQuality( |
243 if( p->nArg==-1 || p->nArg==nArg | 252 FuncDef *p, /* The function we are evaluating for match quality */ |
244 || (nArg==-1 && (p->xFunc!=0 || p->xStep!=0)) | 253 int nArg, /* Desired number of arguments. (-1)==any */ |
245 ){ | 254 u8 enc /* Desired text encoding */ |
| 255 ){ |
| 256 int match; |
| 257 |
| 258 /* nArg of -2 is a special case */ |
| 259 if( nArg==(-2) ) return (p->xFunc==0 && p->xStep==0) ? 0 : FUNC_PERFECT_MATCH; |
| 260 |
| 261 /* Wrong number of arguments means "no match" */ |
| 262 if( p->nArg!=nArg && p->nArg>=0 ) return 0; |
| 263 |
| 264 /* Give a better score to a function with a specific number of arguments |
| 265 ** than to function that accepts any number of arguments. */ |
| 266 if( p->nArg==nArg ){ |
| 267 match = 4; |
| 268 }else{ |
246 match = 1; | 269 match = 1; |
247 if( p->nArg==nArg || nArg==-1 ){ | |
248 match = 4; | |
249 } | |
250 if( enc==p->iPrefEnc ){ | |
251 match += 2; | |
252 } | |
253 else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) || | |
254 (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){ | |
255 match += 1; | |
256 } | |
257 } | 270 } |
| 271 |
| 272 /* Bonus points if the text encoding matches */ |
| 273 if( enc==(p->funcFlags & SQLITE_FUNC_ENCMASK) ){ |
| 274 match += 2; /* Exact encoding match */ |
| 275 }else if( (enc & p->funcFlags & 2)!=0 ){ |
| 276 match += 1; /* Both are UTF16, but with different byte orders */ |
| 277 } |
| 278 |
258 return match; | 279 return match; |
259 } | 280 } |
260 | 281 |
261 /* | 282 /* |
262 ** Search a FuncDefHash for a function with the given name. Return | 283 ** Search a FuncDefHash for a function with the given name. Return |
263 ** a pointer to the matching FuncDef if found, or 0 if there is no match. | 284 ** a pointer to the matching FuncDef if found, or 0 if there is no match. |
264 */ | 285 */ |
265 static FuncDef *functionSearch( | 286 static FuncDef *functionSearch( |
266 FuncDefHash *pHash, /* Hash table to search */ | 287 FuncDefHash *pHash, /* Hash table to search */ |
267 int h, /* Hash of the name */ | 288 int h, /* Hash of the name */ |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 324 |
304 | 325 |
305 /* | 326 /* |
306 ** Locate a user function given a name, a number of arguments and a flag | 327 ** Locate a user function given a name, a number of arguments and a flag |
307 ** indicating whether the function prefers UTF-16 over UTF-8. Return a | 328 ** indicating whether the function prefers UTF-16 over UTF-8. Return a |
308 ** pointer to the FuncDef structure that defines that function, or return | 329 ** pointer to the FuncDef structure that defines that function, or return |
309 ** NULL if the function does not exist. | 330 ** NULL if the function does not exist. |
310 ** | 331 ** |
311 ** If the createFlag argument is true, then a new (blank) FuncDef | 332 ** If the createFlag argument is true, then a new (blank) FuncDef |
312 ** structure is created and liked into the "db" structure if a | 333 ** structure is created and liked into the "db" structure if a |
313 ** no matching function previously existed. When createFlag is true | 334 ** no matching function previously existed. |
314 ** and the nArg parameter is -1, then only a function that accepts | |
315 ** any number of arguments will be returned. | |
316 ** | 335 ** |
317 ** If createFlag is false and nArg is -1, then the first valid | 336 ** If nArg is -2, then the first valid function found is returned. A |
318 ** function found is returned. A function is valid if either xFunc | 337 ** function is valid if either xFunc or xStep is non-zero. The nArg==(-2) |
319 ** or xStep is non-zero. | 338 ** case is used to see if zName is a valid function name for some number |
| 339 ** of arguments. If nArg is -2, then createFlag must be 0. |
320 ** | 340 ** |
321 ** If createFlag is false, then a function with the required name and | 341 ** If createFlag is false, then a function with the required name and |
322 ** number of arguments may be returned even if the eTextRep flag does not | 342 ** number of arguments may be returned even if the eTextRep flag does not |
323 ** match that requested. | 343 ** match that requested. |
324 */ | 344 */ |
325 FuncDef *sqlite3FindFunction( | 345 FuncDef *sqlite3FindFunction( |
326 sqlite3 *db, /* An open database */ | 346 sqlite3 *db, /* An open database */ |
327 const char *zName, /* Name of the function. Not null-terminated */ | 347 const char *zName, /* Name of the function. Not null-terminated */ |
328 int nName, /* Number of characters in the name */ | 348 int nName, /* Number of characters in the name */ |
329 int nArg, /* Number of arguments. -1 means any number */ | 349 int nArg, /* Number of arguments. -1 means any number */ |
330 u8 enc, /* Preferred text encoding */ | 350 u8 enc, /* Preferred text encoding */ |
331 int createFlag /* Create new entry if true and does not otherwise exist */ | 351 u8 createFlag /* Create new entry if true and does not otherwise exist */ |
332 ){ | 352 ){ |
333 FuncDef *p; /* Iterator variable */ | 353 FuncDef *p; /* Iterator variable */ |
334 FuncDef *pBest = 0; /* Best match found so far */ | 354 FuncDef *pBest = 0; /* Best match found so far */ |
335 int bestScore = 0; /* Score of best match */ | 355 int bestScore = 0; /* Score of best match */ |
336 int h; /* Hash value */ | 356 int h; /* Hash value */ |
337 | 357 |
338 | 358 assert( nArg>=(-2) ); |
339 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); | 359 assert( nArg>=(-1) || createFlag==0 ); |
340 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); | 360 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); |
341 | 361 |
342 /* First search for a match amongst the application-defined functions. | 362 /* First search for a match amongst the application-defined functions. |
343 */ | 363 */ |
344 p = functionSearch(&db->aFunc, h, zName, nName); | 364 p = functionSearch(&db->aFunc, h, zName, nName); |
345 while( p ){ | 365 while( p ){ |
346 int score = matchQuality(p, nArg, enc); | 366 int score = matchQuality(p, nArg, enc); |
347 if( score>bestScore ){ | 367 if( score>bestScore ){ |
348 pBest = p; | 368 pBest = p; |
349 bestScore = score; | 369 bestScore = score; |
(...skipping 24 matching lines...) Expand all Loading... |
374 bestScore = score; | 394 bestScore = score; |
375 } | 395 } |
376 p = p->pNext; | 396 p = p->pNext; |
377 } | 397 } |
378 } | 398 } |
379 | 399 |
380 /* If the createFlag parameter is true and the search did not reveal an | 400 /* If the createFlag parameter is true and the search did not reveal an |
381 ** exact match for the name, number of arguments and encoding, then add a | 401 ** exact match for the name, number of arguments and encoding, then add a |
382 ** new entry to the hash table and return it. | 402 ** new entry to the hash table and return it. |
383 */ | 403 */ |
384 if( createFlag && (bestScore<6 || pBest->nArg!=nArg) && | 404 if( createFlag && bestScore<FUNC_PERFECT_MATCH && |
385 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){ | 405 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){ |
386 pBest->zName = (char *)&pBest[1]; | 406 pBest->zName = (char *)&pBest[1]; |
387 pBest->nArg = (u16)nArg; | 407 pBest->nArg = (u16)nArg; |
388 pBest->iPrefEnc = enc; | 408 pBest->funcFlags = enc; |
389 memcpy(pBest->zName, zName, nName); | 409 memcpy(pBest->zName, zName, nName); |
390 pBest->zName[nName] = 0; | 410 pBest->zName[nName] = 0; |
391 sqlite3FuncDefInsert(&db->aFunc, pBest); | 411 sqlite3FuncDefInsert(&db->aFunc, pBest); |
392 } | 412 } |
393 | 413 |
394 if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){ | 414 if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){ |
395 return pBest; | 415 return pBest; |
396 } | 416 } |
397 return 0; | 417 return 0; |
398 } | 418 } |
(...skipping 21 matching lines...) Expand all Loading... |
420 } | 440 } |
421 sqlite3HashClear(&temp2); | 441 sqlite3HashClear(&temp2); |
422 sqlite3HashInit(&pSchema->tblHash); | 442 sqlite3HashInit(&pSchema->tblHash); |
423 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){ | 443 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){ |
424 Table *pTab = sqliteHashData(pElem); | 444 Table *pTab = sqliteHashData(pElem); |
425 sqlite3DeleteTable(0, pTab); | 445 sqlite3DeleteTable(0, pTab); |
426 } | 446 } |
427 sqlite3HashClear(&temp1); | 447 sqlite3HashClear(&temp1); |
428 sqlite3HashClear(&pSchema->fkeyHash); | 448 sqlite3HashClear(&pSchema->fkeyHash); |
429 pSchema->pSeqTab = 0; | 449 pSchema->pSeqTab = 0; |
430 if( pSchema->flags & DB_SchemaLoaded ){ | 450 if( pSchema->schemaFlags & DB_SchemaLoaded ){ |
431 pSchema->iGeneration++; | 451 pSchema->iGeneration++; |
432 pSchema->flags &= ~DB_SchemaLoaded; | 452 pSchema->schemaFlags &= ~DB_SchemaLoaded; |
433 } | 453 } |
434 } | 454 } |
435 | 455 |
436 /* | 456 /* |
437 ** Find and return the schema associated with a BTree. Create | 457 ** Find and return the schema associated with a BTree. Create |
438 ** a new one if necessary. | 458 ** a new one if necessary. |
439 */ | 459 */ |
440 Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ | 460 Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ |
441 Schema * p; | 461 Schema * p; |
442 if( pBt ){ | 462 if( pBt ){ |
443 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear); | 463 p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear); |
444 }else{ | 464 }else{ |
445 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema)); | 465 p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema)); |
446 } | 466 } |
447 if( !p ){ | 467 if( !p ){ |
448 db->mallocFailed = 1; | 468 db->mallocFailed = 1; |
449 }else if ( 0==p->file_format ){ | 469 }else if ( 0==p->file_format ){ |
450 sqlite3HashInit(&p->tblHash); | 470 sqlite3HashInit(&p->tblHash); |
451 sqlite3HashInit(&p->idxHash); | 471 sqlite3HashInit(&p->idxHash); |
452 sqlite3HashInit(&p->trigHash); | 472 sqlite3HashInit(&p->trigHash); |
453 sqlite3HashInit(&p->fkeyHash); | 473 sqlite3HashInit(&p->fkeyHash); |
454 p->enc = SQLITE_UTF8; | 474 p->enc = SQLITE_UTF8; |
455 } | 475 } |
456 return p; | 476 return p; |
457 } | 477 } |
OLD | NEW |