SQLite

Check-in [aa129c51ec]
Login

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

Overview
Comment:Basic functionality is now working.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | lsm-vtab
Files: files | file ages | folders
SHA1: aa129c51ecf5c917cfac30be330886f8a10f49e1
User & Date: drh 2015-11-17 02:23:09.421
Context
2015-11-19
19:27
Work toward more flexible typing for keys and values. (check-in: 5c79f53131 user: drh tags: lsm-vtab)
2015-11-17
02:23
Basic functionality is now working. (check-in: aa129c51ec user: drh tags: lsm-vtab)
00:15
The virtual table compiles but does not work and is missing many features. This is an incremental check-in. (check-in: a32849d6bf user: drh tags: lsm-vtab)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/lsm1/lsm_vtab.c.
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  memset(pNew, 0, sizeof(*pNew));
  rc = lsm_new(0, &pNew->pDb);
  if( rc ){
    *pzErr = sqlite3_mprintf("lsm_new failed with error code %d",  rc);
    rc = SQLITE_ERROR;
    goto connect_failed;
  }
  rc = lsm_open(pNew->pDb, argv[0]);
  if( rc ){
    *pzErr = sqlite3_mprintf("lsm_open failed with %d", rc);
    rc = SQLITE_ERROR;
    goto connect_failed;
  }

/* Column numbers */







|







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  memset(pNew, 0, sizeof(*pNew));
  rc = lsm_new(0, &pNew->pDb);
  if( rc ){
    *pzErr = sqlite3_mprintf("lsm_new failed with error code %d",  rc);
    rc = SQLITE_ERROR;
    goto connect_failed;
  }
  rc = lsm_open(pNew->pDb, argv[3]);
  if( rc ){
    *pzErr = sqlite3_mprintf("lsm_open failed with %d", rc);
    rc = SQLITE_ERROR;
    goto connect_failed;
  }

/* Column numbers */
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  int i                       /* Which column to return */
){
  lsm1_cursor *pCur = (lsm1_cursor*)cur;
  switch( i ){
    case LSM1_COLUMN_KEY: {
      const void *pVal;
      int nVal;
      if( lsm_csr_value(pCur->pLsmCur, (const void**)&pVal, &nVal)==LSM_OK ){
        sqlite3_result_blob(ctx, pVal, nVal, SQLITE_TRANSIENT);
      }
      break;
    }
    case LSM1_COLUMN_VALUE: {
      const unsigned char *aVal;
      int nVal;







|







183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  int i                       /* Which column to return */
){
  lsm1_cursor *pCur = (lsm1_cursor*)cur;
  switch( i ){
    case LSM1_COLUMN_KEY: {
      const void *pVal;
      int nVal;
      if( lsm_csr_key(pCur->pLsmCur, (const void**)&pVal, &nVal)==LSM_OK ){
        sqlite3_result_blob(ctx, pVal, nVal, SQLITE_TRANSIENT);
      }
      break;
    }
    case LSM1_COLUMN_VALUE: {
      const unsigned char *aVal;
      int nVal;
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270



271
272
273
274
275
276
277
*/
static int lsm1Filter(
  sqlite3_vtab_cursor *pVtabCursor, 
  int idxNum, const char *idxStr,
  int argc, sqlite3_value **argv
){
  lsm1_cursor *pCur = (lsm1_cursor *)pVtabCursor;
  int rc;

  if( idxNum==1 ){
    assert( argc==1 );
    pCur->isDesc = 0;
    pCur->bUnique = 1;
    pCur->atEof = 1;
    if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
      const void *pVal = sqlite3_value_blob(argv[0]);
      int nVal = sqlite3_value_bytes(argv[0]);
      rc = lsm_csr_seek(pCur->pLsmCur, pVal, nVal, LSM_SEEK_EQ);
      if( rc==LSM_OK && lsm_csr_valid(pCur->pLsmCur)!=0 ){
        pCur->atEof = 0;
      }
    }
  }else{
    rc = lsm_csr_first(pCur->pLsmCur);
    pCur->atEof = 0;
    pCur->isDesc = 0;
    pCur->bUnique = 0;



  }
  return rc==LSM_OK ? SQLITE_OK : SQLITE_ERROR;
}

/*
** Only comparisons against the key are allowed.  The idxNum defines
** which comparisons are available:







|
>




<




<
<
<



<


>
>
>







245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260
261



262
263
264

265
266
267
268
269
270
271
272
273
274
275
276
*/
static int lsm1Filter(
  sqlite3_vtab_cursor *pVtabCursor, 
  int idxNum, const char *idxStr,
  int argc, sqlite3_value **argv
){
  lsm1_cursor *pCur = (lsm1_cursor *)pVtabCursor;
  int rc = LSM_OK;
  pCur->atEof = 1;
  if( idxNum==1 ){
    assert( argc==1 );
    pCur->isDesc = 0;
    pCur->bUnique = 1;

    if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
      const void *pVal = sqlite3_value_blob(argv[0]);
      int nVal = sqlite3_value_bytes(argv[0]);
      rc = lsm_csr_seek(pCur->pLsmCur, pVal, nVal, LSM_SEEK_EQ);



    }
  }else{
    rc = lsm_csr_first(pCur->pLsmCur);

    pCur->isDesc = 0;
    pCur->bUnique = 0;
  }
  if( rc==LSM_OK && lsm_csr_valid(pCur->pLsmCur)!=0 ){
    pCur->atEof = 0;
  }
  return rc==LSM_OK ? SQLITE_OK : SQLITE_ERROR;
}

/*
** Only comparisons against the key are allowed.  The idxNum defines
** which comparisons are available:
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
      unsigned char aVal[9];
      int i;
      if( eType==SQLITE_INTEGER ){
        *(sqlite3_int64*)&x = sqlite3_value_int64(pValue);
      }else{
        *(double*)&x = sqlite3_value_double(pValue);
      }
      for(i=9; i>=1; i--){
        aVal[i] = x & 0xff;
        x >>= 8;
      }
      aVal[0] = eType;
      rc = lsm_insert(p->pDb, pKey, nKey, aVal, 9);
      break;
    }







|







393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
      unsigned char aVal[9];
      int i;
      if( eType==SQLITE_INTEGER ){
        *(sqlite3_int64*)&x = sqlite3_value_int64(pValue);
      }else{
        *(double*)&x = sqlite3_value_double(pValue);
      }
      for(i=8; i>=1; i--){
        aVal[i] = x & 0xff;
        x >>= 8;
      }
      aVal[0] = eType;
      rc = lsm_insert(p->pDb, pKey, nKey, aVal, 9);
      break;
    }