SQLite

Check-in [396b9d99ae]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bummer. Checked this in as a branch off of the wrong branch.... Was: Add the companion "carray_asc" table-valued function to the carray extension.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | mistake
Files: files | file ages | folders
SHA1: 396b9d99ae43cc5c9ce18509754aac001eae0ecf
User & Date: drh 2017-02-15 16:04:23.036
Original Comment: Add the companion "carray_asc" table-valued function to the carray extension.
Context
2017-02-15
16:11
Add the companion "carray_asc" table-valued function to the carray extension. (check-in: a2b4f60b33 user: drh tags: carray_asc)
16:04
Bummer. Checked this in as a branch off of the wrong branch.... Was: Add the companion "carray_asc" table-valued function to the carray extension. (Closed-Leaf check-in: 396b9d99ae user: drh tags: mistake)
15:11
Remove the CLANG_VERSION macro, since we have learned that version numbers in clang are "marketing" and are inconsistent and unreliable. Builds using clang will still use the GCC_VERSION macro since clang works hard to be gcc compatible. (check-in: 8d3f485d86 user: drh tags: branch-3.17)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/misc/carray.c.
21
22
23
24
25
26
27








28
29
30
31
32
33
34
** has been cast to an integer.
**
** There is an optional third parameter to determine the datatype of
** the C-language array.  Allowed values of the third parameter are
** 'int32', 'int64', 'double', 'char*'.  Example:
**
**      SELECT * FROM carray($ptr,10,'char*');








