/ Changes On Branch carray_asc
Login

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

Changes In Branch carray_asc Excluding Merge-Ins

This is equivalent to a diff from 810d29320b to 1d4759c17c

2017-02-15
18:30
Minor enhancement to mutex tracing on Win32. (check-in: 830b923567 user: mistachkin tags: trunk)
17:47
simple test cases for carray_asc. (Leaf check-in: 1d4759c17c user: drh tags: carray_asc)
16:11
Add the companion "carray_asc" table-valued function to the carray extension. (check-in: a2b4f60b33 user: drh tags: carray_asc)
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)
15:09
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: 810d29320b user: drh tags: trunk)
04:16
Further reforms to Tcl_*Alloc() usage. (check-in: ee1e689633 user: mistachkin tags: trunk)

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;
}

Changes to test/tabfunc01.test.

159
160
161
162
163
164
165

























166
167
168
169
170
171
172
  }
} {(005) (007) (013) (017) (023)}
do_test tabfunc01-702 {
  db eval {
    SELECT b FROM t600 WHERE a IN carray($PTR1,4,'int32');
  }
} {(005) (007) (013) (017)}

























do_catchsql_test tabfunc01-710 {
  SELECT b FROM t600 WHERE a IN carray($PTR1,5,'int33');
} {1 {unknown datatype: 'int33'}}

do_test tabfunc01-720 {
  set PTR2 [int64array_addr 5 7 13 17 23]
  db eval {







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







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  }
} {(005) (007) (013) (017) (023)}
do_test tabfunc01-702 {
  db eval {
    SELECT b FROM t600 WHERE a IN carray($PTR1,4,'int32');
  }
} {(005) (007) (013) (017)}
do_test tabfunc01-703 {
  db eval {
    SELECT value FROM carray($PTR1, 5) ORDER BY value;
  }
} {5 7 13 17 23}
do_test tabfunc01-703x {db status sort} 1
do_test tabfunc01-704 {
  db eval {
    SELECT value FROM carray_asc($PTR1, 5) ORDER BY value;
  }
} {5 7 13 17 23}
do_test tabfunc01-704x {db status sort} 0
do_test tabfunc01-705 {
  db eval {
    SELECT value FROM carray($PTR1, 5) ORDER BY value DESC;
  }
} {23 17 13 7 5}
do_test tabfunc01-705x {db status sort} 1
do_test tabfunc01-706 {
  db eval {
    SELECT value FROM carray_asc($PTR1, 5) ORDER BY value DESC;
  }
} {23 17 13 7 5}
do_test tabfunc01-706x {db status sort} 1

do_catchsql_test tabfunc01-710 {
  SELECT b FROM t600 WHERE a IN carray($PTR1,5,'int33');
} {1 {unknown datatype: 'int33'}}

do_test tabfunc01-720 {
  set PTR2 [int64array_addr 5 7 13 17 23]
  db eval {