SQLite4
Check-in [c7c533dddc]
Not logged in

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

Overview
Comment:Remove legacy API functions: complete16(), errmsg16(), column_name16(), column_database_name16(), column_table_name16(), column_origin_name16(), column_decltype16(), create_function16() and collation_needed16().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c7c533dddcf39d9a47276892573032cb5ff7c257
User & Date: dan 2013-06-11 16:48:56
Context
2013-06-11
17:27
Add a note to www/porting.wiki describing the changes to utf-16 support. check-in: 5cd50e225c user: dan tags: trunk
16:48
Remove legacy API functions: complete16(), errmsg16(), column_name16(), column_database_name16(), column_table_name16(), column_origin_name16(), column_decltype16(), create_function16() and collation_needed16(). check-in: c7c533dddc user: dan tags: trunk
15:18
Add tests and minor fixes for the sqlite4_translate() API. check-in: 211c1baef7 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/main.c.

709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
...
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
....
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
    FuncDef *p = sqlite4FindFunction(db, zFunc, -1, n, enc, 0);
    p->bMatchinfo = 1;
  }
  rc = sqlite4ApiExit(db, rc);
  sqlite4_mutex_leave(db->mutex);
  return rc;
}

#ifndef SQLITE4_OMIT_UTF16
int sqlite4_create_function16(
  sqlite4 *db,
  const void *zFunctionName,
  int nArg,
  int enc,
  void *p,
  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
  void (*xFinal)(sqlite4_context*),
  void (*xDestroy)(void *)
){
  int rc;
  char *zFunc8;
  sqlite4_mutex_enter(db->mutex);
  assert( !db->mallocFailed );
  zFunc8 = sqlite4Utf16to8(db, zFunctionName, -1, SQLITE4_UTF16NATIVE);
  rc = createFunctionDestructor(
      db, zFunc8, nArg, enc, p, xFunc, xStep, xFinal, xDestroy
  );
  sqlite4DbFree(db, zFunc8);
  rc = sqlite4ApiExit(db, rc);
  sqlite4_mutex_leave(db->mutex);
  return rc;
}
#endif


/*
** Declare that a function has been overloaded by a virtual table.
**
** If the function already exists as a regular global function, then
** this routine is a no-op.  If the function does not exist, then create
** a new one that always throws a run-time error.  
................................................................................
      z = sqlite4ErrStr(db->errCode);
    }
  }
  sqlite4_mutex_leave(db->mutex);
  return z;
}

#ifndef SQLITE4_OMIT_UTF16
/*
** Return UTF-16 encoded English language explanation of the most recent
** error.
*/
const void *sqlite4_errmsg16(sqlite4 *db){
  static const u16 outOfMem[] = {
    'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
  };
  static const u16 misuse[] = {
    'l', 'i', 'b', 'r', 'a', 'r', 'y', ' ', 
    'r', 'o', 'u', 't', 'i', 'n', 'e', ' ', 
    'c', 'a', 'l', 'l', 'e', 'd', ' ', 
    'o', 'u', 't', ' ', 
    'o', 'f', ' ', 
    's', 'e', 'q', 'u', 'e', 'n', 'c', 'e', 0
  };

  const void *z;
  if( !db ){
    return (void *)outOfMem;
  }
  if( !sqlite4SafetyCheckSickOrOk(db) ){
    return (void *)misuse;
  }
  sqlite4_mutex_enter(db->mutex);
  if( db->mallocFailed ){
    z = (void *)outOfMem;
  }else{
    z = sqlite4_value_text16(db->pErr, 0);
    if( z==0 ){
      sqlite4ValueSetStr(db->pErr, -1, sqlite4ErrStr(db->errCode),
           SQLITE4_UTF8, SQLITE4_STATIC, 0);
      z = sqlite4_value_text16(db->pErr, 0);
    }
    /* A malloc() may have failed within the call to sqlite4_value_text16()
    ** above. If this is the case, then the db->mallocFailed flag needs to
    ** be cleared before returning. Do this directly, instead of via
    ** sqlite4ApiExit(), to avoid setting the database handle error message.
    */
    db->mallocFailed = 0;
  }
  sqlite4_mutex_leave(db->mutex);
  return z;
}
#endif /* SQLITE4_OMIT_UTF16 */

/*
** Return the most recent error code generated by an SQLite routine. If NULL is
** passed to this function, we assume a malloc() failed during sqlite4_open().
*/
int sqlite4_errcode(sqlite4 *db){
  if( db && !sqlite4SafetyCheckSickOrOk(db) ){
    return SQLITE4_MISUSE_BKPT;
................................................................................
  db->xCollNeeded = xCollNeeded;
  db->xCollNeeded16 = 0;
  db->pCollNeededArg = pCollNeededArg;
  sqlite4_mutex_leave(db->mutex);
  return SQLITE4_OK;
}

#ifndef SQLITE4_OMIT_UTF16
/*
** Register a collation sequence factory callback with the database handle
** db. Replace any previously installed collation sequence factory.
*/
int sqlite4_collation_needed16(
  sqlite4 *db, 
  void(*xCollNeeded16)(void*,sqlite4*,int eTextRep,const void*),
  void *pCollNeededArg
){
  sqlite4_mutex_enter(db->mutex);
  db->xCollNeeded = 0;
  db->xCollNeeded16 = xCollNeeded16;
  db->pCollNeededArg = pCollNeededArg;
  sqlite4_mutex_leave(db->mutex);
  return SQLITE4_OK;
}
#endif /* SQLITE4_OMIT_UTF16 */

/*
** Test to see whether or not the database connection is currently within
** an explicitly started transaction (BEGIN/COMMIT block). Return non-zero 
** if it is and FALSE otherwise. Explicit transactions are opened by a 
** BEGIN statement and concluded by the next COMMIT or ROLLBACK.
*/
int sqlite4_db_transaction_status(sqlite4 *db){







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







709
710
711
712
713
714
715




























716
717
718
719
720
721
722
...
840
841
842
843
844
845
846















































847
848
849
850
851
852
853
....
1472
1473
1474
1475
1476
1477
1478



















1479
1480
1481
1482
1483
1484
1485
    FuncDef *p = sqlite4FindFunction(db, zFunc, -1, n, enc, 0);
    p->bMatchinfo = 1;
  }
  rc = sqlite4ApiExit(db, rc);
  sqlite4_mutex_leave(db->mutex);
  return rc;
}





























