/ Check-in [dddd792d]
Login

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

Overview
Comment:Merge changes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | table-valued-functions
Files: files | file ages | folders
SHA1: dddd792dedf0c73ebe74b4ff8d303e6216c16b6a
User & Date: drh 2015-08-19 12:52:51
Context
2015-08-19
13:54
Virtual table modules with a null xCreate method act as eponymous-only modules - they cannot be used in a CREATE VIRTUAL TABLE statement. Add the series.c extension that implements a postgres-like generate_series virtual table to demonstrate this capability. check-in: c58426db user: drh tags: table-valued-functions
12:52
Merge changes from trunk. check-in: dddd792d user: drh tags: table-valued-functions
12:45
Simplification to error handling in addModuleArgument() in the virtual table processing. check-in: c573b0a1 user: drh tags: trunk
02:32
Initial implementation of eponymous virtual table instances. check-in: c1f43a77 user: drh tags: table-valued-functions
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/rbu/sqlite3rbu.c.

3039
3040
3041
3042
3043
3044
3045

3046
3047
3048
3049
3050
3051
3052
3053










3054
3055
3056
3057
3058
3059
3060
      ** page 1 of the database file. */
      p->rc = SQLITE_BUSY;
      p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
    }

    if( p->rc==SQLITE_OK ){
      if( p->eStage==RBU_STAGE_OAL ){


        /* Open transactions both databases. The *-oal file is opened or
        ** created at this point. */
        p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        if( p->rc==SQLITE_OK ){
          p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        }
  










        /* Point the object iterator at the first object */
        if( p->rc==SQLITE_OK ){
          p->rc = rbuObjIterFirst(p, &p->objiter);
        }

        /* If the RBU database contains no data_xxx tables, declare the RBU
        ** update finished.  */







>



|



|
>
>
>
>
>
>
>
>
>
>







3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
      ** page 1 of the database file. */
      p->rc = SQLITE_BUSY;
      p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
    }

    if( p->rc==SQLITE_OK ){
      if( p->eStage==RBU_STAGE_OAL ){
        sqlite3 *db = p->dbMain;

        /* Open transactions both databases. The *-oal file is opened or
        ** created at this point. */
        p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        if( p->rc==SQLITE_OK ){
          p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        }

        /* Check if the main database is a zipvfs db. If it is, set the upper
        ** level pager to use "journal_mode=off". This prevents it from 
        ** generating a large journal using a temp file.  */
        if( p->rc==SQLITE_OK ){
          int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
          if( frc==SQLITE_OK ){
            p->rc = sqlite3_exec(db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
          }
        }

        /* Point the object iterator at the first object */
        if( p->rc==SQLITE_OK ){
          p->rc = rbuObjIterFirst(p, &p->objiter);
        }

        /* If the RBU database contains no data_xxx tables, declare the RBU
        ** update finished.  */

Changes to src/vtab.c.

272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

303
304
305
306

307
308
309
310
311
312
313
  if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
  if( p->azModuleArg ){
    int i;
    for(i=0; i<p->nModuleArg; i++){
      if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
    }
    sqlite3DbFree(db, p->azModuleArg);
    p->azModuleArg = 0;
  }
}

/*
** Add a new module argument to pTable->azModuleArg[].
** The string is not copied - the pointer is stored.  The
** string will be freed automatically when the table is
** deleted.
*/
static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
  int i = pTable->nModuleArg++;
  int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
  char **azModuleArg;
  azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
  if( azModuleArg==0 ){
    int j;
    for(j=0; j<i; j++){
      sqlite3DbFree(db, pTable->azModuleArg[j]);
    }
    sqlite3DbFree(db, zArg);
    sqlite3DbFree(db, pTable->azModuleArg);
    pTable->nModuleArg = 0;
  }else{

    azModuleArg[i] = zArg;
    azModuleArg[i+1] = 0;
  }
  pTable->azModuleArg = azModuleArg;

}

/*
** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
** statement.  The module name has been parsed, but the optional list
** of parameters that follow the module name are still pending.
*/







<










<
|



<
<
<
<

<
<

>


<
|
>







272
273
274
275
276
277
278

279
280
281
282
283
284
285
286
287
288

289
290
291
292




293


294
295
296
297

298
299
300
301
302
303
304
305
306
  if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
  if( p->azModuleArg ){
    int i;
    for(i=0; i<p->nModuleArg; i++){
      if( i!=1 ) sqlite3DbFree(db, p->azModuleArg[i]);
    }
    sqlite3DbFree(db, p->azModuleArg);

  }
}

/*
** Add a new module argument to pTable->azModuleArg[].
** The string is not copied - the pointer is stored.  The
** string will be freed automatically when the table is
** deleted.
*/
static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){

  int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
  char **azModuleArg;
  azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
  if( azModuleArg==0 ){




    sqlite3DbFree(db, zArg);


  }else{
    int i = pTable->nModuleArg++;
    azModuleArg[i] = zArg;
    azModuleArg[i+1] = 0;

    pTable->azModuleArg = azModuleArg;
  }
}

