Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Implement a "counter" SQL function that can be used to insert a sequence number each row of a result set. Currently in the test harness only, but a candidate to move into the core. (CVS 5614) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
c84d46c71233bbf869513f433b1d18cb |
User & Date: | drh 2008-08-26 14:42:15.000 |
Context
2008-08-26
| ||
18:05 | Simplify the pcache module by only recycling clean pages from 'other' caches. This commit causes errors in test files ioerr5.test and malloc5.test because they test recycling dirty pages from other caches. (CVS 5615) (check-in: 9e511e161b user: danielk1977 tags: trunk) | |
14:42 | Implement a "counter" SQL function that can be used to insert a sequence number each row of a result set. Currently in the test harness only, but a candidate to move into the core. (CVS 5614) (check-in: c84d46c712 user: drh tags: trunk) | |
12:56 | Do not flatten subqueries where the subquery has a LIMIT and the outer query has a WHERE clause. Ticket #3334. (CVS 5613) (check-in: 4995a1d1c9 user: drh tags: trunk) | |
Changes
Changes to src/test_func.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. ** ************************************************************************* ** Code for testing all sorts of SQLite interfaces. This code ** implements new SQL functions used by the test scripts. ** | | | 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. ** ************************************************************************* ** Code for testing all sorts of SQLite interfaces. This code ** implements new SQL functions used by the test scripts. ** ** $Id: test_func.c,v 1.11 2008/08/26 14:42:15 drh Exp $ */ #include "sqlite3.h" #include "tcl.h" #include <stdlib.h> #include <string.h> #include <assert.h> |
︙ | ︙ | |||
201 202 203 204 205 206 207 208 209 210 211 212 213 214 | sqlite3_value **argv ){ sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), -1); if( nArg==2 ){ sqlite3_result_error_code(pCtx, sqlite3_value_int(argv[1])); } } /* ** This function takes two arguments. It performance UTF-8/16 type ** conversions on the first argument then returns a copy of the second ** argument. ** ** This function is used in cases such as the following: | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 237 238 239 240 241 242 243 244 | sqlite3_value **argv ){ sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), -1); if( nArg==2 ){ sqlite3_result_error_code(pCtx, sqlite3_value_int(argv[1])); } } /* ** Implementation of the counter(X) function. If X is an integer ** constant, then the first invocation will return X. The second X+1. ** and so forth. Can be used (for example) to provide a sequence number ** in a result set. */ static void counterFunc( sqlite3_context *pCtx, /* Function context */ int nArg, /* Number of function arguments */ sqlite3_value **argv /* Values for all function arguments */ ){ int i; int *pCounter; pCounter = (int*)sqlite3_get_auxdata(pCtx, 0); if( pCounter==0 ){ pCounter = sqlite3_malloc( sizeof(*pCounter) ); if( pCounter==0 ){ sqlite3_result_error_nomem(pCtx); return; } *pCounter = sqlite3_value_int(argv[0]); sqlite3_set_auxdata(pCtx, 0, pCounter, sqlite3_free); }else{ ++*pCounter; } sqlite3_result_int(pCtx, *pCounter); } /* ** This function takes two arguments. It performance UTF-8/16 type ** conversions on the first argument then returns a copy of the second ** argument. ** ** This function is used in cases such as the following: |
︙ | ︙ | |||
279 280 281 282 283 284 285 286 287 288 289 290 291 292 | #endif { "test_destructor_count", 0, SQLITE_UTF8, test_destructor_count}, { "test_auxdata", -1, SQLITE_UTF8, test_auxdata}, { "test_error", 1, SQLITE_UTF8, test_error}, { "test_error", 2, SQLITE_UTF8, test_error}, { "test_eval", 1, SQLITE_UTF8, test_eval}, { "test_isolation", 2, SQLITE_UTF8, test_isolation}, }; int i; extern int Md5_Register(sqlite3*); for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){ sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg, aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0); | > | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | #endif { "test_destructor_count", 0, SQLITE_UTF8, test_destructor_count}, { "test_auxdata", -1, SQLITE_UTF8, test_auxdata}, { "test_error", 1, SQLITE_UTF8, test_error}, { "test_error", 2, SQLITE_UTF8, test_error}, { "test_eval", 1, SQLITE_UTF8, test_eval}, { "test_isolation", 2, SQLITE_UTF8, test_isolation}, { "test_counter", 1, SQLITE_UTF8, counterFunc}, }; int i; extern int Md5_Register(sqlite3*); for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){ sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg, aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0); |
︙ | ︙ |