Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Change the table record format to support manifest typing. (CVS 1361) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
0242c9e4f7c85e9c911cf30d90b0cdb1 |
User & Date: | danielk1977 2004-05-12 07:33:33.000 |
Context
2004-05-12
| ||
11:24 | Add some more code to support manifest typing in indices. Not activated yet. (CVS 1362) (check-in: 2f16c9ef3c user: danielk1977 tags: trunk) | |
07:33 | Change the table record format to support manifest typing. (CVS 1361) (check-in: 0242c9e4f7 user: danielk1977 tags: trunk) | |
2004-05-11
| ||
10:04 | Change sqlite_ to sqlite3_ in the attach2.test test script. (CVS 1360) (check-in: 98f756e6a0 user: drh tags: trunk) | |
Changes
Changes to src/printf.c.
︙ | ︙ | |||
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | if( longvalue==0 ) flag_alternateform = 0; #else /* More sensible: turn off the prefix for octal (to prevent "00"), ** but leave the prefix for hex. */ if( longvalue==0 && infop->base==8 ) flag_alternateform = 0; #endif if( infop->flags & FLAG_SIGNED ){ if( *(long*)&longvalue<0 ){ longvalue = -*(long*)&longvalue; prefix = '-'; }else if( flag_plussign ) prefix = '+'; else if( flag_blanksign ) prefix = ' '; else prefix = 0; }else prefix = 0; if( flag_zeropad && precision<width-(prefix!=0) ){ precision = width-(prefix!=0); } bufpt = &buf[etBUFSIZE-1]; { register char *cset; /* Use registers for speed */ | > > > > > > > > > | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | if( longvalue==0 ) flag_alternateform = 0; #else /* More sensible: turn off the prefix for octal (to prevent "00"), ** but leave the prefix for hex. */ if( longvalue==0 && infop->base==8 ) flag_alternateform = 0; #endif if( infop->flags & FLAG_SIGNED ){ if( flag_longlong ){ if( *(i64*)&longvalue<0 ){ longvalue = -*(i64*)&longvalue; prefix = '-'; }else if( flag_plussign ) prefix = '+'; else if( flag_blanksign ) prefix = ' '; else prefix = 0; }else{ if( *(long*)&longvalue<0 ){ longvalue = -*(long*)&longvalue; prefix = '-'; }else if( flag_plussign ) prefix = '+'; else if( flag_blanksign ) prefix = ' '; else prefix = 0; } }else prefix = 0; if( flag_zeropad && precision<width-(prefix!=0) ){ precision = width-(prefix!=0); } bufpt = &buf[etBUFSIZE-1]; { register char *cset; /* Use registers for speed */ |
︙ | ︙ |
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.230 2004/05/12 07:33:33 danielk1977 Exp $ */ #include "config.h" #include "sqlite.h" #include "hash.h" #include "parse.h" #include <stdio.h> #include <stdlib.h> |
︙ | ︙ | |||
1284 1285 1286 1287 1288 1289 1290 | void *sqlite3utf8to16be(const unsigned char *pIn, int N); void *sqlite3utf8to16le(const unsigned char *pIn, int N); void sqlite3utf16to16le(void *pData, int N); void sqlite3utf16to16be(void *pData, int N); int sqlite3PutVarint(unsigned char *, u64); int sqlite3GetVarint(const unsigned char *, u64 *); int sqlite3VarintLen(u64 v); | > > | 1284 1285 1286 1287 1288 1289 1290 1291 1292 | void *sqlite3utf8to16be(const unsigned char *pIn, int N); void *sqlite3utf8to16le(const unsigned char *pIn, int N); void sqlite3utf16to16le(void *pData, int N); void sqlite3utf16to16be(void *pData, int N); int sqlite3PutVarint(unsigned char *, u64); int sqlite3GetVarint(const unsigned char *, u64 *); int sqlite3VarintLen(u64 v); |
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.283 2004/05/12 07:33:33 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> #include "vdbeInt.h" /* |
︙ | ︙ | |||
195 196 197 198 199 200 201 | */ #define Stringify(P) if(((P)->flags & MEM_Str)==0){hardStringify(P);} static int hardStringify(Mem *pStack){ int fg = pStack->flags; if( fg & MEM_Real ){ sqlite3_snprintf(sizeof(pStack->zShort),pStack->zShort,"%.15g",pStack->r); }else if( fg & MEM_Int ){ | | | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | */ #define Stringify(P) if(((P)->flags & MEM_Str)==0){hardStringify(P);} static int hardStringify(Mem *pStack){ int fg = pStack->flags; if( fg & MEM_Real ){ sqlite3_snprintf(sizeof(pStack->zShort),pStack->zShort,"%.15g",pStack->r); }else if( fg & MEM_Int ){ sqlite3_snprintf(sizeof(pStack->zShort),pStack->zShort,"%lld",pStack->i); }else{ pStack->zShort[0] = 0; } pStack->z = pStack->zShort; pStack->n = strlen(pStack->zShort)+1; pStack->flags = MEM_Str | MEM_Short; return 0; |
︙ | ︙ | |||
1010 1011 1012 1013 1014 1015 1016 | assert( pNos>=p->aStack ); if( ((pTos->flags | pNos->flags) & MEM_Null)!=0 ){ Release(pTos); pTos--; Release(pTos); pTos->flags = MEM_Null; }else if( (pTos->flags & pNos->flags & MEM_Int)==MEM_Int ){ | | | 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | assert( pNos>=p->aStack ); if( ((pTos->flags | pNos->flags) & MEM_Null)!=0 ){ Release(pTos); pTos--; Release(pTos); pTos->flags = MEM_Null; }else if( (pTos->flags & pNos->flags & MEM_Int)==MEM_Int ){ i64 a, b; a = pTos->i; b = pNos->i; switch( pOp->opcode ){ case OP_Add: b += a; break; case OP_Subtract: b -= a; break; case OP_Multiply: b *= a; break; case OP_Divide: { |
︙ | ︙ | |||
1807 1808 1809 1810 1811 1812 1813 | if( i>=cnt ) pc = pOp->p2-1; if( pOp->p1>0 ) popStack(&pTos, cnt); break; } /* Opcode: Column3 P1 P2 * ** | | | | < | | | < | | < | | | | | | | | | | | | > > > > | < | < < > > > > > | 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 | if( i>=cnt ) pc = pOp->p2-1; if( pOp->p1>0 ) popStack(&pTos, cnt); break; } /* Opcode: Column3 P1 P2 * ** ** This opcode (not yet in use) is a replacement for the current OP_Column3 ** that supports the SQLite3 manifest typing feature. ** ** Interpret the data that cursor P1 points to as a structure built using ** the MakeRecord instruction. (See the MakeRecord opcode for additional ** information about the format of the data.) Push onto the stack the value ** of the P2-th column contained in the data. ** ** If the KeyAsData opcode has previously executed on this cursor, then the ** field might be extracted from the key rather than the data. ** ** If P1 is negative, then the record is stored on the stack rather than in ** a table. For P1==-1, the top of the stack is used. For P1==-2, the ** next on the stack is used. And so forth. The value pushed is always ** just a pointer into the record which is stored further down on the ** stack. The column value is not copied. */ case OP_Column: { int payloadSize; /* Number of bytes in the record */ int i = pOp->p1; int p2 = pOp->p2; /* column number to retrieve */ Cursor *pC; char *zRec; /* Pointer to record-data from stack or pseudo-table. */ BtCursor *pCrsr; char *zData; int freeZdata = 0; /* zData requires sqliteFree() */ u64 nFields; /* number of fields in the record */ u64 *aTypes; /* An array of serial types (size nFields) */ int len; /* The length of the serialized data for the column */ int offset; int nn; assert( i<p->nCursor ); pTos++; /* This block sets the variable payloadSize, and if the data is coming ** from the stack or from a pseudo-table zRec. If the data is coming ** from a real cursor, then zRec is left as NULL. */ if( i<0 ){ assert( &pTos[i]>=p->aStack ); assert( pTos[i].flags & MEM_Str ); zRec = pTos[i].z; payloadSize = pTos[i].n; }else if( (pC = &p->aCsr[i])->pCursor!=0 ){ sqlite3VdbeCursorMoveto(pC); |
︙ | ︙ | |||
1878 1879 1880 1881 1882 1883 1884 | /* If payloadSize is 0, then just push a NULL onto the stack. */ if( payloadSize==0 ){ pTos->flags = MEM_Null; break; } | | > > > < > < > > > | | > > | | > > > > > > > > > > > > > > | < < > > | > > | > > > > > > > > | | < | | > > > > | < < < < < < < < < < > | | > > > | | < | | | < < < < < < < > > > | | | < | | > > | > | > | < > > > > | > > > > > | | > > > > > > > | > > > > | > > > > > > | | | | | | < | < < < < < < < < < < < | > | < > > | | < < | < < < < < | < < < | | | | > > > | | > > > | < > > > < < | < > > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < | | 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 | /* If payloadSize is 0, then just push a NULL onto the stack. */ if( payloadSize==0 ){ pTos->flags = MEM_Null; break; } /* Read the number of fields for the record. ** FIX ME: The Cursor object should cache this data and the array of ** field types for subsequent OP_Column instructions. */ if( zRec ){ zData = zRec; }else{ /* We can assume that 9 bytes (maximum length of a varint) fits ** on the main page in all cases. */ if( pC->keyAsData ){ zData = (char *)sqlite3BtreeKeyFetch(pCrsr, 9>payloadSize?payloadSize:9); }else{ zData = (char *)sqlite3BtreeDataFetch(pCrsr, 9>payloadSize?payloadSize:9); } assert( zData ); } offset = sqlite3GetVarint(zData, &nFields); if( !zRec ){ /* If the record is stored in a table, see if enough of it is on ** the main page to use sqlite3BtreeDataFetch() to get the data ** containing the nFields serial types (varints). This will almost ** always work, but if it doesn't sqliteMalloc() space and use ** sqlite3BtreeData(). ** ** Estimate the maximum space required by the nFields varints by ** assuming the maximum space for each is the length required to store: ** ** (<record length> * 2) + 13 ** ** This is the serial-type for a text object as long as the record ** itself. In all cases the length required to store this is three ** bytes or less. */ int max_space = sqlite3VarintLen((((u64)payloadSize)<<1)+13)*nFields; max_space += offset; if( max_space>payloadSize ){ max_space = payloadSize; } if( pC->keyAsData ){ zData = (char *)sqlite3BtreeKeyFetch(pCrsr, max_space); }else{ zData = (char *)sqlite3BtreeDataFetch(pCrsr, max_space); } if( !zData ){ /* This code will run very infrequently (e.g. tables with several ** hundred columns). */ zData = (char *)sqliteMalloc(offset+max_space); if( !zData ){ rc = SQLITE_NOMEM; goto abort_due_to_error; } if( pC->keyAsData ){ rc = sqlite3BtreeKey(pCrsr, 0, max_space, zData); }else{ rc = sqlite3BtreeData(pCrsr, 0, max_space, zData); } if( rc!=SQLITE_OK ){ sqliteFree(zData); goto abort_due_to_error; } freeZdata = 1; } } /* Dynamically allocate space for the aTypes array. and read all ** the serial types for the record. At the end of this block variable ** offset is set to the offset to the start of Data0 in the record. */ aTypes = (u64 *)sqliteMalloc(sizeof(u64)*nFields); if( !aTypes ){ if( freeZdata ){ sqliteFree(zData); freeZdata = 0; } rc = SQLITE_NOMEM; goto abort_due_to_error; } for(nn=0; nn<nFields; nn++){ offset += sqlite3GetVarint(&zData[offset], &aTypes[nn]); } if( freeZdata ){ freeZdata = 0; sqliteFree(zData); } for(nn=0; nn<p2; nn++){ offset += sqlite3VdbeSerialTypeLen(aTypes[nn]); } len = sqlite3VdbeSerialTypeLen(aTypes[p2]); if( !zRec ){ /* If the record is stored in a table, see if enough of it ** is on the main page to read our column using ** sqlite3BtreeDataFetch(). If not sqliteMalloc() space and read data ** with sqlite3BtreeData(). */ if( pC->keyAsData ){ zData = (char *)sqlite3BtreeKeyFetch(pCrsr, offset+len); }else{ zData = (char *)sqlite3BtreeDataFetch(pCrsr, offset+len); } if( !zData && len>0 ){ zData = (char *)sqliteMalloc(len); if( !zData ){ sqliteFree(aTypes); rc = SQLITE_NOMEM; goto abort_due_to_error; } if( pC->keyAsData ){ rc = sqlite3BtreeKey(pCrsr, offset, len, zData); }else{ rc = sqlite3BtreeData(pCrsr, offset, len, zData); } if( rc!=SQLITE_OK ){ sqliteFree( aTypes ); sqliteFree( zData ); goto abort_due_to_error; } freeZdata = 1; offset = 0; } } /* Deserialize the value directly into the top of the stack */ sqlite3VdbeSerialGet(&zData[offset], aTypes[p2], pTos); sqliteFree(aTypes); if( freeZdata ){ sqliteFree(zData); } break; } /* Opcode MakeRecord3 P1 * * ** ** This opcode (not yet in use) is a replacement for the current ** OP_MakeRecord that supports the SQLite3 manifest typing feature. ** It drops the (P2==1) option that was never use. ** ** Convert the top P1 entries of the stack into a single entry ** suitable for use as a data record in a database table. The ** details of the format are irrelavant as long as the OP_Column ** opcode can decode the record later. Refer to source code ** comments for the details of the record format. */ case OP_MakeRecord: { /* Assuming the record contains N fields, the record format looks ** like this: ** ** -------------------------------------------------------------------------- ** | num-fields | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | ** -------------------------------------------------------------------------- ** ** Data(0) is taken from the lowest element of the stack and data(N-1) is ** the top of the stack. ** ** Each type field is a varint representing the serial type of the ** corresponding data element (see sqlite3VdbeSerialType()). The ** num-fields field is also a varint storing N. ** ** TODO: Even when the record is short enough for Mem::zShort, this opcode ** allocates it dynamically. */ int nField = pOp->p1; unsigned char *zNewRecord; unsigned char *zCsr; Mem *pRec; int nBytes; /* Space required for this record */ Mem *pData0 = &pTos[1-nField]; assert( pData0>=p->aStack ); /* Loop through the elements that will make up the record to figure ** out how much space is required for the new record. */ nBytes = sqlite3VarintLen(nField); for(pRec=pData0; pRec<=pTos; pRec++){ u64 serial_type = sqlite3VdbeSerialType(pRec); nBytes += sqlite3VdbeSerialTypeLen(serial_type); nBytes += sqlite3VarintLen(serial_type); } /* Allocate space for the new record. */ zNewRecord = sqliteMalloc(nBytes); if( !zNewRecord ){ rc = SQLITE_NOMEM; goto abort_due_to_error; } /* Write the record */ zCsr = zNewRecord; zCsr += sqlite3PutVarint(zCsr, nField); /* number of fields */ for(pRec=pData0; pRec<=pTos; pRec++){ u64 serial_type = sqlite3VdbeSerialType(pRec); zCsr += sqlite3PutVarint(zCsr, serial_type); /* serial type */ } for(pRec=pData0; pRec<=pTos; pRec++){ zCsr += sqlite3VdbeSerialPut(zCsr, pRec); /* serial data */ } /* If zCsr has not been advanced exactly nBytes bytes, then one ** of the sqlite3PutVarint() or sqlite3VdbeSerialPut() calls above ** failed. This indicates a corrupted memory cell or code bug. */ if( zCsr!=(zNewRecord+nBytes) ){ rc = SQLITE_INTERNAL; goto abort_due_to_error; } /* Pop nField entries from the stack and push the new entry on */ popStack(&pTos, nField); pTos++; pTos->n = nBytes; pTos->z = zNewRecord; pTos->flags = MEM_Str | MEM_Dyn; break; } /* Opcode: MakeKey P1 P2 P3 ** ** Convert the top P1 entries of the stack into a single entry suitable ** for use as the key in an index. The top P1 records are |
︙ | ︙ | |||
3395 3396 3397 3398 3399 3400 3401 | }else if( pC->pseudoTable ){ pTos->n = pC->nData; pTos->z = pC->pData; pTos->flags = MEM_Str|MEM_Ephem; }else{ pTos->flags = MEM_Null; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 | }else if( pC->pseudoTable ){ pTos->n = pC->nData; pTos->z = pC->pData; pTos->flags = MEM_Str|MEM_Ephem; }else{ pTos->flags = MEM_Null; } break; } /* Opcode: Recno P1 * * ** ** Push onto the stack an integer which is the first 4 bytes of the ** the key to the current entry in a sequential scan of the database |
︙ | ︙ |
Changes to src/vdbeInt.h.
︙ | ︙ | |||
313 314 315 316 317 318 319 | void sqlite3VdbeKeylistFree(Keylist*); void sqliteVdbePopStack(Vdbe*,int); int sqlite3VdbeCursorMoveto(Cursor*); int sqlite3VdbeByteSwap(int); #if !defined(NDEBUG) || defined(VDBE_PROFILE) void sqlite3VdbePrintOp(FILE*, int, Op*); #endif | | > | | | 313 314 315 316 317 318 319 320 321 322 323 324 325 | void sqlite3VdbeKeylistFree(Keylist*); void sqliteVdbePopStack(Vdbe*,int); int sqlite3VdbeCursorMoveto(Cursor*); int sqlite3VdbeByteSwap(int); #if !defined(NDEBUG) || defined(VDBE_PROFILE) void sqlite3VdbePrintOp(FILE*, int, Op*); #endif int sqlite3VdbeSerialTypeLen(u64); u64 sqlite3VdbeSerialType(const Mem *); int sqlite3VdbeSerialPut(unsigned char *, const Mem *); int sqlite3VdbeSerialGet(const unsigned char *, u64, Mem *); int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
Changes to src/vdbeaux.c.
︙ | ︙ | |||
1103 1104 1105 1106 1107 1108 1109 | *pResult = memcmp(pMallocedKey, pKey, nKey>nCellKey?nCellKey:nKey); sqliteFree(pMallocedKey); return rc; } /* | | | > > | | > > > > > > > | > > | | < | > | < < | | | > | > | > > > > | | < | | < < < < | | < < < | < < | < < < < < < < < < < < < < | | < < < < < < | > > > | > > > > > | | > > | < | > > | > > | | > > > > > > > > | > | < < < | < | < > | | > < < < < | | > > > | | | | < < < < < | | > | > | | | > | | < > > | | < < > > > | < | | < | < > | > | > > > | | | | > > | > | < < | < | | 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 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 | *pResult = memcmp(pMallocedKey, pKey, nKey>nCellKey?nCellKey:nKey); sqliteFree(pMallocedKey); return rc; } /* ** The following functions: ** ** sqlite3VdbeSerialType() ** sqlite3VdbeSerialTypeLen() ** sqlite3VdbeSerialRead() ** sqlite3VdbeSerialLen() ** sqlite3VdbeSerialWrite() ** ** encapsulate the code that serializes values for storage in SQLite ** data and index records. Each serialized value consists of a ** 'serial-type' and a blob of data. The serial type is an 8-byte unsigned ** integer, stored as a varint. ** ** In an SQLite index record, the serial type is stored directly before ** the blob of data that it corresponds to. In a table record, all serial ** types are stored at the start of the record, and the blobs of data at ** the end. Hence these functions allow the caller to handle the ** serial-type and data blob seperately. ** ** The following table describes the various storage classes for data: ** ** serial type bytes of data type ** -------------- --------------- --------------- ** 0 0 NULL ** 1 1 signed integer ** 2 2 signed integer ** 3 4 signed integer ** 4 8 signed integer ** 5 8 IEEE float ** 6..12 reserved for expansion ** N>=12 and even (N-12)/2 BLOB ** N>=13 and odd (N-13)/2 text ** */ /* ** Return the serial-type for the value stored in pMem. */ u64 sqlite3VdbeSerialType(const Mem *pMem){ int flags = pMem->flags; if( flags&MEM_Null ){ return 0; } if( flags&MEM_Int ){ /* Figure out whether to use 1, 2, 4 or 8 bytes. */ i64 i = pMem->i; if( i>=-127 && i<=127 ) return 1; if( i>=-32767 && i<=32767 ) return 2; if( i>=-2147483647 && i<=2147483647 ) return 3; return 4; } if( flags&MEM_Real ){ return 5; } if( flags&MEM_Str ){ return (pMem->n*2 + 13); } if( flags&MEM_Blob ){ return (pMem->n*2 + 12); } return 0; } /* ** Return the length of the data corresponding to the supplied serial-type. */ int sqlite3VdbeSerialTypeLen(u64 serial_type){ switch(serial_type){ case 0: return 0; /* NULL */ case 1: return 1; /* 1 byte integer */ case 2: return 2; /* 2 byte integer */ case 3: return 4; /* 4 byte integer */ case 4: return 8; /* 8 byte integer */ case 5: return 8; /* 8 byte float */ } assert( serial_type>=12 ); return ((serial_type-12)>>1); /* text or blob */ } /* ** Write the serialized data blob for the value stored in pMem into ** buf. It is assumed that the caller has allocated sufficient space. ** Return the number of bytes written. */ int sqlite3VdbeSerialPut(unsigned char *buf, const Mem *pMem){ u64 serial_type = sqlite3VdbeSerialType(pMem); int len; /* NULL */ if( serial_type==0 ){ return 0; } /* Integer */ if( serial_type<5 ){ i64 i = pMem->i; len = sqlite3VdbeSerialTypeLen(serial_type); while( len-- ){ buf[len] = (i&0xFF); i = i >> 8; } return sqlite3VdbeSerialTypeLen(serial_type); } /* Float */ if( serial_type==5 ){ /* TODO: byte ordering? */ assert( sizeof(double)==8 ); memcpy(buf, &pMem->r, 8); return 8; } /* String or blob */ assert( serial_type>=12 ); len = sqlite3VdbeSerialTypeLen(serial_type); memcpy(buf, pMem->z, len); return len; } /* ** Deserialize the data blob pointed to by buf as serial type serial_type ** and store the result in pMem. Return the number of bytes read. */ int sqlite3VdbeSerialGet(const unsigned char *buf, u64 serial_type, Mem *pMem){ int len; /* memset(pMem, 0, sizeof(pMem)); */ pMem->flags = 0; pMem->z = 0; /* NULL */ if( serial_type==0 ){ pMem->flags = MEM_Null; return 0; } /* Integer */ if( serial_type<5 ){ i64 i = 0; int n; len = sqlite3VdbeSerialTypeLen(serial_type); if( buf[0]&0x80 ){ for(n=0; n<(8-len); n++){ i = (i<<8)+0xFF; } } for(n=0; n<len; n++){ i = i << 8; i = i + buf[n]; } pMem->flags = MEM_Int; pMem->i = i; return sqlite3VdbeSerialTypeLen(serial_type); } /* Float */ if( serial_type==5 ){ /* TODO: byte ordering? */ assert( sizeof(double)==8 ); memcpy(&pMem->r, buf, 8); pMem->flags = MEM_Real; return 8; } /* String or blob */ assert( serial_type>=12 ); if( serial_type&0x01 ){ pMem->flags = MEM_Str; }else{ pMem->flags = MEM_Blob; } len = sqlite3VdbeSerialTypeLen(serial_type); pMem->n = len; if( len>NBFS ){ pMem->z = sqliteMalloc( len ); if( !pMem->z ){ return -1; } pMem->flags |= MEM_Dyn; }else{ pMem->z = pMem->zShort; pMem->flags |= MEM_Short; } memcpy(pMem->z, buf, len); return len; } /* ** The following is the comparison function for (non-integer) ** keys in the btrees. This function returns negative, zero, or ** positive if the first key is less than, equal to, or greater than ** the second. |
︙ | ︙ |
Changes to test/quick.test.
1 2 3 4 5 6 7 8 9 10 11 12 | # 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. # #*********************************************************************** # This file runs all tests. # | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 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 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 | # 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. # #*********************************************************************** # This file runs all tests. # # $Id: quick.test,v 1.7 2004/05/12 07:33:34 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl rename finish_test really_finish_test proc finish_test {} {} set ISQUICK 1 set EXCLUDE { all.test quick.test btree2.test malloc.test memleak.test misuse.test } lappend EXCLUDE \ auth.test \ bind.test \ capi2.test \ conflict.test \ copy.test \ format3.test \ func.test \ index.test \ interrupt.test \ intpkey.test \ ioerr.test \ memdb.test \ minmax.test \ misc1.test \ misc2.test \ misc3.test \ null.test \ pragma.test \ printf.test \ rowid.test \ table.test \ tableapi.test \ trans.test \ trigger1.test \ trigger2.test \ unique.test \ update.test \ utf.test \ vacuum.test \ version.test \ if {[sqlite -has-codec]} { lappend EXCLUDE \ attach.test \ attach2.test \ auth.test \ format3.test \ |
︙ | ︙ | |||
43 44 45 46 47 48 49 | catch {db close} if {$sqlite_open_file_count>0} { puts "$tail did not close all files: $sqlite_open_file_count" incr nErr lappend ::failList $tail } } | | | 76 77 78 79 80 81 82 83 84 85 86 | catch {db close} if {$sqlite_open_file_count>0} { puts "$tail did not close all files: $sqlite_open_file_count" incr nErr lappend ::failList $tail } } # source $testdir/misuse.test set sqlite_open_file_count 0 really_finish_test |