/*
** Declare that a function has been overloaded by a virtual table.
**
** If the function already exists as a regular global function, then
** this routine is a no-op.  If the function does not exist, then create
** a new one that always throws a run-time error.  
................................................................................
      z = sqlite4ErrStr(db->errCode);
    }
  }
  sqlite4_mutex_leave(db->mutex);
  return z;
}
















































/*
** Return the most recent error code generated by an SQLite routine. If NULL is
** passed to this function, we assume a malloc() failed during sqlite4_open().
*/
int sqlite4_errcode(sqlite4 *db){
  if( db && !sqlite4SafetyCheckSickOrOk(db) ){
    return SQLITE4_MISUSE_BKPT;
................................................................................
  db->xCollNeeded = xCollNeeded;
  db->xCollNeeded16 = 0;
  db->pCollNeededArg = pCollNeededArg;
  sqlite4_mutex_leave(db->mutex);
  return SQLITE4_OK;
}




















/*
** Test to see whether or not the database connection is currently within
** an explicitly started transaction (BEGIN/COMMIT block). Return non-zero 
** if it is and FALSE otherwise. Explicit transactions are opened by a 
** BEGIN statement and concluded by the next COMMIT or ROLLBACK.
*/
int sqlite4_db_transaction_status(sqlite4 *db){

Changes to src/sqlite.h.in.

966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
....
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
....
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931







1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945

1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
....
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
....
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
....
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
....
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
....
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
....
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
** is running then bad things will likely happen.
*/
void sqlite4_interrupt(sqlite4*);

/*
** CAPIREF: Determine If An SQL Statement Is Complete
**
** These routines are useful during command-line input to determine if the
** currently entered text seems to form a complete SQL statement or
** if additional input is needed before sending the text into
** SQLite for parsing.  ^These routines return 1 if the input string
** appears to be a complete SQL statement.  ^A statement is judged to be
** complete if it ends with a semicolon token and is not a prefix of a
** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
** string literals or quoted identifier names or comments are not
** independent tokens (they are part of the token in which they are
** embedded) and thus do not count as a statement terminator.  ^Whitespace
** and comments that follow the final semicolon are ignored.
**
** ^These routines return 0 if the statement is incomplete.  ^If a
** memory allocation fails, then SQLITE4_NOMEM is returned.
**
** ^These routines do not parse the SQL statements thus
** will not detect syntactically incorrect SQL.
**
** ^(If SQLite has not been initialized using [sqlite4_initialize()] prior 
** to invoking sqlite4_complete16() then sqlite4_initialize() is invoked
** automatically by sqlite4_complete16().  If that initialization fails,
** then the return value from sqlite4_complete16() will be non-zero
** regardless of whether or not the input SQL is complete.)^
**
** The input to [sqlite4_complete()] must be a zero-terminated
** UTF-8 string.
**
** The input to [sqlite4_complete16()] must be a zero-terminated
** UTF-16 string in native byte order.
*/
int sqlite4_complete(const char *sql);
int sqlite4_complete16(const void *sql);


/*
** CAPIREF: Formatted String Printing Functions
**
** These routines are work-alikes of the "printf()" family of functions
** from the standard C library.
................................................................................
**
** ^The sqlite4_errcode() interface returns the numeric 
** [extended result code] for the most recent failed sqlite4_* API call
** associated with a [database connection]. If a prior API call failed
** but the most recent API call succeeded, the return value from
** sqlite4_errcode() is undefined.
**
** ^The sqlite4_errmsg() and sqlite4_errmsg16() return English-language
** text that describes the error, as either UTF-8 or UTF-16 respectively.
** ^(Memory to hold the error message string is managed internally.
** The application does not need to worry about freeing the result.
** However, the error string might be overwritten or deallocated by
** subsequent calls to other SQLite interface functions.)^
**
** When the serialized [threading mode] is in use, it might be the
** case that a second error occurs on a separate thread in between
** the time of the first error and the call to these interfaces.
** When that happens, the second error will be reported since these
** interfaces always report the most recent result.  To avoid
** this, each thread can obtain exclusive use of the [database connection] D
** by invoking [sqlite4_mutex_enter]([sqlite4_db_mutex](D)) before beginning
** to use D and invoking [sqlite4_mutex_leave]([sqlite4_db_mutex](D)) after
** all calls to the interfaces listed here are completed.
**
** If an interface fails with SQLITE4_MISUSE, that means the interface
** was invoked incorrectly by the application.  In that case, the
** error code and message may or may not be set.
*/
int sqlite4_errcode(sqlite4 *db);
const char *sqlite4_errmsg(sqlite4*);
const void *sqlite4_errmsg16(sqlite4*);

/*
** CAPIREF: SQL Statement Object
** KEYWORDS: {prepared statement} {prepared statements}
**
** An instance of this object represents a single SQL statement.
** This object is variously known as a "prepared statement" or a
................................................................................
** See also: [sqlite4_data_count()]
*/
int sqlite4_column_count(sqlite4_stmt *pStmt);

/*
** CAPIREF: Column Names In A Result Set
**
** ^These routines return the name assigned to a particular column
** in the result set of a [SELECT] statement.  ^The sqlite4_column_name()
** interface returns a pointer to a zero-terminated UTF-8 string
** and sqlite4_column_name16() returns a pointer to a zero-terminated
** UTF-16 string.  ^The first parameter is the [prepared statement]
** that implements the [SELECT] statement. ^The second parameter is the
** column number.  ^The leftmost column is number 0.
**
** ^The returned string pointer is valid until either the [prepared statement]
** is destroyed by [sqlite4_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite4_step()] for a particular run
** or until the next call to
** sqlite4_column_name() or sqlite4_column_name16() on the same column.
**
** ^If sqlite4_malloc() fails during the processing of either routine
** (for example during a conversion from UTF-8 to UTF-16) then a
** NULL pointer is returned.
**
** ^The name of a result column is the value of the "AS" clause for
** that column, if there is an AS clause.  If there is no AS clause
** then the name of the column is unspecified and may change from
** one release of SQLite to the next.







*/
const char *sqlite4_column_name(sqlite4_stmt*, int N);
const void *sqlite4_column_name16(sqlite4_stmt*, int N);

/*
** CAPIREF: Source Of Data In A Query Result
**
** ^These routines provide a means to determine the database, table, and
** table column that is the origin of a particular result column in
** [SELECT] statement.
** ^The name of the database or table or column can be returned as
** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
** the database name, the _table_ routines return the table name, and
** the origin_ routines return the column name.

** ^The returned string is valid until the [prepared statement] is destroyed
** using [sqlite4_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite4_step()] for a particular run
** or until the same information is requested
** again in a different encoding.
**
** ^The names returned are the original un-aliased names of the
** database, table, and column.
**
** ^The first argument to these interfaces is a [prepared statement].
** ^These functions return information about the Nth result column returned by
** the statement, where N is the second function argument.
................................................................................
**
** ^If the Nth column returned by the statement is an expression or
** subquery and is not a column value, then all of these functions return
** NULL.  ^These routine might also return NULL if a memory allocation error
** occurs.  ^Otherwise, they return the name of the attached database, table,
** or column that query result column was extracted from.
**
** ^As with all other SQLite APIs, those whose names end with "16" return
** UTF-16 encoded strings and the other functions return UTF-8.
**
** ^These APIs are only available if the library was compiled with the
** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
**
** If two or more threads call one or more of these routines against the same
** prepared statement and column at the same time then the results are
** undefined.
**
** If two or more threads call one or more
** [sqlite4_column_database_name | column metadata interfaces]
** for the same [prepared statement] and result column
** at the same time then the results are undefined.
*/
const char *sqlite4_column_database_name(sqlite4_stmt*,int);
const void *sqlite4_column_database_name16(sqlite4_stmt*,int);
const char *sqlite4_column_table_name(sqlite4_stmt*,int);
const void *sqlite4_column_table_name16(sqlite4_stmt*,int);
const char *sqlite4_column_origin_name(sqlite4_stmt*,int);
const void *sqlite4_column_origin_name16(sqlite4_stmt*,int);

/*
** CAPIREF: Declared Datatype Of A Query Result
**
** ^(The first parameter is a [prepared statement].
** If this statement is a [SELECT] statement and the Nth column of the
** returned result set of that [SELECT] is a table column (not an
................................................................................
** is declared to contain a particular type does not mean that the
** data stored in that column is of the declared type.  SQLite is
** strongly typed, but the typing is dynamic not static.  ^Type
** is associated with individual values, not with the containers
** used to hold those values.
*/
const char *sqlite4_column_decltype(sqlite4_stmt*,int);
const void *sqlite4_column_decltype16(sqlite4_stmt*,int);

/*
** CAPIREF: Evaluate An SQL Statement
**
** After a [prepared statement] has been prepared using [sqlite4_prepare()],
** this function must be called one or more times to evaluate the statement.
**
................................................................................
** ^The [sqlite4_reset(S)] interface does not change the values
** of any [sqlite4_bind_blob|bindings] on the [prepared statement] S.
*/
int sqlite4_reset(sqlite4_stmt *pStmt);

/*
** CAPIREF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routines}
** KEYWORDS: {application-defined SQL function}
** KEYWORDS: {application-defined SQL functions}
**
** ^These functions (collectively known as "function creation routines")
** are used to add new SQL scalar or aggregate functions. The only 
** difference between the two routines is the text encoding expected for 
** the second parameter (the name of the function being created).
**
** ^The first parameter is the [database connection] to which the SQL
** function is to be added.  ^If an application uses more than one database
** connection then application-defined SQL functions must be added
** to each database connection separately.
**
** ^The second parameter is the name of the SQL function to be created or
** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
** representation, exclusive of the zero-terminator.  ^Note that the name
** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.  
** ^Any attempt to create a function with a longer name
** will result in [SQLITE4_MISUSE] being returned.
**
** ^The third parameter (nArg) is the number of arguments that the SQL 
** function or aggregate takes. ^If this parameter is -1, then the SQL 
** function or aggregate may take any number of arguments between 0 and 
** the limit set by [sqlite4_limit]([SQLITE4_LIMIT_FUNCTION_ARG]).  If 
** the third parameter is less than -1 or greater than 127 then the 
** behavior is undefined.
................................................................................
** close the database connection nor finalize or reset the prepared
** statement in which the function is running.
*/
int sqlite4_create_function(
  sqlite4 *db,
  const char *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
  void (*xFinal)(sqlite4_context*),
  void(*xDestroy)(void*)
);
int sqlite4_create_function16(
  sqlite4 *db,
  const void *zFunctionName,
  int nArg,
  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
  void (*xFinal)(sqlite4_context*),
  void(*xDestroy)(void*)
);
................................................................................
** CAPIREF: Collation Needed Callbacks
**
** ^To avoid having to register all collation sequences before a database
** can be used, a single callback function may be registered with the
** [database connection] to be invoked whenever an undefined collation
** sequence is required.
**
** ^If the function is registered using the sqlite4_collation_needed() API,
** then it is passed the names of undefined collation sequences as strings
** encoded in UTF-8. ^If sqlite4_collation_needed16() is used,
** the names are passed as UTF-16 in machine native byte order.
** ^A call to either function replaces the existing collation-needed callback.
**
** ^(When the callback is invoked, the first argument passed is a copy
** of the second argument to sqlite4_collation_needed() or
** sqlite4_collation_needed16().  The second argument is the database
** connection.  The third argument is one of [SQLITE4_UTF8], [SQLITE4_UTF16BE],
** or [SQLITE4_UTF16LE], indicating the most desirable form of the collation
** sequence function required.  The fourth parameter is the name of the
** required collation sequence.)^
................................................................................
** [sqlite4_create_collation()].
*/
int sqlite4_collation_needed(
  sqlite4*, 
  void(*)(void*,sqlite4*,int eTextRep,const char*),
  void* 
);
int sqlite4_collation_needed16(
  sqlite4*, 
  void(*)(void*,sqlite4*,int eTextRep,const void*),
  void*
);

/*
** CAPIREF: Suspend Execution For A Short Time
**
** The sqlite4_sleep() function causes the current thread to suspend execution
** for at least a number of milliseconds specified in its parameter.
**







|
|
|
|
|
|
|
|
|
|
|

<
<
<
|
|

<
<
<
<
<
<
|
|
<
<
<


<







 







|
|
|
|
|
|











|
|




<







 







|
|
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<





>
>
>
>
>
>
>


<






|
<
<
|
<
>


|
<
<







 







<
<
<













<

<

<







 







<







 







|



<
|
<
<









<
|
|







 







<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<







 







<
<
<
<
<







966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984



985
986
987






988
989



990
991

992
993
994
995
996
997
998
....
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
....
1889
1890
1891
1892
1893
1894
1895
1896
1897



1898
1899










1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913

1914
1915
1916
1917
1918
1919
1920


1921

1922
1923
1924
1925


1926
1927
1928
1929
1930
1931
1932
....
1934
1935
1936
1937
1938
1939
1940



1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953

1954

1955

1956
1957
1958
1959
1960
1961
1962
....
1980
1981
1982
1983
1984
1985
1986

1987
1988
1989
1990
1991
1992
1993
....
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269

2270


2271
2272
2273
2274
2275
2276
2277
2278
2279

2280
2281
2282
2283
2284
2285
2286
2287
2288
....
2340
2341
2342
2343
2344
2345
2346











2347
2348
2349
2350
2351
2352
2353
....
2774
2775
2776
2777
2778
2779
2780






2781
2782
2783
2784
2785
2786
2787
....
2790
2791
2792
2793
2794
2795
2796





2797
2798
2799
2800
2801
2802
2803
** is running then bad things will likely happen.
*/
void sqlite4_interrupt(sqlite4*);

/*
** CAPIREF: Determine If An SQL Statement Is Complete
**
** This routine is useful when processing command-line input to determine 
** if the currently entered text appears to form a complete SQL statement 
** or if additional input is needed before sending the text into
** SQLite for parsing.  ^This routine returns 1 if the input string
** appears to be a complete SQL statement, or 0 otherwise. ^A statement 
** is judged to be complete if it ends with a semicolon token and is not 
** a prefix of a well-formed CREATE TRIGGER statement. ^Semicolons that 
** are embedded within string literals or quoted identifier names or 
** comments are not independent tokens (they are part of the token in which 
** they are embedded) and thus do not count as a statement terminator. 
** ^Whitespace and comments that follow the final semicolon are ignored.
**



** ^This routine does not parse the SQL statements thus will not detect 
** syntactically incorrect SQL.
**






** The argument passed to [sqlite4_complete()] must be a pointer to a 
** zero-terminated UTF-8 string.



*/
int sqlite4_complete(const char *sql);



/*
** CAPIREF: Formatted String Printing Functions
**
** These routines are work-alikes of the "printf()" family of functions
** from the standard C library.
................................................................................
**
** ^The sqlite4_errcode() interface returns the numeric 
** [extended result code] for the most recent failed sqlite4_* API call
** associated with a [database connection]. If a prior API call failed
** but the most recent API call succeeded, the return value from
** sqlite4_errcode() is undefined.
**
** ^The sqlite4_errmsg() routine returns English-language text that 
** describes the error, as a UTF-8 encoded string. ^(Memory to hold the 
** error message string is managed internally. The application does not 
** need to worry about freeing the result. However, the error string 
** might be overwritten or deallocated by subsequent calls to other 
** SQLite interface functions.)^
**
** When the serialized [threading mode] is in use, it might be the
** case that a second error occurs on a separate thread in between
** the time of the first error and the call to these interfaces.
** When that happens, the second error will be reported since these
** interfaces always report the most recent result.  To avoid
** this, each thread can obtain exclusive use of the [database connection] D
** by invoking [sqlite4_mutex_enter]([sqlite4_db_mutex](D)) before beginning
** to use D and invoking [sqlite4_mutex_leave]([sqlite4_db_mutex](D)) after
** all calls to the interfaces listed here are completed.
**
** If an SQLite API call fails with SQLITE4_MISUSE, that means the 
** interface was invoked incorrectly by the application. In that case, the
** error code and message may or may not be set.
*/
int sqlite4_errcode(sqlite4 *db);
const char *sqlite4_errmsg(sqlite4*);


/*
** CAPIREF: SQL Statement Object
** KEYWORDS: {prepared statement} {prepared statements}
**
** An instance of this object represents a single SQL statement.
** This object is variously known as a "prepared statement" or a
................................................................................
** See also: [sqlite4_data_count()]
*/
int sqlite4_column_count(sqlite4_stmt *pStmt);

/*
** CAPIREF: Column Names In A Result Set
**
** ^This routine returns the name assigned to a particular column
** in the result set of a [SELECT] statement. ^The first parameter is the



** [prepared statement] that implements the [SELECT] statement. ^The second
** parameter is the column number. ^The leftmost column is number 0.










**
** ^The name of a result column is the value of the "AS" clause for
** that column, if there is an AS clause.  If there is no AS clause
** then the name of the column is unspecified and may change from
** one release of SQLite to the next.
**
** ^The returned string pointer is valid until either the [prepared statement]
** is destroyed by [sqlite4_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite4_step()] for a particular run.
**
** ^If a memory allocation fails during the processing of this routine
** then a NULL pointer is returned.
*/
const char *sqlite4_column_name(sqlite4_stmt*, int N);


/*
** CAPIREF: Source Of Data In A Query Result
**
** ^These routines provide a means to determine the database, table, and
** table column that is the origin of a particular result column in
** [SELECT] statement. Specifically, the sqlite4_column_database_name()


** routine returns the database name, the _table_name() routine returns

** the table name and _origin_name() returns the column name.
** ^The returned string is valid until the [prepared statement] is destroyed
** using [sqlite4_finalize()] or until the statement is automatically
** reprepared by the first call to [sqlite4_step()] for a particular run.


**
** ^The names returned are the original un-aliased names of the
** database, table, and column.
**
** ^The first argument to these interfaces is a [prepared statement].
** ^These functions return information about the Nth result column returned by
** the statement, where N is the second function argument.
................................................................................
**
** ^If the Nth column returned by the statement is an expression or
** subquery and is not a column value, then all of these functions return
** NULL.  ^These routine might also return NULL if a memory allocation error
** occurs.  ^Otherwise, they return the name of the attached database, table,
** or column that query result column was extracted from.
**



** ^These APIs are only available if the library was compiled with the
** [SQLITE4_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
**
** If two or more threads call one or more of these routines against the same
** prepared statement and column at the same time then the results are
** undefined.
**
** If two or more threads call one or more
** [sqlite4_column_database_name | column metadata interfaces]
** for the same [prepared statement] and result column
** at the same time then the results are undefined.
*/
const char *sqlite4_column_database_name(sqlite4_stmt*,int);

const char *sqlite4_column_table_name(sqlite4_stmt*,int);

const char *sqlite4_column_origin_name(sqlite4_stmt*,int);


/*
** CAPIREF: Declared Datatype Of A Query Result
**
** ^(The first parameter is a [prepared statement].
** If this statement is a [SELECT] statement and the Nth column of the
** returned result set of that [SELECT] is a table column (not an
................................................................................
** is declared to contain a particular type does not mean that the
** data stored in that column is of the declared type.  SQLite is
** strongly typed, but the typing is dynamic not static.  ^Type
** is associated with individual values, not with the containers
** used to hold those values.
*/
const char *sqlite4_column_decltype(sqlite4_stmt*,int);


/*
** CAPIREF: Evaluate An SQL Statement
**
** After a [prepared statement] has been prepared using [sqlite4_prepare()],
** this function must be called one or more times to evaluate the statement.
**
................................................................................
** ^The [sqlite4_reset(S)] interface does not change the values
** of any [sqlite4_bind_blob|bindings] on the [prepared statement] S.
*/
int sqlite4_reset(sqlite4_stmt *pStmt);

/*
** CAPIREF: Create Or Redefine SQL Functions
** KEYWORDS: {function creation routine}
** KEYWORDS: {application-defined SQL function}
** KEYWORDS: {application-defined SQL functions}
**

** ^This function is used to add new SQL scalar or aggregate functions. 


**
** ^The first parameter is the [database connection] to which the SQL
** function is to be added.  ^If an application uses more than one database
** connection then application-defined SQL functions must be added
** to each database connection separately.
**
** ^The second parameter is the name of the SQL function to be created or
** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
** representation, exclusive of the zero-terminator.  ^Note that the name

** length limit is in bytes, not characters. ^Any attempt to create a 
** function with a longer name will result in [SQLITE4_MISUSE] being returned.
**
** ^The third parameter (nArg) is the number of arguments that the SQL 
** function or aggregate takes. ^If this parameter is -1, then the SQL 
** function or aggregate may take any number of arguments between 0 and 
** the limit set by [sqlite4_limit]([SQLITE4_LIMIT_FUNCTION_ARG]).  If 
** the third parameter is less than -1 or greater than 127 then the 
** behavior is undefined.
................................................................................
** close the database connection nor finalize or reset the prepared
** statement in which the function is running.
*/
int sqlite4_create_function(
  sqlite4 *db,
  const char *zFunctionName,
  int nArg,











  int eTextRep,
  void *pApp,
  void (*xFunc)(sqlite4_context*,int,sqlite4_value**),
  void (*xStep)(sqlite4_context*,int,sqlite4_value**),
  void (*xFinal)(sqlite4_context*),
  void(*xDestroy)(void*)
);
................................................................................
** CAPIREF: Collation Needed Callbacks
**
** ^To avoid having to register all collation sequences before a database
** can be used, a single callback function may be registered with the
** [database connection] to be invoked whenever an undefined collation
** sequence is required.
**






** ^(When the callback is invoked, the first argument passed is a copy
** of the second argument to sqlite4_collation_needed() or
** sqlite4_collation_needed16().  The second argument is the database
** connection.  The third argument is one of [SQLITE4_UTF8], [SQLITE4_UTF16BE],
** or [SQLITE4_UTF16LE], indicating the most desirable form of the collation
** sequence function required.  The fourth parameter is the name of the
** required collation sequence.)^
................................................................................
** [sqlite4_create_collation()].
*/
int sqlite4_collation_needed(
  sqlite4*, 
  void(*)(void*,sqlite4*,int eTextRep,const char*),
  void* 
);






/*
** CAPIREF: Suspend Execution For A Short Time
**
** The sqlite4_sleep() function causes the current thread to suspend execution
** for at least a number of milliseconds specified in its parameter.
**

Changes to src/vdbeapi.c.

846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
...
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
*/
const char *sqlite4_column_name(sqlite4_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_NAME);
}
#ifndef SQLITE4_OMIT_UTF16
const void *sqlite4_column_name16(sqlite4_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*, int*))sqlite4_value_text16, COLNAME_NAME);
}
#endif