/*
** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
** statement.  The module name has been parsed, but the optional list
** of parameters that follow the module name are still pending.
*/

Added test/spellfix2.test.





































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 2012 July 12
#
# 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.
#
#***********************************************************************
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix spellfix2

ifcapable !vtab { finish_test ; return }
load_static_extension db spellfix nextchar

do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE demo USING spellfix1;
  INSERT INTO demo(word) VALUES ('amsterdam');
  INSERT INTO demo(word) VALUES ('amsterdammetje');
  INSERT INTO demo(word) VALUES ('amsterdamania');
  INSERT INTO demo(word) VALUES ('amsterdamweg');
  INSERT INTO demo(word) VALUES ('amsterdamsestraat');
  INSERT INTO demo(word) VALUES ('amsterdamlaan');
}

do_execsql_test 1.1 {
  SELECT word, distance, matchlen FROM demo 
  WHERE word MATCH 'amstedam*' AND top=3;
} {
   amsterdam      100 9
   amsterdammetje 100 9
   amsterdamania  100 9
}

do_execsql_test 1.2 {
  SELECT word, distance, matchlen FROM demo WHERE 
  word MATCH 'amstedam*' AND top=3 AND distance <= 100;
} {
   amsterdam      100 9
   amsterdammetje 100 9
   amsterdamania  100 9
}

do_execsql_test 1.3 {
  SELECT word, distance, matchlen FROM demo WHERE 
  word MATCH 'amstedam*' AND distance <= 100;
} {
   amsterdam         100 9
   amsterdammetje    100 9
   amsterdamania     100 9
   amsterdamweg      100 9
   amsterdamsestraat 100 9
   amsterdamlaan     100 9
}

do_test 1.4 {
  foreach l {a b c d e f g h i j k l m n o p q r s t u v w x y z} {
    execsql { INSERT INTO demo(word) VALUES ('amsterdam' || $l) }
  }
} {}

do_execsql_test 1.5 {
  SELECT count(*) FROM demo WHERE word MATCH 'amstedam*' AND distance <= 100;
  SELECT count(*) FROM demo 
  WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20;
} {
  32 20
}

do_execsql_test 1.6 {
  SELECT word, distance, matchlen FROM demo 
  WHERE word MATCH 'amstedam*' AND distance <= 100;
} {
  amsterdam         100 9        amsterdamh        100 9
  amsterdamm        100 9        amsterdamn        100 9
  amsterdama        100 9        amsterdame        100 9
  amsterdami        100 9        amsterdamo        100 9
  amsterdamu        100 9        amsterdamy        100 9
  amsterdammetje    100 9        amsterdamania     100 9
  amsterdamb        100 9        amsterdamf        100 9
  amsterdamp        100 9        amsterdamv        100 9
  amsterdamw        100 9        amsterdamweg      100 9
  amsterdamc        100 9        amsterdamg        100 9
  amsterdamj        100 9        amsterdamk        100 9
  amsterdamq        100 9        amsterdams        100 9
  amsterdamx        100 9        amsterdamz        100 9
  amsterdamsestraat 100 9        amsterdamd        100 9
  amsterdamt        100 9        amsterdaml        100 9
  amsterdamlaan     100 9        amsterdamr        100 9
}

do_execsql_test 1.7 {
  SELECT word, distance, matchlen FROM demo 
  WHERE word MATCH 'amstedam*' AND distance <= 100 AND top=20;
} {
  amsterdam         100 9        amsterdamh        100 9
  amsterdamm        100 9        amsterdamn        100 9
  amsterdama        100 9        amsterdame        100 9
  amsterdami        100 9        amsterdamo        100 9
  amsterdamu        100 9        amsterdamy        100 9
  amsterdammetje    100 9        amsterdamania     100 9
  amsterdamb        100 9        amsterdamf        100 9
  amsterdamp        100 9        amsterdamv        100 9
  amsterdamw        100 9        amsterdamweg      100 9
  amsterdamc        100 9        amsterdamg        100 9
}


finish_test