Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Use sqliteErrorMsg instead of sqliteSetString whereever practical. (CVS 1264) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
69aac043af7f93e7b3f036622c0ac926 |
User & Date: | drh 2004-02-22 18:40:57.000 |
Context
2004-02-22
| ||
18:56 | Code cleanup in build.c. (CVS 1265) (check-in: 9211e14cf8 user: drh tags: trunk) | |
18:40 | Use sqliteErrorMsg instead of sqliteSetString whereever practical. (CVS 1264) (check-in: 69aac043af user: drh tags: trunk) | |
17:49 | Code cleanup in the date and time functions. (CVS 1263) (check-in: 9b3bcde153 user: drh tags: trunk) | |
Changes
Changes to src/auth.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** This file contains code used to implement the sqlite_set_authorizer() ** API. This facility is an optional feature of the library. Embedded ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ** | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ** ************************************************************************* ** This file contains code used to implement the sqlite_set_authorizer() ** API. This facility is an optional feature of the library. Embedded ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ** ** $Id: auth.c,v 1.12 2004/02/22 18:40:57 drh Exp $ */ #include "sqliteInt.h" /* ** All of the code in this file may be omitted by defining a single ** macro. */ |
︙ | ︙ | |||
81 82 83 84 85 86 87 | } /* ** Write an error message into pParse->zErrMsg that explains that the ** user-supplied authorization function returned an illegal value. */ static void sqliteAuthBadReturnCode(Parse *pParse, int rc){ | < < | | | < | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | } /* ** Write an error message into pParse->zErrMsg that explains that the ** user-supplied authorization function returned an illegal value. */ static void sqliteAuthBadReturnCode(Parse *pParse, int rc){ sqliteErrorMsg(pParse, "illegal return value (%d) from the " "authorization function - should be SQLITE_OK, SQLITE_IGNORE, " "or SQLITE_DENY", rc); pParse->rc = SQLITE_MISUSE; } /* ** The pExpr should be a TK_COLUMN expression. The table referred to ** is in pTabList or else it is the NEW or OLD table of a trigger. ** Check to see if it is OK to read this particular column. |
︙ | ︙ | |||
146 147 148 149 150 151 152 | zDBase = db->aDb[pExpr->iDb].zName; rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase, pParse->zAuthContext); if( rc==SQLITE_IGNORE ){ pExpr->op = TK_NULL; }else if( rc==SQLITE_DENY ){ if( db->nDb>2 || pExpr->iDb!=0 ){ | | | < | < | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | zDBase = db->aDb[pExpr->iDb].zName; rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase, pParse->zAuthContext); if( rc==SQLITE_IGNORE ){ pExpr->op = TK_NULL; }else if( rc==SQLITE_DENY ){ if( db->nDb>2 || pExpr->iDb!=0 ){ sqliteErrorMsg(pParse, "access to %s.%s.%s is prohibited", zDBase, pTab->zName, zCol); }else{ sqliteErrorMsg(pParse, "access to %s.%s is prohibited", pTab->zName,zCol); } pParse->rc = SQLITE_AUTH; }else if( rc!=SQLITE_OK ){ sqliteAuthBadReturnCode(pParse, rc); } } /* |
︙ | ︙ | |||
180 181 182 183 184 185 186 | int rc; if( db->xAuth==0 ){ return SQLITE_OK; } rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext); if( rc==SQLITE_DENY ){ | | < | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | int rc; if( db->xAuth==0 ){ return SQLITE_OK; } rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext); if( rc==SQLITE_DENY ){ sqliteErrorMsg(pParse, "not authorized"); pParse->rc = SQLITE_AUTH; }else if( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){ rc = SQLITE_DENY; sqliteAuthBadReturnCode(pParse, rc); } return rc; } |
︙ | ︙ |
Changes to src/build.c.
︙ | ︙ | |||
19 20 21 22 23 24 25 | ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** PRAGMA ** | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ** DROP INDEX ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** PRAGMA ** ** $Id: build.c,v 1.172 2004/02/22 18:40:57 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** This routine is called when a new SQL statement is beginning to ** be parsed. Check to see if the schema for the database needs |
︙ | ︙ | |||
470 471 472 473 474 475 476 | /* Before trying to create a temporary table, make sure the Btree for ** holding temporary tables is open. */ if( isTemp && db->aDb[1].pBt==0 && !pParse->explain ){ int rc = sqliteBtreeFactory(db, 0, 0, MAX_PAGES, &db->aDb[1].pBt); if( rc!=SQLITE_OK ){ | | | | | < | < | < < | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | /* Before trying to create a temporary table, make sure the Btree for ** holding temporary tables is open. */ if( isTemp && db->aDb[1].pBt==0 && !pParse->explain ){ int rc = sqliteBtreeFactory(db, 0, 0, MAX_PAGES, &db->aDb[1].pBt); if( rc!=SQLITE_OK ){ sqliteErrorMsg(pParse, "unable to open a temporary database " "file for storing temporary tables"); pParse->nErr++; return; } if( db->flags & SQLITE_InTrans ){ rc = sqliteBtreeBeginTrans(db->aDb[1].pBt); if( rc!=SQLITE_OK ){ sqliteErrorMsg(pParse, "unable to get a write lock on " "the temporary database file"); pParse->nErr++; return; } } } /* Make sure the new table name does not collide with an existing ** index or table name. Issue an error message if it does. ** ** If we are re-reading the sqlite_master table because of a schema ** change and a new permanent table is found whose name collides with ** an existing temporary table, that is not an error. */ pTable = sqliteFindTable(db, zName, 0); iDb = isTemp ? 1 : db->init.iDb; if( pTable!=0 && (pTable->iDb==iDb || !db->init.busy) ){ sqliteErrorMsg(pParse, "table %T already exists", pName); sqliteFree(zName); return; } if( (pIdx = sqliteFindIndex(db, zName, 0))!=0 && (pIdx->iDb==0 || !db->init.busy) ){ sqliteErrorMsg(pParse, "there is already an index named %s", zName); sqliteFree(zName); return; } pTable = sqliteMalloc( sizeof(Table) ); if( pTable==0 ){ sqliteFree(zName); return; } |
︙ | ︙ | |||
565 566 567 568 569 570 571 | Column *pCol; if( (p = pParse->pNewTable)==0 ) return; sqliteSetNString(&z, pName->z, pName->n, 0); if( z==0 ) return; sqliteDequote(z); for(i=0; i<p->nCol; i++){ if( sqliteStrICmp(z, p->aCol[i].zName)==0 ){ | | < | 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | Column *pCol; if( (p = pParse->pNewTable)==0 ) return; sqliteSetNString(&z, pName->z, pName->n, 0); if( z==0 ) return; sqliteDequote(z); for(i=0; i<p->nCol; i++){ if( sqliteStrICmp(z, p->aCol[i].zName)==0 ){ sqliteErrorMsg(pParse, "duplicate column name: %s", z); sqliteFree(z); return; } } if( (p->nCol & 0x7)==0 ){ Column *aNew; aNew = sqliteRealloc( p->aCol, (p->nCol+8)*sizeof(p->aCol[0])); |
︙ | ︙ | |||
685 686 687 688 689 690 691 | */ void sqliteAddPrimaryKey(Parse *pParse, IdList *pList, int onError){ Table *pTab = pParse->pNewTable; char *zType = 0; int iCol = -1, i; if( pTab==0 ) goto primary_key_exit; if( pTab->hasPrimKey ){ | | | < | 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | */ void sqliteAddPrimaryKey(Parse *pParse, IdList *pList, int onError){ Table *pTab = pParse->pNewTable; char *zType = 0; int iCol = -1, i; if( pTab==0 ) goto primary_key_exit; if( pTab->hasPrimKey ){ sqliteErrorMsg(pParse, "table \"%s\" has more than one primary key", pTab->zName); goto primary_key_exit; } pTab->hasPrimKey = 1; if( pList==0 ){ iCol = pTab->nCol - 1; pTab->aCol[iCol].isPrimKey = 1; }else{ |
︙ | ︙ | |||
1103 1104 1105 1106 1107 1108 1109 | ** CREATE VIEW one AS SELECT * FROM two; ** CREATE VIEW two AS SELECT * FROM one; ** ** Actually, this error is caught previously and so the following test ** should always fail. But we will leave it in place just to be safe. */ if( pTable->nCol<0 ){ | < | < | 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 | ** CREATE VIEW one AS SELECT * FROM two; ** CREATE VIEW two AS SELECT * FROM one; ** ** Actually, this error is caught previously and so the following test ** should always fail. But we will leave it in place just to be safe. */ if( pTable->nCol<0 ){ sqliteErrorMsg(pParse, "view %s is circularly defined", pTable->zName); return 1; } /* If we get this far, it means we need to compute the table names. */ assert( pTable->pSelect ); /* If nCol==0, then pTable must be a VIEW */ pSel = pTable->pSelect; |
︙ | ︙ | |||
1194 1195 1196 1197 1198 1199 1200 | char *zName; Table *pTab; zName = sqliteTableNameFromToken(pTok); if( zName==0 ) return 0; pTab = sqliteFindTable(pParse->db, zName, 0); sqliteFree(zName); if( pTab==0 ){ | | < < | 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | char *zName; Table *pTab; zName = sqliteTableNameFromToken(pTok); if( zName==0 ) return 0; pTab = sqliteFindTable(pParse->db, zName, 0); sqliteFree(zName); if( pTab==0 ){ sqliteErrorMsg(pParse, "no such table: %T", pTok); } return pTab; } /* ** This routine is called to do the work of a DROP TABLE statement. ** pName is the name of the table to be dropped. |
︙ | ︙ | |||
1247 1248 1249 1250 1251 1252 1253 | } if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTable->zName, 0, zDb) ){ return; } } #endif if( pTable->readOnly ){ | < | | < < | < < | 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | } if( sqliteAuthCheck(pParse, SQLITE_DELETE, pTable->zName, 0, zDb) ){ return; } } #endif if( pTable->readOnly ){ sqliteErrorMsg(pParse, "table %s may not be dropped", pTable->zName); pParse->nErr++; return; } if( isView && pTable->pSelect==0 ){ sqliteErrorMsg(pParse, "use DROP TABLE to delete table %s", pTable->zName); return; } if( !isView && pTable->pSelect ){ sqliteErrorMsg(pParse, "use DROP VIEW to delete view %s", pTable->zName); return; } /* Generate code to remove the table from the master table ** on disk. */ v = sqliteGetVdbe(pParse); |
︙ | ︙ | |||
1404 1405 1406 1407 1408 1409 1410 | assert( pTo!=0 ); if( p==0 || pParse->nErr ) goto fk_end; if( pFromCol==0 ){ int iCol = p->nCol-1; if( iCol<0 ) goto fk_end; if( pToCol && pToCol->nId!=1 ){ | | < | | < | | < | 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | assert( pTo!=0 ); if( p==0 || pParse->nErr ) goto fk_end; if( pFromCol==0 ){ int iCol = p->nCol-1; if( iCol<0 ) goto fk_end; if( pToCol && pToCol->nId!=1 ){ sqliteErrorMsg(pParse, "foreign key on %s" " should reference only one column of table %T", p->aCol[iCol].zName, pTo); goto fk_end; } nCol = 1; }else if( pToCol && pToCol->nId!=pFromCol->nId ){ sqliteErrorMsg(pParse, "number of columns in foreign key does not match the number of " "columns in the referenced table"); goto fk_end; }else{ nCol = pFromCol->nId; } nByte = sizeof(*pFKey) + nCol*sizeof(pFKey->aCol[0]) + pTo->n + 1; if( pToCol ){ for(i=0; i<pToCol->nId; i++){ |
︙ | ︙ | |||
1452 1453 1454 1455 1456 1457 1458 | for(j=0; j<p->nCol; j++){ if( sqliteStrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){ pFKey->aCol[i].iFrom = j; break; } } if( j>=p->nCol ){ | > | | < | 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 | for(j=0; j<p->nCol; j++){ if( sqliteStrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){ pFKey->aCol[i].iFrom = j; break; } } if( j>=p->nCol ){ sqliteErrorMsg(pParse, "unknown column \"%s\" in foreign key definition", pFromCol->a[i].zName); goto fk_end; } } } if( pToCol ){ for(i=0; i<nCol; i++){ int n = strlen(pToCol->a[i].zName); |
︙ | ︙ | |||
1549 1550 1551 1552 1553 1554 1555 | pTab = sqliteSrcListLookup(pParse, pTable); }else{ assert( pName==0 ); pTab = pParse->pNewTable; } if( pTab==0 || pParse->nErr ) goto exit_create_index; if( pTab->readOnly ){ | < | < < | < | < | 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 | pTab = sqliteSrcListLookup(pParse, pTable); }else{ assert( pName==0 ); pTab = pParse->pNewTable; } if( pTab==0 || pParse->nErr ) goto exit_create_index; if( pTab->readOnly ){ sqliteErrorMsg(pParse, "table %s may not be indexed", pTab->zName); goto exit_create_index; } if( pTab->iDb>=2 && db->init.busy==0 ){ sqliteErrorMsg(pParse, "table %s may not have indices added", pTab->zName); goto exit_create_index; } if( pTab->pSelect ){ sqliteErrorMsg(pParse, "views may not be indexed"); goto exit_create_index; } isTemp = pTab->iDb==1; /* ** Find the name of the index. Make sure there is not already another ** index or table with the same name. |
︙ | ︙ | |||
1586 1587 1588 1589 1590 1591 1592 | */ if( pName && !db->init.busy ){ Index *pISameName; /* Another index with the same name */ Table *pTSameName; /* A table with same name as the index */ zName = sqliteStrNDup(pName->z, pName->n); if( zName==0 ) goto exit_create_index; if( (pISameName = sqliteFindIndex(db, zName, 0))!=0 ){ | < | < | < < | 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 | */ if( pName && !db->init.busy ){ Index *pISameName; /* Another index with the same name */ Table *pTSameName; /* A table with same name as the index */ zName = sqliteStrNDup(pName->z, pName->n); if( zName==0 ) goto exit_create_index; if( (pISameName = sqliteFindIndex(db, zName, 0))!=0 ){ sqliteErrorMsg(pParse, "index %s already exists", zName); goto exit_create_index; } if( (pTSameName = sqliteFindTable(db, zName, 0))!=0 ){ sqliteErrorMsg(pParse, "there is already a table named %s", zName); goto exit_create_index; } }else if( pName==0 ){ char zBuf[30]; int n; Index *pLoop; for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){} |
︙ | ︙ | |||
1663 1664 1665 1666 1667 1668 1669 | ** if any column is not found. */ for(i=0; i<pList->nId; i++){ for(j=0; j<pTab->nCol; j++){ if( sqliteStrICmp(pList->a[i].zName, pTab->aCol[j].zName)==0 ) break; } if( j>=pTab->nCol ){ | | | < | 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 | ** if any column is not found. */ for(i=0; i<pList->nId; i++){ for(j=0; j<pTab->nCol; j++){ if( sqliteStrICmp(pList->a[i].zName, pTab->aCol[j].zName)==0 ) break; } if( j>=pTab->nCol ){ sqliteErrorMsg(pParse, "table %s has no column named %s", pTab->zName, pList->a[i].zName); sqliteFree(pIndex); goto exit_create_index; } pIndex->aiColumn[i] = j; } /* Link the new Index structure to its table and to the other |
︙ | ︙ |
Changes to src/expr.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** ** $Id: expr.c,v 1.110 2004/02/22 18:40:57 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> /* ** Construct a new expression node and return a pointer to it. Memory ** for this node is obtained from sqliteMalloc(). The calling function |
︙ | ︙ | |||
843 844 845 846 847 848 849 | }else{ wrong_num_args = 1; } }else{ is_agg = pDef->xFunc==0; } if( is_agg && !allowAgg ){ | | < < | < < | < > > | | > | 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | }else{ wrong_num_args = 1; } }else{ is_agg = pDef->xFunc==0; } if( is_agg && !allowAgg ){ sqliteErrorMsg(pParse, "misuse of aggregate function %.*s()", nId, zId); nErr++; is_agg = 0; }else if( no_such_func ){ sqliteErrorMsg(pParse, "no such function: %.*s", nId, zId); nErr++; }else if( wrong_num_args ){ sqliteErrorMsg(pParse,"wrong number of arguments to function %.*s()", nId, zId); nErr++; } if( is_agg ){ pExpr->op = TK_AGG_FUNCTION; if( pIsAgg ) *pIsAgg = 1; } for(i=0; nErr==0 && i<n; i++){ nErr = sqliteExprCheck(pParse, pExpr->pList->a[i].pExpr, allowAgg && !is_agg, pIsAgg); } if( pDef==0 ){ if( is_type_of ){ pExpr->op = TK_STRING; |
︙ | ︙ |
Changes to src/parse.y.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** This file contains SQLite's grammar for SQL. Process this file ** using the lemon parser generator to generate C code that runs ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** | | < | | < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ** ************************************************************************* ** This file contains SQLite's grammar for SQL. Process this file ** using the lemon parser generator to generate C code that runs ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** ** @(#) $Id: parse.y,v 1.112 2004/02/22 18:40:57 drh Exp $ */ %token_prefix TK_ %token_type {Token} %default_type {Token} %extra_argument {Parse *pParse} %syntax_error { if( pParse->zErrMsg==0 ){ if( TOKEN.z[0] ){ sqliteErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); }else{ sqliteErrorMsg(pParse, "incomplete SQL statement"); } } } %name sqliteParser %include { #include "sqliteInt.h" #include "parse.h" /* |
︙ | ︙ |
Changes to src/where.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. ** ** $Id: where.c,v 1.88 2004/02/22 18:40:57 drh Exp $ */ #include "sqliteInt.h" /* ** The query generator uses an array of instances of this structure to ** help it analyze the subexpressions of the WHERE clause. Each WHERE ** clause subexpression is separated from the others by an AND operator. |
︙ | ︙ | |||
376 377 378 379 380 381 382 | ** array fills up, the last entry might point to an expression which ** contains additional unfactored AND operators. */ initMaskSet(&maskSet); memset(aExpr, 0, sizeof(aExpr)); nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere); if( nExpr==ARRAYSIZE(aExpr) ){ | < < | | < | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | ** array fills up, the last entry might point to an expression which ** contains additional unfactored AND operators. */ initMaskSet(&maskSet); memset(aExpr, 0, sizeof(aExpr)); nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere); if( nExpr==ARRAYSIZE(aExpr) ){ sqliteErrorMsg(pParse, "WHERE clause too complex - no more " "than %d terms allowed", (int)ARRAYSIZE(aExpr)-1); return 0; } /* Allocate and initialize the WhereInfo structure that will become the ** return value. */ pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel)); |
︙ | ︙ |