Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Change all SQLITE3 preprocessor macros to SQLITE. Documentation updates. (CVS 1511) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
adf7e29ff60dc559f64832fadb09f0b9 |
User & Date: | drh 2004-05-31 18:51:58.000 |
Context
2004-05-31
| ||
19:34 | Change the name of the sqlite3_freemem API function to just sqlite3_free. (CVS 1512) (check-in: f3b80bbb97 user: drh tags: trunk) | |
18:51 | Change all SQLITE3 preprocessor macros to SQLITE. Documentation updates. (CVS 1511) (check-in: adf7e29ff6 user: drh tags: trunk) | |
18:23 | Change the name of the include file to "sqlite3.h". The names of the shell command and static library become "sqlite3" and "libsqlite3.a". (CVS 1510) (check-in: 4c37b6d2b7 user: drh tags: trunk) | |
Changes
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.205 2004/05/31 18:51:58 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 |
︙ | ︙ | |||
882 883 884 885 886 887 888 889 890 891 892 893 894 895 | {"INT", 3, SQLITE_AFF_INTEGER}, {"CHAR", 4, SQLITE_AFF_TEXT}, {"CLOB", 4, SQLITE_AFF_TEXT}, {"TEXT", 4, SQLITE_AFF_TEXT}, {"BLOB", 4, SQLITE_AFF_NONE}, }; for(i=0; i<sizeof(substrings)/sizeof(substrings[0]); i++){ int c1 = substrings[i].zSub[0]; int c2 = tolower(c1); int limit = nType - substrings[i].nSub; const char *z = substrings[i].zSub; for(n=0; n<=limit; n++){ int c = zType[n]; | > > > | 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | {"INT", 3, SQLITE_AFF_INTEGER}, {"CHAR", 4, SQLITE_AFF_TEXT}, {"CLOB", 4, SQLITE_AFF_TEXT}, {"TEXT", 4, SQLITE_AFF_TEXT}, {"BLOB", 4, SQLITE_AFF_NONE}, }; if( nType==0 ){ return SQLITE_AFF_NONE; } for(i=0; i<sizeof(substrings)/sizeof(substrings[0]); i++){ int c1 = substrings[i].zSub[0]; int c2 = tolower(c1); int limit = nType - substrings[i].nSub; const char *z = substrings[i].zSub; for(n=0; n<=limit; n++){ int c = zType[n]; |
︙ | ︙ |
Changes to src/date.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This file contains the C functions that implement date and time ** functions for SQLite. ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This file contains the C functions that implement date and time ** functions for SQLite. ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** ** $Id: date.c,v 1.27 2004/05/31 18:51:58 drh Exp $ ** ** NOTES: ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon ** in Greenwich on November 24, 4714 B.C. according to the Gregorian ** calendar system. |
︙ | ︙ | |||
640 641 642 643 644 645 646 | ** argv[1] and following are modifiers. Parse them all and write ** the resulting time into the DateTime structure p. Return 0 ** on success and 1 if there are any errors. */ static int isDate(int argc, sqlite3_value **argv, DateTime *p){ int i; if( argc==0 ) return 1; | | | | 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | ** argv[1] and following are modifiers. Parse them all and write ** the resulting time into the DateTime structure p. Return 0 ** on success and 1 if there are any errors. */ static int isDate(int argc, sqlite3_value **argv, DateTime *p){ int i; if( argc==0 ) return 1; if( SQLITE_NULL==sqlite3_value_type(argv[0]) || parseDateOrTime(sqlite3_value_text(argv[0]), p) ) return 1; for(i=1; i<argc; i++){ if( SQLITE_NULL==sqlite3_value_type(argv[i]) || parseModifier(sqlite3_value_text(argv[i]), p) ) return 1; } return 0; } /* |
︙ | ︙ |
Changes to src/func.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This file contains the C functions that implement various SQL ** functions of SQLite. ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** ** $Id: func.c,v 1.62 2004/05/31 18:51:58 drh Exp $ */ #include <ctype.h> #include <math.h> #include <stdlib.h> #include <assert.h> #include "sqliteInt.h" #include "vdbeInt.h" |
︙ | ︙ | |||
38 39 40 41 42 43 44 | int mask; /* 0 for min() or 0xffffffff for max() */ int iBest; if( argc==0 ) return; mask = (int)sqlite3_user_data(context); assert( mask==-1 || mask==0 ); iBest = 0; | | | | | | | | | | | | | | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | int mask; /* 0 for min() or 0xffffffff for max() */ int iBest; if( argc==0 ) return; mask = (int)sqlite3_user_data(context); assert( mask==-1 || mask==0 ); iBest = 0; if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; for(i=1; i<argc; i++){ if( sqlite3_value_type(argv[i])==SQLITE_NULL ) return; if( (sqlite3MemCompare(argv[iBest], argv[i], 0)^mask)>=0 ){ iBest = i; } } sqlite3_result_value(context, argv[iBest]); } /* ** Return the type of the argument. */ static void typeofFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ const char *z = 0; switch( sqlite3_value_type(argv[0]) ){ case SQLITE_NULL: z = "null"; break; case SQLITE_INTEGER: z = "integer"; break; case SQLITE_TEXT: z = "text"; break; case SQLITE_FLOAT: z = "real"; break; case SQLITE_BLOB: z = "blob"; break; } sqlite3_result_text(context, z, -1, 0); } /* ** Implementation of the length() function */ static void lengthFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int len; assert( argc==1 ); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_BLOB: case SQLITE_INTEGER: case SQLITE_FLOAT: { sqlite3_result_int(context, sqlite3_value_bytes(argv[0])); break; } case SQLITE_TEXT: { const char *z = sqlite3_value_text(argv[0]); for(len=0; *z; z++){ if( (0xc0&*z)!=0x80 ) len++; } sqlite3_result_int(context, len); break; } default: { sqlite3_result_null(context); break; } } } /* ** Implementation of the abs() function */ static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ assert( argc==1 ); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_INTEGER: { i64 iVal = sqlite3_value_int64(argv[0]); if( iVal<0 ) iVal = iVal * -1; sqlite3_result_int64(context, iVal); break; } case SQLITE_NULL: { sqlite3_result_null(context); break; } default: { double rVal = sqlite3_value_double(argv[0]); if( rVal<0 ) rVal = rVal * -1.0; sqlite3_result_double(context, rVal); |
︙ | ︙ | |||
175 176 177 178 179 180 181 | */ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; char zBuf[100]; assert( argc==1 || argc==2 ); if( argc==2 ){ | | | | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | */ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int n = 0; double r; char zBuf[100]; assert( argc==1 || argc==2 ); if( argc==2 ){ if( SQLITE_NULL==sqlite3_value_type(argv[1]) ) return; n = sqlite3_value_int(argv[1]); if( n>30 ) n = 30; if( n<0 ) n = 0; } if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; r = sqlite3_value_double(argv[0]); sprintf(zBuf,"%.*f",n,r); sqlite3_result_text(context, zBuf, -1, 1); } /* ** Implementation of the upper() and lower() SQL functions. */ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ char *z; int i; if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; z = sqliteMalloc(sqlite3_value_bytes(argv[0])+1); if( z==0 ) return; strcpy(z, sqlite3_value_text(argv[0])); for(i=0; z[i]; i++){ if( islower(z[i]) ) z[i] = toupper(z[i]); } sqlite3_result_text(context, z, -1, 1); sqliteFree(z); } static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ char *z; int i; if( argc<1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; z = sqliteMalloc(sqlite3_value_bytes(argv[0])+1); if( z==0 ) return; strcpy(z, sqlite3_value_text(argv[0])); for(i=0; z[i]; i++){ if( isupper(z[i]) ) z[i] = tolower(z[i]); } sqlite3_result_text(context, z, -1, 1); |
︙ | ︙ | |||
228 229 230 231 232 233 234 | static void ifnullFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int i; for(i=0; i<argc; i++){ | | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | static void ifnullFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int i; for(i=0; i<argc; i++){ if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){ sqlite3_result_value(context, argv[i]); break; } } } /* |
︙ | ︙ | |||
367 368 369 370 371 372 373 | ** the argument. If the argument is NULL, the return value is the string ** "NULL". Otherwise, the argument is enclosed in single quotes with ** single-quote escapes. */ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ if( argc<1 ) return; switch( sqlite3_value_type(argv[0]) ){ | | | | | | | 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | ** the argument. If the argument is NULL, the return value is the string ** "NULL". Otherwise, the argument is enclosed in single quotes with ** single-quote escapes. */ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ if( argc<1 ) return; switch( sqlite3_value_type(argv[0]) ){ case SQLITE_NULL: { sqlite3_result_text(context, "NULL", 4, 0); break; } case SQLITE_INTEGER: case SQLITE_FLOAT: { sqlite3_result_value(context, argv[0]); break; } case SQLITE_BLOB: /*** FIX ME. Use a BLOB encoding ***/ case SQLITE_TEXT: { int i,j,n; const char *zArg = sqlite3_value_text(argv[0]); char *z; for(i=n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; } z = sqliteMalloc( i+n+3 ); if( z==0 ) return; |
︙ | ︙ | |||
500 501 502 503 504 505 506 | /* ** Routines used to compute the sum or average. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; if( argc<1 ) return; p = sqlite3_aggregate_context(context, sizeof(*p)); | | | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | /* ** Routines used to compute the sum or average. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; if( argc<1 ) return; p = sqlite3_aggregate_context(context, sizeof(*p)); if( p && SQLITE_NULL!=sqlite3_value_type(argv[0]) ){ p->sum += sqlite3_value_double(argv[0]); p->cnt++; } } static void sumFinalize(sqlite3_context *context){ SumCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); |
︙ | ︙ | |||
571 572 573 574 575 576 577 | /* ** Routines to implement the count() aggregate function. */ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){ CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); | | | 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | /* ** Routines to implement the count() aggregate function. */ static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){ CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){ p->n++; } } static void countFinalize(sqlite3_context *context){ CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); sqlite3_result_int(context, p ? p->n : 0); |
︙ | ︙ | |||
600 601 602 603 604 605 606 | */ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){ int max = 0; int cmp = 0; Mem *pArg = (Mem *)argv[0]; Mem *pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest)); | | | 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | */ static void minmaxStep(sqlite3_context *context, int argc, sqlite3_value **argv){ int max = 0; int cmp = 0; Mem *pArg = (Mem *)argv[0]; Mem *pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest)); if( SQLITE_NULL==sqlite3_value_type(argv[0]) ) return; if( pBest->flags ){ /* This step function is used for both the min() and max() aggregates, ** the only difference between the two being that the sense of the ** comparison is inverted. For the max() aggregate, the ** sqlite3_user_data() function returns (void *)-1. For min() it ** returns (void *)db, where db is the sqlite3* database pointer. |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
10 11 12 13 14 15 16 | ** ************************************************************************* ** 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. ** | | | | | 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 38 39 40 41 | ** ************************************************************************* ** 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.199 2004/05/31 18:51:58 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** A pointer to this structure is used to communicate information ** from sqlite3Init into the sqlite3InitCallback. */ typedef struct { sqlite *db; /* The database being initialized */ char **pzErrMsg; /* Error message stored here */ } InitData; /* ** The following constant value is used by the SQLITE_BIGENDIAN and ** SQLITE_LITTLEENDIAN macros. */ const int sqlite3one = 1; /* ** Fill the InitData structure with an error message that indicates ** that the database is corrupt. */ |
︙ | ︙ | |||
688 689 690 691 692 693 694 | void *pUserData, void (*xFunc)(sqlite3_context*,int,sqlite3_value**), void (*xStep)(sqlite3_context*,int,sqlite3_value**), void (*xFinal)(sqlite3_context*) ){ int rc; char *zFunctionName8; | | | 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | void *pUserData, void (*xFunc)(sqlite3_context*,int,sqlite3_value**), void (*xStep)(sqlite3_context*,int,sqlite3_value**), void (*xFinal)(sqlite3_context*) ){ int rc; char *zFunctionName8; zFunctionName8 = sqlite3utf16to8(zFunctionName, -1, SQLITE_BIGENDIAN); if( !zFunctionName8 ){ return SQLITE_NOMEM; } rc = sqlite3_create_function(db, zFunctionName8, nArg, eTextRep, iCollateArg, pUserData, xFunc, xStep, xFinal); sqliteFree(zFunctionName8); return rc; |
︙ | ︙ | |||
815 816 817 818 819 820 821 | static char outOfMemBe[] = { 0, 'o', 0, 'u', 0, 't', 0, ' ', 0, 'o', 0, 'f', 0, ' ', 0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0 }; static char *outOfMemLe = &outOfMemBe[1]; | | | | 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | static char outOfMemBe[] = { 0, 'o', 0, 'u', 0, 't', 0, ' ', 0, 'o', 0, 'f', 0, ' ', 0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0 }; static char *outOfMemLe = &outOfMemBe[1]; if( SQLITE_BIGENDIAN ){ return (void *)outOfMemBe; }else{ return (void *)outOfMemLe; } } if( !db->zErrMsg16 ){ char const *zErr8 = sqlite3_errmsg(db); if( SQLITE_BIGENDIAN ){ db->zErrMsg16 = sqlite3utf8to16be(zErr8, -1); }else{ db->zErrMsg16 = sqlite3utf8to16le(zErr8, -1); } } return db->zErrMsg16; } |
︙ | ︙ | |||
956 957 958 959 960 961 962 | ** encoded string to UTF-8, then invoking sqlite3_prepare(). The ** tricky bit is figuring out the pointer to return in *pzTail. */ char *zSql8 = 0; char const *zTail8 = 0; int rc; | | | 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 | ** encoded string to UTF-8, then invoking sqlite3_prepare(). The ** tricky bit is figuring out the pointer to return in *pzTail. */ char *zSql8 = 0; char const *zTail8 = 0; int rc; zSql8 = sqlite3utf16to8(zSql, nBytes, SQLITE_BIGENDIAN); if( !zSql8 ){ sqlite3Error(db, SQLITE_NOMEM, 0); return SQLITE_NOMEM; } rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8); if( zTail8 && pzTail ){ |
︙ | ︙ | |||
1086 1087 1088 1089 1090 1091 1092 | const char **options ){ char *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ int rc; assert( ppDb ); | | | | 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | const char **options ){ char *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ int rc; assert( ppDb ); zFilename8 = sqlite3utf16to8(zFilename, -1, SQLITE_BIGENDIAN); if( !zFilename8 ){ *ppDb = 0; return SQLITE_NOMEM; } /* FIX ME: Also need to translate the option strings */ if( SQLITE_BIGENDIAN ){ rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16be); }else{ rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le); } sqliteFree(zFilename8); return rc; |
︙ | ︙ |
Changes to src/sqlite.h.in.
︙ | ︙ | |||
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 header file defines the interface that the SQLite library ** presents to client programs. ** | | | 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 header file defines the interface that the SQLite library ** presents to client programs. ** ** @(#) $Id: sqlite.h.in,v 1.86 2004/05/31 18:51:58 drh Exp $ */ #ifndef _SQLITE_H_ #define _SQLITE_H_ #include <stdarg.h> /* Needed for the definition of va_list */ /* ** Make sure we can call this stuff from C++. |
︙ | ︙ | |||
764 765 766 767 768 769 770 | */ int sqlite3_data_count(sqlite3_stmt *pStmt); /* ** Values are stored in the database in one of the following fundamental ** types. */ | | | | | | | 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | */ int sqlite3_data_count(sqlite3_stmt *pStmt); /* ** Values are stored in the database in one of the following fundamental ** types. */ #define SQLITE_INTEGER 1 #define SQLITE_FLOAT 2 #define SQLITE_TEXT 3 #define SQLITE_BLOB 4 #define SQLITE_NULL 5 /* ** The next group of routines returns information about the information ** in a single column of the current result row of a query. In every ** case the first parameter is a pointer to the SQL statement that is being ** executed (the sqlite_stmt* that was returned from sqlite3_prepare()) and ** the second argument is the index of the column for which information |
︙ | ︙ |
Changes to src/sqliteInt.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.265 2004/05/31 18:51:58 drh Exp $ */ #include "config.h" #include "sqlite3.h" #include "hash.h" #include "parse.h" #include <stdio.h> #include <stdlib.h> |
︙ | ︙ | |||
130 131 132 133 134 135 136 | typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */ /* ** Macros to determine whether the machine is big or little endian, ** evaluated at runtime. */ extern const int sqlite3one; | | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | typedef unsigned INTPTR_TYPE uptr; /* Big enough to hold a pointer */ /* ** Macros to determine whether the machine is big or little endian, ** evaluated at runtime. */ extern const int sqlite3one; #define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) #define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) /* ** Defer sourcing vdbe.h until after the "u8" typedef is defined. */ #include "vdbe.h" #include "btree.h" |
︙ | ︙ | |||
320 321 322 323 324 325 326 | /* ** Possible values for the Db.textEnc field. */ #define TEXT_Utf8 1 #define TEXT_Utf16le 2 #define TEXT_Utf16be 3 | | | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | /* ** Possible values for the Db.textEnc field. */ #define TEXT_Utf8 1 #define TEXT_Utf16le 2 #define TEXT_Utf16be 3 #define TEXT_Utf16 (SQLITE_BIGENDIAN?TEXT_Utf16be:TEXT_Utf16le) /* ** Each database is an instance of the following structure. ** ** The sqlite.temp_store determines where temporary database files ** are stored. If 1, then a file is created to hold those tables. If ** 2, then they are held in memory. 0 means use the default value in |
︙ | ︙ |
Changes to src/tclsqlite.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** A TCL Interface to SQLite ** | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* ** 2001 September 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** A TCL Interface to SQLite ** ** $Id: tclsqlite.c,v 1.77 2004/05/31 18:51:58 drh Exp $ */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ #include "sqliteInt.h" #include "tcl.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
209 210 211 212 213 214 215 | Tcl_DString cmd; int i; int rc; Tcl_DStringInit(&cmd); Tcl_DStringAppend(&cmd, p->zScript, -1); for(i=0; i<argc; i++){ | | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | Tcl_DString cmd; int i; int rc; Tcl_DStringInit(&cmd); Tcl_DStringAppend(&cmd, p->zScript, -1); for(i=0; i<argc; i++){ if( SQLITE_NULL==sqlite3_value_type(argv[i]) ){ Tcl_DStringAppendElement(&cmd, ""); }else{ Tcl_DStringAppendElement(&cmd, sqlite3_value_text(argv[i])); } } rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd)); if( rc ){ |
︙ | ︙ | |||
654 655 656 657 658 659 660 | } while( pStmt && SQLITE_ROW==sqlite3_step(pStmt) ){ for(i=0; i<sqlite3_column_count(pStmt); i++){ Tcl_Obj *pVal; /* Set pVal to contain the i'th column of this row. */ | | | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | } while( pStmt && SQLITE_ROW==sqlite3_step(pStmt) ){ for(i=0; i<sqlite3_column_count(pStmt); i++){ Tcl_Obj *pVal; /* Set pVal to contain the i'th column of this row. */ if( SQLITE_BLOB!=sqlite3_column_type(pStmt, i) ){ pVal = dbTextToObj(sqlite3_column_text(pStmt, i)); }else{ int bytes = sqlite3_column_bytes(pStmt, i); pVal = Tcl_NewByteArrayObj(sqlite3_column_blob(pStmt, i), bytes); } if( objc==5 ){ |
︙ | ︙ |
Changes to src/test1.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** ** $Id: test1.c,v 1.66 2004/05/31 18:51:58 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
321 322 323 324 325 326 327 | /* ** Implementation of the x_coalesce() function. ** Return the first argument non-NULL argument. */ static void ifnullFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int i; for(i=0; i<argc; i++){ | | | 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | /* ** Implementation of the x_coalesce() function. ** Return the first argument non-NULL argument. */ static void ifnullFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ int i; for(i=0; i<argc; i++){ if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){ sqlite3_result_text(context, sqlite3_value_text(argv[i]), -1, 1); break; } } } /* |
︙ | ︙ | |||
446 447 448 449 450 451 452 | typedef struct CountCtx CountCtx; struct CountCtx { int n; }; static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){ CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); | | | 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | typedef struct CountCtx CountCtx; struct CountCtx { int n; }; static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){ CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0]) ) && p ){ p->n++; } } static void countFinalize(sqlite3_context *context){ CountCtx *p; p = sqlite3_aggregate_context(context, sizeof(*p)); sqlite3_result_int(context, p ? p->n : 0); |
︙ | ︙ | |||
1395 1396 1397 1398 1399 1400 1401 | } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; tp = sqlite3_column_type(pStmt, col); switch( tp ){ | | | | | | | 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 | } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; tp = sqlite3_column_type(pStmt, col); switch( tp ){ case SQLITE_INTEGER: Tcl_SetResult(interp, "INTEGER", TCL_STATIC); break; case SQLITE_NULL: Tcl_SetResult(interp, "NULL", TCL_STATIC); break; case SQLITE_FLOAT: Tcl_SetResult(interp, "FLOAT", TCL_STATIC); break; case SQLITE_TEXT: Tcl_SetResult(interp, "TEXT", TCL_STATIC); break; case SQLITE_BLOB: Tcl_SetResult(interp, "BLOB", TCL_STATIC); break; default: assert(0); } return TCL_OK; |
︙ | ︙ |
Changes to src/test5.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** Code for testing the utf.c module in SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. Specifically, the code in this file ** is used for testing the SQLite routines for converting between ** the various supported unicode encodings. ** | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ************************************************************************* ** Code for testing the utf.c module in SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. Specifically, the code in this file ** is used for testing the SQLite routines for converting between ** the various supported unicode encodings. ** ** $Id: test5.c,v 1.6 2004/05/31 18:51:58 drh Exp $ */ #include "sqliteInt.h" #include "os.h" /* to get SQLITE_BIGENDIAN */ #include "tcl.h" #include <stdlib.h> #include <string.h> /* ** Return the number of bytes up to and including the first pair of ** 0x00 bytes in *pStr. |
︙ | ︙ | |||
163 164 165 166 167 168 169 | if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <utf-16 encoded-string>", 0); return TCL_ERROR; } in = Tcl_GetByteArrayFromObj(objv[1], 0); | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetStringFromObj(objv[0], 0), " <utf-16 encoded-string>", 0); return TCL_ERROR; } in = Tcl_GetByteArrayFromObj(objv[1], 0); out = sqlite3utf16to8(in, -1, SQLITE_BIGENDIAN); res = Tcl_NewByteArrayObj(out, strlen(out)+1); sqliteFree(out); Tcl_SetObjResult(interp, res); return TCL_OK; } |
︙ | ︙ | |||
217 218 219 220 221 222 223 | int i; for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); } return TCL_OK; } | < < < | 217 218 219 220 221 222 223 | int i; for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); } return TCL_OK; } |
Changes to src/tokenize.c.
︙ | ︙ | |||
11 12 13 14 15 16 17 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ************************************************************************* ** An tokenizer for SQL ** ** This file contains C code that splits an SQL input string up into ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** ** $Id: tokenize.c,v 1.75 2004/05/31 18:51:58 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include <stdlib.h> /* |
︙ | ︙ | |||
698 699 700 701 702 703 704 | /* ** This routine is the same as the sqlite3_complete() routine described ** above, except that the parameter is required to be UTF-16 encoded, not ** UTF-8. */ int sqlite3_complete16(const void *zSql){ int rc; | | < | 698 699 700 701 702 703 704 705 706 707 708 709 710 | /* ** This routine is the same as the sqlite3_complete() routine described ** above, except that the parameter is required to be UTF-16 encoded, not ** UTF-8. */ int sqlite3_complete16(const void *zSql){ int rc; char *zSql8 = sqlite3utf16to8(zSql, -1, SQLITE_BIGENDIAN); if( !zSql8 ) return 0; rc = sqlite3_complete(zSql8); sqliteFree(zSql8); return rc; } |
Changes to src/utf.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 to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** | | | 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 to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** ** $Id: utf.c,v 1.15 2004/05/31 18:51:58 drh Exp $ ** ** Notes on UTF-8: ** ** Byte-0 Byte-1 Byte-2 Byte-3 Value ** 0xxxxxxx 00000000 00000000 0xxxxxxx ** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx ** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx |
︙ | ︙ | |||
58 59 60 61 62 63 64 | int n; /* Allocated length of pZ in bytes */ int c; /* Number of pZ bytes already read or written */ }; /* TODO: Implement this macro in os.h. It should be 1 on big-endian ** machines, and 0 on little-endian. */ | | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | int n; /* Allocated length of pZ in bytes */ int c; /* Number of pZ bytes already read or written */ }; /* TODO: Implement this macro in os.h. It should be 1 on big-endian ** machines, and 0 on little-endian. */ #define SQLITE_NATIVE_BIGENDIAN 0 #if SQLITE_NATIVE_BIGENDIAN == 1 #define BOM_BIGENDIAN 0x0000FFFE #define BOM_LITTLEENDIAN 0x0000FEFF #else #define BOM_BIGENDIAN 0x0000FEFF #define BOM_LITTLEENDIAN 0x0000FFFE #endif |
︙ | ︙ | |||
519 520 521 522 523 524 525 | inout.c = 0; inout.n = N; if( inout.n<0 ){ inout.n = sqlite3utf16ByteLen(inout.pZ, -1); } | | | 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | inout.c = 0; inout.n = N; if( inout.n<0 ){ inout.n = sqlite3utf16ByteLen(inout.pZ, -1); } if( readUtf16Bom(&inout, SQLITE_BIGENDIAN)!=big_endian ){ /* swab(&inout.pZ[inout.c], inout.pZ, inout.n-inout.c); */ int i; for(i=0; i<(inout.n-inout.c); i += 2){ char c1 = inout.pZ[i+inout.c]; char c2 = inout.pZ[i+inout.c+1]; inout.pZ[i] = c2; inout.pZ[i+1] = c1; |
︙ | ︙ |
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.353 2004/05/31 18:51:58 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
134 135 136 137 138 139 140 | ** stack variables. This routine sets the pMem->enc and pMem->type ** variables used by the sqlite3_value_*() routines. */ #define storeTypeInfo(A,B) _storeTypeInfo(A) static void _storeTypeInfo(Mem *pMem){ int flags = pMem->flags; if( flags & MEM_Null ){ | | | | | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | ** stack variables. This routine sets the pMem->enc and pMem->type ** variables used by the sqlite3_value_*() routines. */ #define storeTypeInfo(A,B) _storeTypeInfo(A) static void _storeTypeInfo(Mem *pMem){ int flags = pMem->flags; if( flags & MEM_Null ){ pMem->type = SQLITE_NULL; } else if( flags & MEM_Int ){ pMem->type = SQLITE_INTEGER; } else if( flags & MEM_Real ){ pMem->type = SQLITE_FLOAT; } else if( flags & MEM_Str ){ pMem->type = SQLITE_TEXT; }else{ pMem->type = SQLITE_BLOB; } } /* ** Insert a new aggregate element and make it the element that ** has focus. ** |
︙ | ︙ |
Changes to src/vdbeInt.h.
︙ | ︙ | |||
120 121 122 123 124 125 126 | ** Internally, the vdbe manipulates nearly all SQL values as Mem ** structures. Each Mem struct may cache multiple representations (string, ** integer etc.) of the same value. A value (and therefore Mem structure) ** has the following properties: ** ** Each value has a manifest type. The manifest type of the value stored ** in a Mem struct is returned by the MemType(Mem*) macro. The type is | | | | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | ** Internally, the vdbe manipulates nearly all SQL values as Mem ** structures. Each Mem struct may cache multiple representations (string, ** integer etc.) of the same value. A value (and therefore Mem structure) ** has the following properties: ** ** Each value has a manifest type. The manifest type of the value stored ** in a Mem struct is returned by the MemType(Mem*) macro. The type is ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or ** SQLITE_BLOB. */ struct Mem { i64 i; /* Integer value */ int n; /* Number of characters in string value, including '\0' */ u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ u8 type; /* One of MEM_Null, MEM_Str, etc. */ u8 enc; /* TEXT_Utf8, TEXT_Utf16le, or TEXT_Utf16be */ |
︙ | ︙ |
Changes to src/vdbeapi.c.
︙ | ︙ | |||
493 494 495 496 497 498 499 | ** byte after the BOM. */ txt_enc = sqlite3UtfReadBom(zData, nData); if( txt_enc ){ zData = (void *)(((u8 *)zData) + 2); nData -= 2; }else{ | | | 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | ** byte after the BOM. */ txt_enc = sqlite3UtfReadBom(zData, nData); if( txt_enc ){ zData = (void *)(((u8 *)zData) + 2); nData -= 2; }else{ txt_enc = SQLITE_BIGENDIAN?TEXT_Utf16be:TEXT_Utf16le; } rc = sqlite3VdbeMemSetStr(pVar, zData, nData, txt_enc, eCopy); if( rc ){ return rc; } rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc); return rc; |
︙ | ︙ |
Changes to src/vdbeaux.c.
︙ | ︙ | |||
567 568 569 570 571 572 573 | } rc = SQLITE_ERROR; sqlite3SetString(&p->zErrMsg, sqlite3_error_string(p->rc), (char*)0); }else{ Op *pOp = &p->aOp[i]; Mem *pMem = p->aStack; pMem->flags = MEM_Int; | | | | | | | 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | } rc = SQLITE_ERROR; sqlite3SetString(&p->zErrMsg, sqlite3_error_string(p->rc), (char*)0); }else{ Op *pOp = &p->aOp[i]; Mem *pMem = p->aStack; pMem->flags = MEM_Int; pMem->type = SQLITE_INTEGER; pMem->i = i; /* Program counter */ pMem++; pMem->flags = MEM_Static|MEM_Str|MEM_Term; pMem->z = sqlite3OpcodeNames[pOp->opcode]; /* Opcode */ pMem->n = strlen(pMem->z); pMem->type = SQLITE_TEXT; pMem->enc = TEXT_Utf8; pMem++; pMem->flags = MEM_Int; pMem->i = pOp->p1; /* P1 */ pMem->type = SQLITE_INTEGER; pMem++; pMem->flags = MEM_Int; pMem->i = pOp->p2; /* P2 */ pMem->type = SQLITE_INTEGER; pMem++; pMem->flags = MEM_Short|MEM_Str|MEM_Term; /* P3 */ pMem->z = displayP3(pOp, pMem->zShort, sizeof(pMem->zShort)); pMem->type = SQLITE_TEXT; pMem->enc = TEXT_Utf8; p->nResColumn = 5; p->pTos = pMem; p->rc = SQLITE_OK; p->resOnStack = 1; rc = SQLITE_ROW; |
︙ | ︙ |
Changes to src/vdbemem.c.
︙ | ︙ | |||
175 176 177 178 179 180 181 | /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8 ** string representation of the value. Then, if the required encoding ** is UTF-16le or UTF-16be do a translation. ** ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16. */ u8 *z = pMem->zShort; | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8 ** string representation of the value. Then, if the required encoding ** is UTF-16le or UTF-16be do a translation. ** ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16. */ u8 *z = pMem->zShort; if( fg & MEM_Real || (pMem->type==SQLITE_FLOAT) ){ sqlite3_snprintf(NBFS, z, "%.15g", pMem->r); }else{ assert( fg & MEM_Int ); sqlite3_snprintf(NBFS, z, "%lld", pMem->i); } pMem->n = strlen(z); pMem->z = z; |
︙ | ︙ | |||
232 233 234 235 236 237 238 | ** Add MEM_Real to the set of representations for pMem. Prior ** prior representations other than MEM_Null retained. NULL is ** converted into 0.0. */ int sqlite3VdbeMemRealify(Mem *pMem){ if( pMem->flags & MEM_Real ){ /* Do nothing */ | | | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | ** Add MEM_Real to the set of representations for pMem. Prior ** prior representations other than MEM_Null retained. NULL is ** converted into 0.0. */ int sqlite3VdbeMemRealify(Mem *pMem){ if( pMem->flags & MEM_Real ){ /* Do nothing */ }else if( (pMem->flags & MEM_Int) && pMem->type!=SQLITE_TEXT ){ pMem->r = pMem->i; }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ if( sqlite3VdbeChangeEncoding(pMem, TEXT_Utf8) || sqlite3VdbeMemNulTerminate(pMem) ){ return SQLITE_NOMEM; } assert( pMem->z ); |
︙ | ︙ | |||
254 255 256 257 258 259 260 | /* ** Delete any previous value and set the value stored in *pMem to NULL. */ void sqlite3VdbeMemSetNull(Mem *pMem){ releaseMem(pMem); pMem->flags = MEM_Null; | | | | | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | /* ** Delete any previous value and set the value stored in *pMem to NULL. */ void sqlite3VdbeMemSetNull(Mem *pMem){ releaseMem(pMem); pMem->flags = MEM_Null; pMem->type = SQLITE_NULL; } /* ** Delete any previous value and set the value stored in *pMem to val, ** manifest type INTEGER. */ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){ releaseMem(pMem); pMem->i = val; pMem->flags = MEM_Int; pMem->type = SQLITE_INTEGER; } /* ** Delete any previous value and set the value stored in *pMem to val, ** manifest type REAL. */ void sqlite3VdbeMemSetDouble(Mem *pMem, double val){ releaseMem(pMem); pMem->r = val; pMem->flags = MEM_Real; pMem->type = SQLITE_FLOAT; } /* ** Copy the contents of memory cell pFrom into pTo. */ int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ releaseMem(pTo); |
︙ | ︙ | |||
306 307 308 309 310 311 312 | int n, /* Bytes in string, or negative */ u8 enc, /* Encoding of z. 0 for BLOBs */ int eCopy /* True if this function should make a copy of z */ ){ releaseMem(pMem); if( !z ){ pMem->flags = MEM_Null; | | | | 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 | int n, /* Bytes in string, or negative */ u8 enc, /* Encoding of z. 0 for BLOBs */ int eCopy /* True if this function should make a copy of z */ ){ releaseMem(pMem); if( !z ){ pMem->flags = MEM_Null; pMem->type = SQLITE_NULL; return SQLITE_OK; } pMem->z = (char *)z; if( eCopy ){ pMem->flags = MEM_Ephem; }else{ pMem->flags = MEM_Static; } pMem->enc = enc; pMem->type = enc==0 ? SQLITE_BLOB : SQLITE_TEXT; pMem->n = n; switch( enc ){ case 0: pMem->flags |= MEM_Blob; break; case TEXT_Utf8: |
︙ | ︙ | |||
487 488 489 490 491 492 493 | pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term; }else{ zData = &(pMem->zShort[0]); pMem->flags = MEM_Blob|MEM_Short|MEM_Term; } pMem->z = zData; pMem->enc = 0; | | | 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term; }else{ zData = &(pMem->zShort[0]); pMem->flags = MEM_Blob|MEM_Short|MEM_Term; } pMem->z = zData; pMem->enc = 0; pMem->type = SQLITE_BLOB; if( key ){ rc = sqlite3BtreeKey(pCur, offset, amt, zData); }else{ rc = sqlite3BtreeData(pCur, offset, amt, zData); } zData[amt] = 0; |
︙ | ︙ |
Changes to www/capi3.tcl.
|
| | | 1 2 3 4 5 6 7 8 | set rcsid {$Id: capi3.tcl,v 1.2 2004/05/31 18:51:59 drh Exp $} source common.tcl header {C/C++ Interface For SQLite Version 3} puts { <h2>C/C++ Interface For SQLite Version 3</h2> <h3>1.0 Overview</h3> |
︙ | ︙ | |||
85 86 87 88 89 90 91 92 93 94 95 96 97 98 | text error message for the most recent error. The error message will be represented in UTF-8 and will be ephemeral - it could disappear on the next call to any SQLite API function. sqlite3_errmsg16() works like sqlite3_errmsg() except that it returns the error message represented as UTF-16 in host native byte order. </p> <h4>2.2 Executing SQL statements</h4> <blockquote><pre> typedef struct sqlite3_stmt sqlite3_stmt; int sqlite3_prepare(sqlite3*, const char*, sqlite3_stmt**, const char**); int sqlite3_prepare16(sqlite3*, const void*, sqlite3_stmt**, const void**); int sqlite3_finalize(sqlite3_stmt*); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | text error message for the most recent error. The error message will be represented in UTF-8 and will be ephemeral - it could disappear on the next call to any SQLite API function. sqlite3_errmsg16() works like sqlite3_errmsg() except that it returns the error message represented as UTF-16 in host native byte order. </p> <p> The error codes for SQLite version 3 are unchanged from version2. They are as follows: </p> <blockquote><pre> #define SQLITE_OK 0 /* Successful result */ #define SQLITE_ERROR 1 /* SQL error or missing database */ #define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */ #define SQLITE_PERM 3 /* Access permission denied */ #define SQLITE_ABORT 4 /* Callback routine requested an abort */ #define SQLITE_BUSY 5 /* The database file is locked */ #define SQLITE_LOCKED 6 /* A table in the database is locked */ #define SQLITE_NOMEM 7 /* A malloc() failed */ #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */ #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ #define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */ #define SQLITE_FULL 13 /* Insertion failed because database is full */ #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ #define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */ #define SQLITE_SCHEMA 17 /* The database schema changed */ #define SQLITE_TOOBIG 18 /* Too much data for one row of a table */ #define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */ #define SQLITE_MISMATCH 20 /* Data type mismatch */ #define SQLITE_MISUSE 21 /* Library used incorrectly */ #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ #define SQLITE_AUTH 23 /* Authorization denied */ #define SQLITE_ROW 100 /* sqlite_step() has another row ready */ #define SQLITE_DONE 101 /* sqlite_step() has finished executing */ </pre></blockquote> <h4>2.2 Executing SQL statements</h4> <blockquote><pre> typedef struct sqlite3_stmt sqlite3_stmt; int sqlite3_prepare(sqlite3*, const char*, sqlite3_stmt**, const char**); int sqlite3_prepare16(sqlite3*, const void*, sqlite3_stmt**, const void**); int sqlite3_finalize(sqlite3_stmt*); |
︙ | ︙ | |||
189 190 191 192 193 194 195 | The sqlite3_column_count() function returns the number of columns in the results set. The sqlite3_column_type() function returns the datatype for the value in the Nth column. The return value is one of these: </p> <blockquote><pre> | | | | | | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | The sqlite3_column_count() function returns the number of columns in the results set. The sqlite3_column_type() function returns the datatype for the value in the Nth column. The return value is one of these: </p> <blockquote><pre> #define SQLITE_INTEGER 1 #define SQLITE_FLOAT 2 #define SQLITE_TEXT 3 #define SQLITE_BLOB 4 #define SQLITE_NULL 5 </pre></blockquote> <p> The sqlite3_column_decltype() routine returns text which is the declared type of the column in the CREATE TABLE statement. For an expression, the return type is an empty string. sqlite3_column_name() returns the name of the Nth column. sqlite3_column_bytes() returns |
︙ | ︙ |
Changes to www/datatype3.tcl.
|
| | | 1 2 3 4 5 6 7 8 | set rcsid {$Id: datatype3.tcl,v 1.2 2004/05/31 18:51:59 drh Exp $} source common.tcl header {Datatypes In SQLite Version 3} puts { <h2>Datatypes In SQLite Version 3</h2> <h3>1. Storage Classes</h3> |
︙ | ︙ | |||
119 120 121 122 123 124 125 | is assigned INTEGER affinity.</P> <LI><P>If the datatype of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.</P> | | > | | | | | | > | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | is assigned INTEGER affinity.</P> <LI><P>If the datatype of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.</P> <LI><P>If the datatype for a column contains the string "BLOB" or if not datatype is specified then the column has affinity NONE.</P> <LI><P>Otherwise, the affinity is NUMERIC. Notice that a column where no datatype is specified is given affinity NUMERIC.</P> </OL> <P>If a table is created using a "CREATE TABLE <table> AS SELECT..." statement, then all columns have no datatype specified and they are given no affinity.</P> <h4>2.2 Column Affinity Example</h4> <blockquote> <PRE>CREATE TABLE t1( t TEXT, nu NUMERIC, i INTEGER, no BLOB ); -- Storage classes for the following row: -- TEXT, REAL, INTEGER, TEXT INSERT INTO t1 VALUES('500.0', '500.0', '500.0', '500.0'); -- Storage classes for the following row: -- TEXT, REAL, INTEGER, REAL INSERT INTO t1 VALUES(500.0, 500.0, 500.0, 500.0); </PRE> </blockquote> <h3>3. Comparison Expressions</h3> <P>Like SQLite version 2, version 3 features the binary comparison operators '=', '<', '<=', '>=' and '!=', an operation to test for set |
︙ | ︙ | |||
197 198 199 200 201 202 203 | affinity is applied to both values before the comparison takes place.</P> </UL> <h4>3.1 Comparison Example</h4> <blockquote> | > | | | | | | > > | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | affinity is applied to both values before the comparison takes place.</P> </UL> <h4>3.1 Comparison Example</h4> <blockquote> <PRE> CREATE TABLE t1( a TEXT, b NUMERIC, c BLOB ); -- Storage classes for the following row: -- TEXT, REAL, TEXT INSERT INTO t1 VALUES('500', '500', '500'); -- 60 and 40 are converted to '60' and '40' and values are compared as TEXT. SELECT a < 60, a < 40 FROM t1; 1|0 -- Comparisons are numeric. No conversions are required. SELECT b < 60, b < 600 FROM t1; 0|1 -- Both 60 and 600 (storage class NUMERIC) are less than '500' -- (storage class TEXT). SELECT c < 60, c < 600 FROM t1; 0|0 </PRE> </blockquote> <P> In SQLite, the expression "a BETWEEN b AND c" is currently equivalent to "a >= b AND a <= c". SQLite will continue to treat the two as exactly equivalent, even if this means that different affinities are applied to 'a' in each of the comparisons |
︙ | ︙ |