Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Minor coding enhancements. (CVS 1839) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
65c3af74c16c9fe0341b1e7e6d029927 |
User & Date: | drh 2004-07-21 02:53:30.000 |
Context
2004-07-21
| ||
14:07 | Updates to the C-language API documents for version 3.0. (CVS 1840) (check-in: 814c58d470 user: drh tags: trunk) | |
02:53 | Minor coding enhancements. (CVS 1839) (check-in: 65c3af74c1 user: drh tags: trunk) | |
2004-07-20
| ||
18:23 | Simplify the where.c logic by flipping expression over so that the controlling variable is always on the left. (CVS 1838) (check-in: ec8bfa3891 user: drh tags: trunk) | |
Changes
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.152 2004/07/21 02:53:30 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> char const *sqlite3AffinityString(char affinity){ switch( affinity ){ case SQLITE_AFF_INTEGER: return "i"; |
︙ | ︙ | |||
1163 1164 1165 1166 1167 1168 1169 | case TK_OR: case TK_PLUS: case TK_STAR: case TK_MINUS: case TK_REM: case TK_BITAND: case TK_BITOR: | | < < < < < | | | 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | case TK_OR: case TK_PLUS: case TK_STAR: case TK_MINUS: case TK_REM: case TK_BITAND: case TK_BITOR: case TK_SLASH: case TK_LSHIFT: case TK_RSHIFT: { sqlite3ExprCode(pParse, pExpr->pLeft); sqlite3ExprCode(pParse, pExpr->pRight); sqlite3VdbeAddOp(v, op, 0, 0); break; } case TK_CONCAT: { sqlite3ExprCode(pParse, pExpr->pLeft); sqlite3ExprCode(pParse, pExpr->pRight); sqlite3VdbeAddOp(v, OP_Concat8, 2, 0); |
︙ | ︙ |
Changes to src/vdbe.c.
︙ | ︙ | |||
39 40 41 42 43 44 45 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ** ** Various scripts scan this source file in order to generate HTML ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** ** $Id: vdbe.c,v 1.403 2004/07/21 02:53:30 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
286 287 288 289 290 291 292 | ** SQLITE_AFF_NUMERIC ** SQLITE_AFF_TEXT ** SQLITE_AFF_NONE ** SQLITE_AFF_INTEGER ** */ static void applyAffinity(Mem *pRec, char affinity, u8 enc){ | | > | > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < < < < < | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | ** SQLITE_AFF_NUMERIC ** SQLITE_AFF_TEXT ** SQLITE_AFF_NONE ** SQLITE_AFF_INTEGER ** */ static void applyAffinity(Mem *pRec, char affinity, u8 enc){ if( affinity==SQLITE_AFF_NONE ){ /* do nothing */ }else if( affinity==SQLITE_AFF_TEXT ){ /* Only attempt the conversion to TEXT if there is an integer or real ** representation (blob and NULL do not get converted) but no string ** representation. */ if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ sqlite3VdbeMemStringify(pRec, enc); } pRec->flags &= ~(MEM_Real|MEM_Int); }else{ if( 0==(pRec->flags&(MEM_Real|MEM_Int)) ){ /* pRec does not have a valid integer or real representation. ** Attempt a conversion if pRec has a string representation and ** it looks like a number. */ int realnum; sqlite3VdbeMemNulTerminate(pRec); if( pRec->flags&MEM_Str && sqlite3IsNumber(pRec->z, &realnum, enc) ){ if( realnum ){ Realify(pRec); }else{ Integerify(pRec); } } } if( affinity==SQLITE_AFF_INTEGER ){ /* For INTEGER affinity, try to convert a real value to an int */ if( (pRec->flags&MEM_Real) && !(pRec->flags&MEM_Int) ){ pRec->i = pRec->r; if( ((double)pRec->i)==pRec->r ){ pRec->flags |= MEM_Int; } } } } } #ifndef NDEBUG /* ** Write a nice string representation of the contents of cell pMem ** into buffer zBuf, length nBuf. |
︙ | ︙ | |||
604 605 606 607 608 609 610 | ** ** The return address stack is of limited depth. If too many ** OP_Gosub operations occur without intervening OP_Returns, then ** the return address stack will fill up and processing will abort ** with a fatal error. */ case OP_Gosub: { | | < < < < | < < < < | 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | ** ** The return address stack is of limited depth. If too many ** OP_Gosub operations occur without intervening OP_Returns, then ** the return address stack will fill up and processing will abort ** with a fatal error. */ case OP_Gosub: { assert( p->returnDepth<sizeof(p->returnStack)/sizeof(p->returnStack[0]) ); p->returnStack[p->returnDepth++] = pc+1; pc = pOp->p2 - 1; break; } /* Opcode: Return * * * ** ** Jump immediately to the next instruction after the last unreturned ** OP_Gosub. If an OP_Return has occurred for all OP_Gosubs, then ** processing aborts with a fatal error. */ case OP_Return: { assert( p->returnDepth>0 ); p->returnDepth--; pc = p->returnStack[p->returnDepth] - 1; break; } /* Opcode: Halt P1 P2 * ** |
︙ | ︙ | |||
654 655 656 657 658 659 660 | */ case OP_Halt: { p->magic = VDBE_MAGIC_HALT; p->pTos = pTos; if( pOp->p1!=SQLITE_OK ){ p->rc = pOp->p1; p->errorAction = pOp->p2; | < | < | 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | */ case OP_Halt: { p->magic = VDBE_MAGIC_HALT; p->pTos = pTos; if( pOp->p1!=SQLITE_OK ){ p->rc = pOp->p1; p->errorAction = pOp->p2; sqlite3SetString(&p->zErrMsg, pOp->p3, (char*)0); return SQLITE_ERROR; }else{ p->rc = SQLITE_OK; return SQLITE_DONE; } } |
︙ | ︙ | |||
809 810 811 812 813 814 815 816 817 818 819 820 821 822 | ** sqlite3_bind() API. */ case OP_Variable: { int j = pOp->p1 - 1; assert( j>=0 && j<p->nVar ); pTos++; memcpy(pTos, &p->apVar[j], sizeof(*pTos)-NBFS); pTos->xDel = 0; if( pTos->flags&(MEM_Str|MEM_Blob) ){ pTos->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Short); pTos->flags |= MEM_Static; } break; | > | 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | ** sqlite3_bind() API. */ case OP_Variable: { int j = pOp->p1 - 1; assert( j>=0 && j<p->nVar ); pTos++; /* sqlite3VdbeMemCopyStatic(pTos, &p->apVar[j]); */ memcpy(pTos, &p->apVar[j], sizeof(*pTos)-NBFS); pTos->xDel = 0; if( pTos->flags&(MEM_Str|MEM_Blob) ){ pTos->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Short); pTos->flags |= MEM_Static; } break; |
︙ | ︙ | |||
1293 1294 1295 1296 1297 1298 1299 | ** to integers. Push back onto the stack the bit-wise OR of the ** two elements. ** If either operand is NULL, the result is NULL. */ /* Opcode: ShiftLeft * * * ** ** Pop the top two elements from the stack. Convert both elements | | | | | | | | 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 | ** to integers. Push back onto the stack the bit-wise OR of the ** two elements. ** If either operand is NULL, the result is NULL. */ /* Opcode: ShiftLeft * * * ** ** Pop the top two elements from the stack. Convert both elements ** to integers. Push back onto the stack the second element shifted ** left by N bits where N is the top element on the stack. ** If either operand is NULL, the result is NULL. */ /* Opcode: ShiftRight * * * ** ** Pop the top two elements from the stack. Convert both elements ** to integers. Push back onto the stack the second element shifted ** right by N bits where N is the top element on the stack. ** If either operand is NULL, the result is NULL. */ case OP_BitAnd: case OP_BitOr: case OP_ShiftLeft: case OP_ShiftRight: { Mem *pNos = &pTos[-1]; int a, b; assert( pNos>=p->aStack ); if( (pTos->flags | pNos->flags) & MEM_Null ){ popStack(&pTos, 2); pTos++; pTos->flags = MEM_Null; break; } a = sqlite3VdbeIntValue(pNos); b = sqlite3VdbeIntValue(pTos); switch( pOp->opcode ){ case OP_BitAnd: a &= b; break; case OP_BitOr: a |= b; break; case OP_ShiftLeft: a <<= b; break; case OP_ShiftRight: a >>= b; break; default: /* CANT HAPPEN */ break; } |
︙ | ︙ | |||
1362 1363 1364 1365 1366 1367 1368 | ** convert it into the least integer that is greater than or equal to its ** current value if P1==0, or to the least integer that is strictly ** greater than its current value if P1==1. */ case OP_ForceInt: { int v; assert( pTos>=p->aStack ); | > | < | 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 | ** convert it into the least integer that is greater than or equal to its ** current value if P1==0, or to the least integer that is strictly ** greater than its current value if P1==1. */ case OP_ForceInt: { int v; assert( pTos>=p->aStack ); applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc); if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){ Release(pTos); pTos--; pc = pOp->p2 - 1; break; } if( pTos->flags & MEM_Int ){ v = pTos->i + (pOp->p1!=0); |
︙ | ︙ | |||
1396 1397 1398 1399 1400 1401 1402 | ** ** If the top of the stack is not an integer and P2 is not zero and ** P1 is 1, then the stack is popped. In all other cases, the depth ** of the stack is unchanged. */ case OP_MustBeInt: { assert( pTos>=p->aStack ); | < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < | < < < | | | | | | > > > > | 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 | ** ** If the top of the stack is not an integer and P2 is not zero and ** P1 is 1, then the stack is popped. In all other cases, the depth ** of the stack is unchanged. */ case OP_MustBeInt: { assert( pTos>=p->aStack ); applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc); if( (pTos->flags & MEM_Int)==0 ){ if( pOp->p2==0 ){ rc = SQLITE_MISMATCH; goto abort_due_to_error; }else{ if( pOp->p1 ) popStack(&pTos, 1); pc = pOp->p2 - 1; } }else{ Release(pTos); pTos->flags = MEM_Int; } break; } /* Opcode: Eq P1 P2 P3 ** ** Pop the top two elements from the stack. If they are equal, then |
︙ | ︙ |