/*
** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
** not define OMIT_DECLTYPE.
*/
#if defined(SQLITE4_OMIT_DECLTYPE) && defined(SQLITE4_ENABLE_COLUMN_METADATA)
# error "Must not define both SQLITE4_OMIT_DECLTYPE \
................................................................................
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt.
*/
const char *sqlite4_column_decltype(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_DECLTYPE);
}
#ifndef SQLITE4_OMIT_UTF16
const void *sqlite4_column_decltype16(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text16, COLNAME_DECLTYPE);
}
#endif /* SQLITE4_OMIT_UTF16 */
#endif /* SQLITE4_OMIT_DECLTYPE */

#ifdef SQLITE4_ENABLE_COLUMN_METADATA
/*
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite4_column_database_name(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_DATABASE);
}
#ifndef SQLITE4_OMIT_UTF16
const void *sqlite4_column_database_name16(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text16, COLNAME_DATABASE);
}
#endif /* SQLITE4_OMIT_UTF16 */

/*
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite4_column_table_name(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_TABLE);
}
#ifndef SQLITE4_OMIT_UTF16
const void *sqlite4_column_table_name16(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text16, COLNAME_TABLE);
}
#endif /* SQLITE4_OMIT_UTF16 */

/*
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite4_column_origin_name(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_COLUMN);
}
#ifndef SQLITE4_OMIT_UTF16
const void *sqlite4_column_origin_name16(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text16, COLNAME_COLUMN);
}
#endif /* SQLITE4_OMIT_UTF16 */
#endif /* SQLITE4_ENABLE_COLUMN_METADATA */