**
** HOW IT WORKS
**
** The carray "function" is really a virtual table with the
** following schema:
**
**     CREATE TABLE carray(







>
>
>
>
>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
** has been cast to an integer.
**
** There is an optional third parameter to determine the datatype of
** the C-language array.  Allowed values of the third parameter are
** 'int32', 'int64', 'double', 'char*'.  Example:
**
**      SELECT * FROM carray($ptr,10,'char*');
**
** There is a second table-valued funnction named "carrray_asc" that works
** exactly like carray except that it requires the values in the $ptr array
** to be in ascending order.  Queries involving ORDER BY clauses can sometimes
** be a little faster with carray_asc compared to plain carray.  However, if
** the application provides carray_asc($ptr) with a $ptr array in which the
** elements are not in ascending order, then incorrect query results might
** result.
**
** HOW IT WORKS
**
** The carray "function" is really a virtual table with the
** following schema:
**
**     CREATE TABLE carray(
60
61
62
63
64
65
66














67
68
69
70
71
72
73
#define CARRAY_TEXT     3

/*
** Names of types
*/
static const char *azType[] = { "int32", "int64", "double", "char*" };
















/* carray_cursor is a subclass of sqlite3_vtab_cursor which will
** serve as the underlying representation of a cursor that scans
** over rows of the result
*/
typedef struct carray_cursor carray_cursor;
struct carray_cursor {







>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
#define CARRAY_TEXT     3

/*
** Names of types
*/
static const char *azType[] = { "int32", "int64", "double", "char*" };

/* carray_vtab is a subclass of sqlite3_vtab containing carray-specific
** extensions.
*/
typedef struct carray_vtab carray_vtab;
struct carray_vtab {
  sqlite3_vtab base;         /* Base class - must be first */
  unsigned int mFlags;       /* Operational flags */
};

/*
** Possible values for carray_vtab.mFlags
*/
#define CARRAY_ASC    0x0001    /* Values are always in ascending order */


/* carray_cursor is a subclass of sqlite3_vtab_cursor which will
** serve as the underlying representation of a cursor that scans
** over rows of the result
*/
typedef struct carray_cursor carray_cursor;
struct carray_cursor {
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
static int carrayConnect(
  sqlite3 *db,
  void *pAux,
  int argc, const char *const*argv,
  sqlite3_vtab **ppVtab,
  char **pzErr
){
  sqlite3_vtab *pNew;
  int rc;

/* Column numbers */
#define CARRAY_COLUMN_VALUE   0
#define CARRAY_COLUMN_POINTER 1
#define CARRAY_COLUMN_COUNT   2
#define CARRAY_COLUMN_CTYPE   3

  rc = sqlite3_declare_vtab(db,
     "CREATE TABLE x(value,pointer hidden,count hidden,ctype hidden)");
  if( rc==SQLITE_OK ){
    pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );

    if( pNew==0 ) return SQLITE_NOMEM;
    memset(pNew, 0, sizeof(*pNew));

  }
  return rc;
}

/*
** This method is the destructor for carray_cursor objects.
*/







|











|
>


>







116
117
118
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
static int carrayConnect(
  sqlite3 *db,
  void *pAux,
  int argc, const char *const*argv,
  sqlite3_vtab **ppVtab,
  char **pzErr
){
  carray_vtab *pNew;
  int rc;

/* Column numbers */
#define CARRAY_COLUMN_VALUE   0
#define CARRAY_COLUMN_POINTER 1
#define CARRAY_COLUMN_COUNT   2
#define CARRAY_COLUMN_CTYPE   3

  rc = sqlite3_declare_vtab(db,
     "CREATE TABLE x(value,pointer hidden,count hidden,ctype hidden)");
  if( rc==SQLITE_OK ){
    pNew = sqlite3_malloc( sizeof(*pNew) );
    *ppVtab = (sqlite3_vtab*)pNew;
    if( pNew==0 ) return SQLITE_NOMEM;
    memset(pNew, 0, sizeof(*pNew));
    if( pAux ) pNew->mFlags = *(unsigned int*)pAux;
  }
  return rc;
}

/*
** This method is the destructor for carray_cursor objects.
*/
301
302
303
304
305
306
307







308
309
310
311
312
313
314
    pIdxInfo->aConstraintUsage[ptrIdx].argvIndex = 1;
    pIdxInfo->aConstraintUsage[ptrIdx].omit = 1;
    pIdxInfo->aConstraintUsage[cntIdx].argvIndex = 2;
    pIdxInfo->aConstraintUsage[cntIdx].omit = 1;
    pIdxInfo->estimatedCost = (double)1;
    pIdxInfo->estimatedRows = 100;
    pIdxInfo->idxNum = 2;







    if( ctypeIdx>=0 ){
      pIdxInfo->aConstraintUsage[ctypeIdx].argvIndex = 3;
      pIdxInfo->aConstraintUsage[ctypeIdx].omit = 1;
      pIdxInfo->idxNum = 3;
    }
  }else{
    pIdxInfo->estimatedCost = (double)2147483647;







>
>
>
>
>
>
>







325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
    pIdxInfo->aConstraintUsage[ptrIdx].argvIndex = 1;
    pIdxInfo->aConstraintUsage[ptrIdx].omit = 1;
    pIdxInfo->aConstraintUsage[cntIdx].argvIndex = 2;
    pIdxInfo->aConstraintUsage[cntIdx].omit = 1;
    pIdxInfo->estimatedCost = (double)1;
    pIdxInfo->estimatedRows = 100;
    pIdxInfo->idxNum = 2;
    if( pIdxInfo->nOrderBy==1
     && pIdxInfo->aOrderBy[0].iColumn==0
     && pIdxInfo->aOrderBy[0].desc==0
     && (((carray_vtab*)tab)->mFlags & CARRAY_ASC)!=0
    ){
      pIdxInfo->orderByConsumed = 1;
    }
    if( ctypeIdx>=0 ){
      pIdxInfo->aConstraintUsage[ctypeIdx].argvIndex = 3;
      pIdxInfo->aConstraintUsage[ctypeIdx].omit = 1;
      pIdxInfo->idxNum = 3;
    }
  }else{
    pIdxInfo->estimatedCost = (double)2147483647;
352
353
354
355
356
357
358

359
360
361




362
363
364
#endif
int sqlite3_carray_init(
  sqlite3 *db, 
  char **pzErrMsg, 
  const sqlite3_api_routines *pApi
){
  int rc = SQLITE_OK;

  SQLITE_EXTENSION_INIT2(pApi);
#ifndef SQLITE_OMIT_VIRTUALTABLE
  rc = sqlite3_create_module(db, "carray", &carrayModule, 0);




#endif
  return rc;
}







>



>
>
>
>



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#endif
int sqlite3_carray_init(
  sqlite3 *db, 
  char **pzErrMsg, 
  const sqlite3_api_routines *pApi
){
  int rc = SQLITE_OK;
  static const unsigned int mAscFlags = CARRAY_ASC;
  SQLITE_EXTENSION_INIT2(pApi);
#ifndef SQLITE_OMIT_VIRTUALTABLE
  rc = sqlite3_create_module(db, "carray", &carrayModule, 0);
  if( rc==SQLITE_OK ){
    rc = sqlite3_create_module(db, "carray_asc", &carrayModule,
                               (void*)&mAscFlags);
  }
#endif
  return rc;
}