SQLite

Check-in [203af2b2e3]
Login

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

Overview
Comment:Add API functions sqlite3_open_varargs(), sqlite3_open16_varargs() and sqlite3_complete16(). (CVS 1479)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 203af2b2e3a25f4fe0e128e350c21834cad0bd7f
User & Date: danielk1977 2004-05-27 23:56:16.000
Context
2004-05-28
01:39
Remove the encoding argument from sqlite3VdbeSerialGet. Use the 32-bit version of sqlite3GetVarint for schema-level parameters. (CVS 1480) (check-in: 321f8c4635 user: drh tags: trunk)
2004-05-27
23:56
Add API functions sqlite3_open_varargs(), sqlite3_open16_varargs() and sqlite3_complete16(). (CVS 1479) (check-in: 203af2b2e3 user: danielk1977 tags: trunk)
19:59
Change the record format to include an extra varint at the beginning to record the number of bytes in the header. (CVS 1478) (check-in: 0c4d138807 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/main.c.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.194 2004/05/26 16:54:43 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** A pointer to this structure is used to communicate information







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.195 2004/05/27 23:56:16 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>

/*
** A pointer to this structure is used to communicate information
1096
1097
1098
1099
1100
1101
1102


















































































1103
1104
1105
1106
1107
1108
1109
  }else{
    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le);
  }

  sqliteFree(zFilename8);
  return rc;
}



















































































/*
** The following routine destroys a virtual machine that is created by
** the sqlite3_compile() routine. The integer returned is an SQLITE_
** success/failure code that describes the result of executing the virtual
** machine.
**







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







1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
  }else{
    rc = openDatabase(zFilename8, ppDb, options, TEXT_Utf16le);
  }

  sqliteFree(zFilename8);
  return rc;
}

/*
** Open a new database handle.
*/
int sqlite3_open_vararg(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  ...                     /* Option strings */
){
  va_list ap;
  const char **aOpts = 0;
  int nOpts = 0;
  int rc;

  /* Count the arguments */
  va_start(ap, ppDb);
  while( va_arg(ap, const char *) ) nOpts++;
  va_end(ap);

  /* If there are more than zero arguments, construct an array */
  if( nOpts ){
    aOpts = (const char **)sqliteMalloc(sizeof(const char *)*nOpts+1);
    if( !aOpts ){
      *ppDb = 0;
      return SQLITE_NOMEM;
    }
    va_start(ap, ppDb);
    nOpts = 0;
    while( va_arg(ap, const char *) ){
      aOpts[nOpts] = va_arg(ap, const char *);
      nOpts++;
    }
    aOpts[nOpts] = 0;
    va_end(ap);
  }
  
  /* Call the regular sqlite3_open() */
  rc = sqlite3_open(filename, ppDb, aOpts);
  if( aOpts ) sqliteFree(aOpts);
  return rc;
}

/*
** Open a new database handle.
*/
int sqlite3_open16_vararg(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  ...                     /* Option strings */
){
  va_list ap;
  const char **aOpts = 0;
  int nOpts = 0;
  int rc;

  /* Count the arguments */
  va_start(ap, ppDb);
  while( va_arg(ap, const char *) ) nOpts++;
  va_end(ap);

  /* If there are more than zero arguments, construct an array */
  if( nOpts ){
    aOpts = (const char **)sqliteMalloc(sizeof(const char *)*nOpts+1);
    if( !aOpts ){
      *ppDb = 0;
      return SQLITE_NOMEM;
    }
    va_start(ap, ppDb);
    nOpts = 0;
    while( va_arg(ap, const char *) ){
      aOpts[nOpts] = va_arg(ap, const char *);
      nOpts++;
    }
    aOpts[nOpts] = 0;
    va_end(ap);
  }
  
  /* Call the regular sqlite3_open16() */
  rc = sqlite3_open16(filename, ppDb, aOpts);
  if( aOpts ) sqliteFree(aOpts);
  return rc;
}

/*
** The following routine destroys a virtual machine that is created by
** the sqlite3_compile() routine. The integer returned is an SQLITE_
** success/failure code that describes the result of executing the virtual
** machine.
**
Changes to src/select.c.
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.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.179 2004/05/27 10:30:53 danielk1977 Exp $
*/
#include "sqliteInt.h"


/*
** Allocate a new Select structure and return a pointer to that
** structure.







|







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.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.180 2004/05/27 23:56:16 danielk1977 Exp $
*/
#include "sqliteInt.h"


/*
** Allocate a new Select structure and return a pointer to that
** structure.
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
  Vdbe *v = pParse->pVdbe;
  int i, j;
  sqlite *db = pParse->db;
  int fullNames, shortNames;

  /* If this is an EXPLAIN, skip this step */
  if( pParse->explain ){
    return SQLITE_OK;
  }

  assert( v!=0 );
  if( pParse->colNamesSet || v==0 || sqlite3_malloc_failed ) return;
  pParse->colNamesSet = 1;
  fullNames = (db->flags & SQLITE_FullColNames)!=0;
  shortNames = (db->flags & SQLITE_ShortColNames)!=0;
  sqlite3VdbeSetNumCols(v, pEList->nExpr);
  for(i=0; i<pEList->nExpr; i++){
    Expr *p;
    int p2 = i==pEList->nExpr-1;
    p = pEList->a[i].pExpr;
    if( p==0 ) continue;
    if( pEList->a[i].zName ){
      char *zName = pEList->a[i].zName;
      sqlite3VdbeSetColName(v, i, zName, 0);
      continue;
    }







|










<







680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697

698
699
700
701
702
703
704
  Vdbe *v = pParse->pVdbe;
  int i, j;
  sqlite *db = pParse->db;
  int fullNames, shortNames;

  /* If this is an EXPLAIN, skip this step */
  if( pParse->explain ){
    return;
  }

  assert( v!=0 );
  if( pParse->colNamesSet || v==0 || sqlite3_malloc_failed ) return;
  pParse->colNamesSet = 1;
  fullNames = (db->flags & SQLITE_FullColNames)!=0;
  shortNames = (db->flags & SQLITE_ShortColNames)!=0;
  sqlite3VdbeSetNumCols(v, pEList->nExpr);
  for(i=0; i<pEList->nExpr; i++){
    Expr *p;

    p = pEList->a[i].pExpr;
    if( p==0 ) continue;
    if( pEList->a[i].zName ){
      char *zName = pEList->a[i].zName;
      sqlite3VdbeSetColName(v, i, zName, 0);
      continue;
    }
Changes to src/sqlite.h.in.
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.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.84 2004/05/27 09:28:43 danielk1977 Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.







|







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.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.85 2004/05/27 23:56:16 danielk1977 Exp $
*/
#ifndef _SQLITE_H_
#define _SQLITE_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
225
226
227
228
229
230
231
232
233



234
235
236
237
238
239

240
241
242
243
244
245
246
** called in response to a user action such as pressing "Cancel"
** or Ctrl-C where the user wants a long query operation to halt
** immediately.
*/
void sqlite3_interrupt(sqlite*);


/* This function returns true if the given input string comprises
** one or more complete SQL statements.



**
** The algorithm is simple.  If the last token other than spaces
** and comments is a semicolon, then return true.  otherwise return
** false.
*/
int sqlite3_complete(const char *sql);


/*
** This routine identifies a callback function that is invoked
** whenever an attempt is made to open a database table that is
** currently locked by another process or thread.  If the busy callback
** is NULL, then sqlite3_exec() returns SQLITE_BUSY immediately if
** it finds a locked table.  If the busy callback is not NULL, then







|
|
>
>
>






>







225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
** called in response to a user action such as pressing "Cancel"
** or Ctrl-C where the user wants a long query operation to halt
** immediately.
*/
void sqlite3_interrupt(sqlite*);


/* These functions return true if the given input string comprises
** one or more complete SQL statements. For the sqlite3_complete() call,
** the parameter must be a nul-terminated UTF-8 string. For
** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string
** is required.
**
** The algorithm is simple.  If the last token other than spaces
** and comments is a semicolon, then return true.  otherwise return
** false.
*/
int sqlite3_complete(const char *sql);
int sqlite3_complete16(const void *sql);

/*
** This routine identifies a callback function that is invoked
** whenever an attempt is made to open a database table that is
** currently locked by another process or thread.  If the busy callback
** is NULL, then sqlite3_exec() returns SQLITE_BUSY immediately if
** it finds a locked table.  If the busy callback is not NULL, then
518
519
520
521
522
523
524

















525
526
527
528
529
530
531
  const char **args       /* Null terminated array of option strings */
);
int sqlite3_open16(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  const char **args       /* Null terminated array of option strings */
);


















/*
** Return the error code for the most recent sqlite3_* API call associated
** with sqlite3 handle 'db'. SQLITE_OK is returned if the most recent 
** API call was successful.
**
** Calls to many sqlite3_* functions set the error code and string returned







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







522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
  const char **args       /* Null terminated array of option strings */
);
int sqlite3_open16(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  const char **args       /* Null terminated array of option strings */
);

/*
** The following two functions are identical to sqlite3_open() and
** sqlite3_open16(), except that any option strings are specified as the
** third and subsequent arguments, instead of as an array.  The final
** argument to either of the following two functions must be a NULL.
*/
int sqlite3_open_vararg(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  ...                     /* Option strings */
);
int sqlite3_open16_vararg(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  ...                     /* Option strings */
);

/*
** Return the error code for the most recent sqlite3_* API call associated
** with sqlite3 handle 'db'. SQLITE_OK is returned if the most recent 
** API call was successful.
**
** Calls to many sqlite3_* functions set the error code and string returned
Changes to src/tokenize.c.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that splits an SQL input string up into
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.73 2004/05/27 17:22:56 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <stdlib.h>

/*







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
*************************************************************************
** An tokenizer for SQL
**
** This file contains C code that splits an SQL input string up into
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.74 2004/05/27 23:56:16 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include <stdlib.h>

/*
690
691
692
693
694
695
696















      }
    }
    state = trans[state][token];
    zSql++;
  }
  return state==0;
}






















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
      }
    }
    state = trans[state][token];
    zSql++;
  }
  return state==0;
}

/*
** This routine is the same as the sqlite3_complete() routine described
** above, except that the parameter is required to be UTF-16 encoded, not
** UTF-8.
*/
int sqlite3_complete16(const void *zSql){
  int rc;
  char *zSql8 = sqlite3utf16to8(zSql, -1, SQLITE3_BIGENDIAN);
  if( !zSql8 ) return 0;
  rc = sqlite3_complete(zSql8);
  sqliteFree(zSql8);
  return rc;
}

Changes to src/vdbeaux.c.
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
    }
    return len;
  }

  /* String or blob */
  assert( serial_type>=12 );
  len = sqlite3VdbeSerialTypeLen(serial_type);
  pMem->z = buf;
  pMem->n = len;
  if( serial_type&0x01 ){
    pMem->flags = MEM_Str | MEM_Ephem;
    pMem->enc = enc;
  }else{
    pMem->flags = MEM_Blob | MEM_Ephem;
  }







|







1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
    }
    return len;
  }

  /* String or blob */
  assert( serial_type>=12 );
  len = sqlite3VdbeSerialTypeLen(serial_type);
  pMem->z = (char *)buf;
  pMem->n = len;
  if( serial_type&0x01 ){
    pMem->flags = MEM_Str | MEM_Ephem;
    pMem->enc = enc;
  }else{
    pMem->flags = MEM_Blob | MEM_Ephem;
  }