/******************************* sqlite4_bind_  ***************************
** 
** Routines used to attach values to wildcards in a compiled SQL statement.
*/







<
<
<
<
<
<







 







<
<
<
<
<
<












<
<
<
<
<
<










<
<
<
<
<
<










<
<
<
<
<
<







846
847
848
849
850
851
852






853
854
855
856
857
858
859
...
865
866
867
868
869
870
871






872
873
874
875
876
877
878
879
880
881
882
883






884
885
886
887
888
889
890
891
892
893






894
895
896
897
898
899
900
901
902
903






904
905
906
907
908
909
910
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
*/
const char *sqlite4_column_name(sqlite4_stmt *pStmt, int N){
  return columnName(
      pStmt, N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_NAME);
}







/*
** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
** not define OMIT_DECLTYPE.
*/
#if defined(SQLITE4_OMIT_DECLTYPE) && defined(SQLITE4_ENABLE_COLUMN_METADATA)
# error "Must not define both SQLITE4_OMIT_DECLTYPE \
................................................................................
** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt.
*/
const char *sqlite4_column_decltype(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_DECLTYPE);
}






#endif /* SQLITE4_OMIT_DECLTYPE */

#ifdef SQLITE4_ENABLE_COLUMN_METADATA
/*
** Return the name of the database from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite4_column_database_name(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_DATABASE);
}







/*
** Return the name of the table from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite4_column_table_name(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_TABLE);
}







/*
** Return the name of the table column from which a result column derives.
** NULL is returned if the result column is an expression or constant or
** anything else which is not an unabiguous reference to a database column.
*/
const char *sqlite4_column_origin_name(sqlite4_stmt *pStmt, int N){
  return columnName(pStmt, 
      N, (const void*(*)(Mem*, int*))sqlite4_value_text, COLNAME_COLUMN);
}






#endif /* SQLITE4_ENABLE_COLUMN_METADATA */


/******************************* sqlite4_bind_  ***************************
** 
** Routines used to attach values to wildcards in a compiled SQL statement.
*/

Changes to test/bind.test.

373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# Test that the 'out of range' error works.
do_test bind-8.1 {
  catch { sqlite4_bind_null $VM 0 }
} {1}
do_test bind-8.2 {
  sqlite4_errmsg $DB
} {bind or column index out of range}
ifcapable {utf16} {
  do_test bind-8.3 {
    encoding convertfrom unicode [sqlite4_errmsg16 $DB]
  } {bind or column index out of range}
}
do_test bind-8.4 {
  sqlite4_bind_null $VM 1 
  sqlite4_errmsg $DB
} {not an error}
do_test bind-8.5 {
  catch { sqlite4_bind_null $VM 4 }
} {1}
do_test bind-8.6 {
  sqlite4_errmsg $DB
} {bind or column index out of range}
ifcapable {utf16} {
  do_test bind-8.7 {
    encoding convertfrom unicode [sqlite4_errmsg16 $DB]
  } {bind or column index out of range}
}

do_test bind-8.8 {
  catch { sqlite4_bind_blob $VM 0 "abc" 3 }
} {1}
do_test bind-8.9 {
  catch { sqlite4_bind_blob $VM 4 "abc" 3 }
} {1}







<
|
|
|
<










<
|
|
|
<







373
374
375
376
377
378
379

380
381
382

383
384
385
386
387
388
389
390
391
392

393
394
395

396
397
398
399
400
401
402
# Test that the 'out of range' error works.
do_test bind-8.1 {
  catch { sqlite4_bind_null $VM 0 }
} {1}
do_test bind-8.2 {
  sqlite4_errmsg $DB
} {bind or column index out of range}

do_test bind-8.3 {
  sqlite4_errmsg $DB
} {bind or column index out of range}

do_test bind-8.4 {
  sqlite4_bind_null $VM 1 
  sqlite4_errmsg $DB
} {not an error}
do_test bind-8.5 {
  catch { sqlite4_bind_null $VM 4 }
} {1}
do_test bind-8.6 {
  sqlite4_errmsg $DB
} {bind or column index out of range}

do_test bind-8.7 {
  sqlite4_errmsg $DB
} {bind or column index out of range}


do_test bind-8.8 {
  catch { sqlite4_bind_blob $VM 0 "abc" 3 }
} {1}
do_test bind-8.9 {
  catch { sqlite4_bind_blob $VM 4 "abc" 3 }
} {1}

Changes to test/test_func.c.

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#ifndef SQLITE4_OMIT_BUILTIN_TEST
void sqlite4BeginBenignMalloc(void);
void sqlite4EndBenignMalloc(void);
#else
  #define sqlite4BeginBenignMalloc()
  #define sqlite4EndBenignMalloc()
#endif
static void test_agg_errmsg16_step(sqlite4_context *a, int b,sqlite4_value **c){
}
static void test_agg_errmsg16_final(sqlite4_context *ctx){
#ifndef SQLITE4_OMIT_UTF16
  const void *z;
  sqlite4 * db = sqlite4_context_db_handle(ctx);
  sqlite4_aggregate_context(ctx, 2048);
  sqlite4BeginBenignMalloc();
  z = sqlite4_errmsg16(db);
  sqlite4EndBenignMalloc();
  sqlite4_result_text16(ctx, z, -1, SQLITE4_TRANSIENT, 0);
#endif
}

/*
** Routines for testing the sqlite4_auxdata_fetch() and sqlite4_auxdata_store()
** interface.
**
** The test_auxdata() SQL function attempts to register each of its arguments
** as auxiliary data.  If there are no prior registrations of aux data for
................................................................................
  int i;

  for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
    sqlite4_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
        aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0, 0);
  }

  sqlite4_create_function(db, "test_agg_errmsg16", 0, SQLITE4_ANY, 0, 0, 
      test_agg_errmsg16_step, test_agg_errmsg16_final, 0);
      
  return SQLITE4_OK;
}

/*
** A bogus step function and finalizer function.
*/
static void tStep(sqlite4_context *a, int b, sqlite4_value **c){}







<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<







155
156
157
158
159
160
161













162
163
164
165
166
167
168
...
451
452
453
454
455
456
457



458
459
460
461
462
463
464
#ifndef SQLITE4_OMIT_BUILTIN_TEST
void sqlite4BeginBenignMalloc(void);
void sqlite4EndBenignMalloc(void);
#else
  #define sqlite4BeginBenignMalloc()
  #define sqlite4EndBenignMalloc()
#endif














/*
** Routines for testing the sqlite4_auxdata_fetch() and sqlite4_auxdata_store()
** interface.
**
** The test_auxdata() SQL function attempts to register each of its arguments
** as auxiliary data.  If there are no prior registrations of aux data for
................................................................................
  int i;

  for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
    sqlite4_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
        aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0, 0);
  }




  return SQLITE4_OK;
}

/*
** A bogus step function and finalizer function.
*/
static void tStep(sqlite4_context *a, int b, sqlite4_value **c){}

Changes to test/test_main.c.

866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897
898
899
900
....
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
....
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
....
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
....
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
....
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
....
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
  }
#endif
  if( rc==SQLITE4_OK ){
    rc = sqlite4_create_function(db, "tkt2213func", 1, SQLITE4_ANY, 0, 
          tkt2213Function, 0, 0, 0);
  }

#ifndef SQLITE4_OMIT_UTF16
  /* Use the sqlite4_create_function16() API here. Mainly for fun, but also 
  ** because it is not tested anywhere else. */
  if( rc==SQLITE4_OK ){
    const void *zUtf16;
    sqlite4_value *pVal;
    sqlite4_mutex_enter(db->mutex);
    pVal = sqlite4ValueNew(db);
    sqlite4ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE4_UTF8,
                       SQLITE4_STATIC, 0);
    zUtf16 = sqlite4ValueText(pVal, SQLITE4_UTF16NATIVE);
    if( db->mallocFailed ){
      rc = SQLITE4_NOMEM;
    }else{
      rc = sqlite4_create_function16(db, zUtf16, 
                1, SQLITE4_UTF16, db, sqlite4ExecFunc, 0, 0, 0);

    }
    sqlite4ValueFree(pVal);
    sqlite4_mutex_leave(db->mutex);
  }
#endif

  if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
  return TCL_OK;
}

/*
................................................................................
** Called when a collating sequence is needed.  Registered using
** sqlite4_collation_needed16().
*/
static void test_collate_needed_cb(
  void *pCtx, 
  sqlite4 *db,
  int eTextRep,
  const void *pName
){
  int enc = ENC(db);
  int i;
  char *z;
  for(z = (char*)pName, i=0; *z || z[1]; z++){
    if( *z ) zNeededCollation[i++] = *z;
  }
  zNeededCollation[i] = 0;
  sqlite4_create_collation(
      db, "test_collate", ENC(db), SQLITE4_INT_TO_PTR(enc), test_collate_func,
      0, 0);
}

/*
** Usage: add_test_collate_needed DB
*/
static int test_collate_needed(
  void * clientData,
................................................................................
  Tcl_Obj *CONST objv[]
){
  sqlite4 *db;
  int rc;

  if( objc!=2 ) goto bad_args;
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  rc = sqlite4_collation_needed16(db, test_collate_needed_cb, 0);
  zNeededCollation[0] = 0;
  if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  return TCL_OK;

bad_args:
  Tcl_WrongNumArgs(interp, 1, objv, "DB");
  return TCL_ERROR;
}
................................................................................
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;

  zErr = sqlite4_errmsg(db);
  Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1));
  return TCL_OK;
}

/*
** Usage:   test_errmsg16 DB
**
** Returns the UTF-16 representation of the error message string for the
** most recent sqlite4_* API call. This is a byte array object at the TCL 
** level, and it includes the 0x00 0x00 terminator bytes at the end of the
** UTF-16 string.
*/
static int test_errmsg16(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
#ifndef SQLITE4_OMIT_UTF16
  sqlite4 *db;
  const void *zErr;
  const char *z;
  int bytes = 0;

  if( objc!=2 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", 
       Tcl_GetString(objv[0]), " DB", 0);
    return TCL_ERROR;
  }
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;

  zErr = sqlite4_errmsg16(db);
  if( zErr ){
    z = zErr;
    for(bytes=0; z[bytes] || z[bytes+1]; bytes+=2){}
  }
  Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes));
#endif /* SQLITE4_OMIT_UTF16 */
  return TCL_OK;
}

/*
** Usage: sqlite4_prepare DB sql bytes ?tailvar?
**
** Compile up to <bytes> bytes of the supplied SQL string <sql> using
** database handle <DB>. The parameter <tailval> is the name of a global
** variable that is set to the unused portion of <sql> (if any). A
** STMT handle is returned.
................................................................................

  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
  zRet = xFunc(pStmt, col, 0);
  if( zRet ){
    Tcl_SetResult(interp, (char *)zRet, 0);
  }
  return TCL_OK;
}

/*
** Usage: sqlite4_column_text STMT column
**
** Usage: sqlite4_column_decltype STMT column
**
** Usage: sqlite4_column_name STMT column
*/
static int test_stmt_utf16(
  void * clientData,     /* Pointer to SQLite API function to be invoked */
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
#ifndef SQLITE4_OMIT_UTF16
  sqlite4_stmt *pStmt;
  int col;
  Tcl_Obj *pRet;
  const void *zName16;
  const void *(*xFunc)(sqlite4_stmt*, int);

  xFunc = (const void *(*)(sqlite4_stmt*, int))clientData;
  if( objc!=3 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"", 
       Tcl_GetString(objv[0]), " STMT column", 0);
    return TCL_ERROR;
  }

  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;

  zName16 = xFunc(pStmt, col);
  if( zName16 ){
    int n;
    const char *z = zName16;
    for(n=0; z[n] || z[n+1]; n+=2){}
    pRet = Tcl_NewByteArrayObj(zName16, n+2);
    Tcl_SetObjResult(interp, pRet);
  }
#endif /* SQLITE4_OMIT_UTF16 */

  return TCL_OK;
}

/*
** Usage: sqlite4_column_int STMT column
*/
static int test_stmt_int(
................................................................................
     { "sqlite4_bind_parameter_count",  test_bind_parameter_count, 0},
     { "sqlite4_bind_parameter_name",   test_bind_parameter_name,  0},
     { "sqlite4_bind_parameter_index",  test_bind_parameter_index, 0},
     { "sqlite4_clear_bindings",        test_clear_bindings, 0},
     { "sqlite4_sleep",                 test_sleep,          0},
     { "sqlite4_errcode",               test_errcode       ,0 },
     { "sqlite4_errmsg",                test_errmsg        ,0 },
     { "sqlite4_errmsg16",              test_errmsg16      ,0 },
     { "sqlite4_open",                  test_open          ,0 },
     { "sqlite4_open_v2",               test_open_v2       ,0 },

     { "sqlite4_prepare",               test_prepare       ,0 },
     { "sqlite4_prepare_tkt3134",       test_prepare_tkt3134, 0},
     { "sqlite4_finalize",              test_finalize      ,0 },
     { "sqlite4_stmt_status",           test_stmt_status   ,0 },
................................................................................
#ifdef SQLITE4_ENABLE_COLUMN_METADATA
{ "sqlite4_column_database_name",test_stmt_utf8,(void*)sqlite4_column_database_name},
{ "sqlite4_column_table_name",test_stmt_utf8,(void*)sqlite4_column_table_name},
{ "sqlite4_column_origin_name",test_stmt_utf8,(void*)sqlite4_column_origin_name},
#endif

#ifndef SQLITE4_OMIT_UTF16
     { "sqlite4_column_text16",  test_stmt_utf16, (void*)sqlite4_column_text16},
     { "sqlite4_column_name16",  test_stmt_utf16, (void*)sqlite4_column_name16},
     { "add_alignment_test_collations", add_alignment_test_collations, 0      },
#ifndef SQLITE4_OMIT_DECLTYPE
     { "sqlite4_column_decltype16",test_stmt_utf16,(void*)sqlite4_column_decltype16},
#endif
#ifdef SQLITE4_ENABLE_COLUMN_METADATA
{"sqlite4_column_database_name16",
  test_stmt_utf16, sqlite4_column_database_name16},
{"sqlite4_column_table_name16", test_stmt_utf16, (void*)sqlite4_column_table_name16},
{"sqlite4_column_origin_name16", test_stmt_utf16, (void*)sqlite4_column_origin_name16},
#endif
#endif
     { "sqlite4_create_collation",   test_create_collation, 0 },
     { "working_64bit_int",          working_64bit_int,   0   },
     { "sqlite4_create_function_v2", test_create_function_v2, 0 },

     /* Functions from os.h */
#ifndef SQLITE4_OMIT_UTF16







<
<
<

<
<
<
<
<
<
<
<
<
<
|
|
>
|
<
<
<
<







 







|


<
<
<
<
<
|

|
|







 







|
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<







 







<
<

<
<
<
<
<
<
<
<
<







866
867
868
869
870
871
872



873










874
875
876
877




878
879
880
881
882
883
884
....
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095





2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
....
2109
2110
2111
2112
2113
2114
2115
2116

2117
2118
2119
2120
2121
2122
2123
....
2858
2859
2860
2861
2862
2863
2864





































2865
2866
2867
2868
2869
2870
2871
....
3304
3305
3306
3307
3308
3309
3310











































3311
3312
3313
3314
3315
3316
3317
....
4120
4121
4122
4123
4124
4125
4126

4127
4128
4129
4130
4131
4132
4133
....
4166
4167
4168
4169
4170
4171
4172


4173









4174
4175
4176
4177
4178
4179
4180
  }
#endif
  if( rc==SQLITE4_OK ){
    rc = sqlite4_create_function(db, "tkt2213func", 1, SQLITE4_ANY, 0, 
          tkt2213Function, 0, 0, 0);
  }




  if( rc==SQLITE4_OK ){










    rc = sqlite4_create_function(
        db, "x_sqlite_exec", 1, SQLITE4_UTF16, db, sqlite4ExecFunc, 0, 0, 0
    );
  }





  if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
  return TCL_OK;
}

/*
................................................................................
** Called when a collating sequence is needed.  Registered using
** sqlite4_collation_needed16().
*/
static void test_collate_needed_cb(
  void *pCtx, 
  sqlite4 *db,
  int eTextRep,
  const char *zName
){
  int enc = ENC(db);





  strcpy(zNeededCollation, zName);
  sqlite4_create_collation(
      db, "test_collate", enc, SQLITE4_INT_TO_PTR(enc), test_collate_func, 0, 0
  );
}

/*
** Usage: add_test_collate_needed DB
*/
static int test_collate_needed(
  void * clientData,
................................................................................
  Tcl_Obj *CONST objv[]
){
  sqlite4 *db;
  int rc;

  if( objc!=2 ) goto bad_args;
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  rc = sqlite4_collation_needed(db, test_collate_needed_cb, 0);

  if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  return TCL_OK;

bad_args:
  Tcl_WrongNumArgs(interp, 1, objv, "DB");
  return TCL_ERROR;
}
................................................................................
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;

  zErr = sqlite4_errmsg(db);
  Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1));
  return TCL_OK;
}






































/*
** Usage: sqlite4_prepare DB sql bytes ?tailvar?
**
** Compile up to <bytes> bytes of the supplied SQL string <sql> using
** database handle <DB>. The parameter <tailval> is the name of a global
** variable that is set to the unused portion of <sql> (if any). A
** STMT handle is returned.
................................................................................

  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
  zRet = xFunc(pStmt, col, 0);
  if( zRet ){
    Tcl_SetResult(interp, (char *)zRet, 0);
  }











































  return TCL_OK;
}

/*
** Usage: sqlite4_column_int STMT column
*/
static int test_stmt_int(
................................................................................
     { "sqlite4_bind_parameter_count",  test_bind_parameter_count, 0},
     { "sqlite4_bind_parameter_name",   test_bind_parameter_name,  0},
     { "sqlite4_bind_parameter_index",  test_bind_parameter_index, 0},
     { "sqlite4_clear_bindings",        test_clear_bindings, 0},
     { "sqlite4_sleep",                 test_sleep,          0},
     { "sqlite4_errcode",               test_errcode       ,0 },
     { "sqlite4_errmsg",                test_errmsg        ,0 },

     { "sqlite4_open",                  test_open          ,0 },
     { "sqlite4_open_v2",               test_open_v2       ,0 },

     { "sqlite4_prepare",               test_prepare       ,0 },
     { "sqlite4_prepare_tkt3134",       test_prepare_tkt3134, 0},
     { "sqlite4_finalize",              test_finalize      ,0 },
     { "sqlite4_stmt_status",           test_stmt_status   ,0 },
................................................................................
#ifdef SQLITE4_ENABLE_COLUMN_METADATA
{ "sqlite4_column_database_name",test_stmt_utf8,(void*)sqlite4_column_database_name},
{ "sqlite4_column_table_name",test_stmt_utf8,(void*)sqlite4_column_table_name},
{ "sqlite4_column_origin_name",test_stmt_utf8,(void*)sqlite4_column_origin_name},
#endif

#ifndef SQLITE4_OMIT_UTF16


     { "add_alignment_test_collations", add_alignment_test_collations, 0      },









#endif
     { "sqlite4_create_collation",   test_create_collation, 0 },
     { "working_64bit_int",          working_64bit_int,   0   },
     { "sqlite4_create_function_v2", test_create_function_v2, 0 },

     /* Functions from os.h */
#ifndef SQLITE4_OMIT_UTF16

Changes to test/test_utf.c.

87
88
89
90
91
92
93

94
95
96
97
98
99
100
  val.z = "hello world";
  val.type = SQLITE4_TEXT;
  val.enc = SQLITE4_UTF8;

  for(i=0; i<repeat_count; i++){
    if( do_calls ){
      zVal = sqlite4_value_text(&val, 0);

    }
  }

  return TCL_OK;
}

static u8 name_to_enc(Tcl_Interp *interp, Tcl_Obj *pObj){







>







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  val.z = "hello world";
  val.type = SQLITE4_TEXT;
  val.enc = SQLITE4_UTF8;

  for(i=0; i<repeat_count; i++){
    if( do_calls ){
      zVal = sqlite4_value_text(&val, 0);
      UNUSED_PARAMETER(zVal);
    }
  }

  return TCL_OK;
}

static u8 name_to_enc(Tcl_Interp *interp, Tcl_Obj *pObj){