
b709e29 Fix URL typo in release notes 01f203c Update release notes c49810a Update COPYRIGHT e327526 Add BSL version number to LICENSE.TXT 07e3a4e Remove superfluous COPURIGHT.md and LICENSE.md 54c3310 Replace Dynamic Data Routing Platform with Database Proxy 305d02f Remove *.cmake wildcard from .gitignore b0b5208 Cleanup of spaces aeca6d0 Extend maxscaled error messages 817d74c Document where the CDC users are stored 9a569db Update license ff8697a MXS-716: Fix table level privilege detection 2071a8c Only check replies of slaves that are in use f8dfa42 Fix possible hangs in CDC python scripts fa1d99e Removed "filestem option" from example 009b549 Removed "filestem option" from example 8d515c2 Add example Kafka producer script for Python 64e976b Fix sporadic SSL authentication failures 5a655dc MXS-814: Check service/monitor permissions on all servers 2a7f596 Add note about galeramon priority to Galera tutorials b90b5a6 Fixed SHOW SLAVE STATUS in binlog router e22fe39 Changed couln size for SHOW SLAVE STATUS ae97b18 Fix avrorouter build failure with older sqlite libraries 56ef8b7 Replace GPL license with BSL license in scripts and tests 552836f Initialize all fields when MySQL users are loaded from cache bf42947 Update all licensing related files b29db9d Remove optimize_wildcard parameter from use 5170844 Make readwritesplit diagnosting output more clear 262ffb1 Fix crash when a config parameter has no section 33ac9e6 Add note about LEAST_BEHIND_MASTER and server weights e13e860 Fix a memory leak when backend authentication fails 75d00c2 MXS-801: Set the default value of strip_db_esc to true bd5f2db MXS-800: Add a log message about the working directory 4b1dd8c Update MySQL Monitor documentation on detect_replication_lag 559bc99 Fix installation of license file b057587 Change LICENSE to LICENSE.TXT 223fa43 Remove null characters from log messages 36fd05b Fix fatal signal handler log message 053dc8a Fix typos in documentation 371dc87 Fix Galera text in Master-Slave tutorial 30b6265 Disable adding of new objects at runtime db92311 Update the documentation on configuration reloading 0923d40 Update Connector-C version c4738b5 Add define for avro-conversion.ini 196e6ac Update license from GPL to BSL. e612366 Correctly calculate the number of bytes read in dcb_read 93a2a03 Update rotate documentation in admin tutorial c5eb854 MXS-585: Fix authentication handling regression 6330070 Fix schemarouter memory leak aa5827e Fix CDC authentication memory leak a5af4ad Fix avro memory leaks 627d73f Fix Avro scripts 0ff7556 Add build instructions to avrorouter documentation 734a1c8 Fix doxygen mainpage e51ce09 Add licence text to avro scripts 4d27c14 Update Avro documentation and fix installation directories a58a330 Fix readconnroute error message about router_options 22b138c MXS-772: Fix postinstall script a9960b7 Fix function declaration in mysql_backend.c cbe1704 Add missing newline 09d76ee Fix avro documentation default values 1d3f8f3 Added refresh users on START SLAVE 880db34 Make router configuration errors fatal 3bad5ca Update documentation and add logging to avrorouter 10f3384 Disable SSLv3 ca8d902 Fix rwsplit error reporting when master is lost e816d65 Fix MaxScale Tutorial deca3e1 Update MaxScale man page f1735b7 Update release notes 9238714 qc: Change type of DEALLOCATE PREPARE 0b77c3b dbfwfilter: Do not require a trailing new line 1152ca9 Remove copyright message a038a85 Remove debug assertion on ERANGE error in galeramon 12ab235 Fix comparison error for connections limit. 5de1a8f qc_sqlite: Correct string recognition b63d754 Fix links in documentation contents 05d457e CDC protocol link fix 50676ef Fix monitor code formatting 218ba09 Remove MaxScale-and-SSL.md 0d6845b Add images to Avro documentation and tutorial 8dd2c9b Update MaxScale-2.0.0-Release-Notes.md 6d4b593 Change avrorouter default transaction grouping 4c629de Add notes about monitor changes to upgrading and release notes 267d0dc Update Binlogrouter.md c624781 Update Replication-Proxy-Binlog-Router-Tutorial.md f3261bc CDC users 1368797 Format authenticator and module headers ab01749 Format filters 8b05d32 Format core and include files f3974e5 Add GPL LICENSE to qc_mysqlembedded bfec36a astyle rabbitmq_consumer/consumer.c 54b960a Check that the Avro directory is writable 3d4cd2e Fix cdc_users using the wrong path for service users cache 1e738dd Add CDC client program documentation f6809fd Remove superfluous rabbitmw_consumer/LICENSE 6b5e667 Update license text in files 9bfcb46 Change CDC protocol documentation formatting 607f25c REQUEST-DATA formatting 8175ab4 CDC protocol update d5ca272 CDC protocol update 6c91764 Only check wsrep_local_index if node is joined f12e2c2 Do not use SSL for monitors and services 6d2cd99 Fix TestAdminUsers f4ae50d Apply astyle to server/core/test/*.c 7cc2824 Update build instructions cf8e2b5 Update release notes 03c7a6c Remove wrong function prototypes 5a11eed Revert "Remove duplicate functions" 80ed488 Remove duplicate functions bb0de8d Add info on SSL and throttling to release notes for 2.0. 0934aee Update MaxAdmin reference guide 2a3fe9b Update source URL in release notes e575cf0 Merge branch 'MXS-177-develop' into develop cc8c88d Change header for BSL ecde266 Change header for BSL 890b208 Log a message when a script is executed 9c365df Added information on server side SSL to config guide. aa3e002 Remove obsolete heading 79dd73a Make dprintAllSessions use dprintSession 1fc0db9 Align output of "show services" 1b9d301 Make monitorShowAll use monitorShow 983615e Adjust output of 'show modules' 436badd qc_sqlite: The module is now beta a7cbbe5 Update Upgrade document 71ac13f Remove obsolete user/password from example eb20ff8 Fix and clean up Avrorouter diagnostics code 31d4052 Change MaxScale to MariaDB MaxScale e6e4858 Fix `source` parameter not working with `router_options` d8de99a Update module version numbers eb81add Merge remote-tracking branch 'origin/develop' into MXS-177-develop daba563 Merge remote-tracking branch 'origin/MXS-651-develop-merge' into develop 678f417 Changes in response to reviews. 410fb81 Changes in response to reviews. 60135e5 Add initial release notes about Avrorouter 7400ecc qc_sqlite: Remove uninitialized read 536962c Update version number 018f044 Fix debug assertion in client command processing 51f0804 Prevent 'show monitor' from crashing with failed monitor 559347e Fix "Too many connections" message; add comments. 01d3929 Add printf format checking to dcb_printf fbd49a6 dbfwfilter: Require complete parsing only when needed 1885863 Add information to release notes about readwritesplit changes 73b56a2 Update MaxScale section in release notes. 0a2f56f MaxAdmin: Remove debug information from 'show users' 3cf3279 MaxAdmin: Report SSL information as well 29c2b66 Always use SSL if server configured with SSL 7d6b335 dprintAllServers should use dprintServer 02a5246 qc_sqlite: Correctly detect parsing context 469419b compare: Add strict mode 8c5b3d3 compare: Allow the comparison of a single statement 4691514 Add Updgrade to 2.0 document 38b3ecb Expand the checks done before a monitor is stopped 8e2cfb9 Add backend name to authentication error message 9600a07 Fix MaxInfo crash 91c58b0 Removed log message for duplicate entry while adding an user 40392fe Fixed log message priority 0ec35b8 maxadmin: Allow the last user to be removed 5a0ebed maxadmin: Change name of user file 87aa8f1 maxadmin: Always allow root to connect bf37751 Fix COM_QUIT packet detection 7c93ee4 Update avrorouter documentation and tutorial 95ce463 Fix wrong directory in avrorouter log message cfe54c7 Update ChangeLog d69562c Fix LOAD DATA LOCAL INFILE data size tracking 24e7cd6 MXS-584: added support for SET @@session.autocommit d6f6f76 Fixes, correct too many connections message efeb924 Update release notes for 2.0.0 8f71a87 qc_sqlite: Adjust error messages b967d60 Remove copy of enum enum_server_command 822b7e3 Update package license b58301a Update MaxScale License for overlooked files c09ee47 Update MaxScale License 49f46fa Tidy up. Comment out config items not yet supported. f5c3470 Updated and simplified the Building from Source document 98b98e2 Add note about master failure modes to documentation e036f2c Update Limitations document 62219a5 Merge remote-tracking branch 'origin/drain-writeq' into develop 5caf667 Invoke DCB_REASON_DRAINED more frequently. 77b107b qc_sqlite: Add support for LOAD DATA INFILE 8e70f26 compare: Optionally print out the parse result ad750e6 Merge remote-tracking branch 'origin/MXS-651-develop-merge' into develop ef85779 Merge remote-tracking branch 'origin/develop' into MXS-651-develop-merge ea9fdda MXS-477: Add LONGBLOB support for readconnroute eae6d42 qc_sqlite: Remove superfluous columnname definition 8fe2b21 Add binlog source to avrorouter b25cc37 qc_sqlite: Add missing destructors 8a749e7 qc_sqlite: Reduce number of keywords 5f4bb8b compare: Output query immediately 2456e52 dbfwfilter: Reject queries that cannot be parsed 5f1fbbd qc_sqlite: Extend SET grammar b8d8418 dbfwfilter: Remove 'allow' from firewall filter rule 0bd2a44 MXS-741 When no events are read from binlog file, ... a07c491 Remove duplicated function (merge error, probably) b237008 Save conflict resolution, missed last time. a0c0b40 Merge remote-tracking branch 'origin/develop' into MXS-651-develop 385d47d Change SSL logic, fix large read problem. b93b5e0 Remove false debug assertion b953b1f Turn off SSL read ahead. e0d46a5 Fix error messages and remove commented code 49b4655 MXS-739: Fix invalid JSON in Maxinfo 0c30692 qc_sqlite: Handle GROUP_CONCAT arguments 54e48a1 qc_sqlite: Consider \ as an escape character in strings 713a5d6 qc_sqlite: Add test cases 20d1b51 qc_sqlite: Handle qualified names in CREATE VIEW 1019313 qc_sqlite: Make QUERY_TYPE_WRITE default for SHOW 059c14e qc_sqlite: Accept qualified function names in SELECT db34989 qc_sqlite: Accept qualified function names b93e2f1 qc_sqlite: Add limited support for GRAND and REVOKE 678672d qc_sqlite: Cleanup copying of database and table names 9b744b9 qc_sqlite: Update table and database names at the same time db75e61 qc: Support getting the qualified table names 1f867f4 qc: Add join.test 9c7e02a qc_sqlite: Accept "...from NATURAL straight_join..." 93d1c31 qc_sqlite: Both " and ' can enclose a string literal 8055b21 qc_sqlite: Set more information based upon tokens 37e3663 qc_sqlite: Do not blindly add affected fields 50f1360 qc: Correctly collect affected fields 71c234e qc_sqlite: Recognize CREATE TABLE ... UNION 01803f1 qc_sqlite: Recognize {DEALLOCATE|DROP} PREPARE ... 6ecd4b3 qc_sqlite: Parse index hints 0bdab01 qc: Compare sets of tables b908c8f Fix double freeing of internal DCBs 8903556 qc_sqlite: Recognize LEFT, INSERT and REPLACE 266e6c0 qc: Log all problems by default (compare program) 7b54cac qc_sqlite: Fix logging bug 9566e9f qc_sqlite: Plug a leak b0a860d qc: Run compare a specified number of times 050d698 qc_sqlite: Simplified argument handling 97c56b8 qc: Allow arguments to be passed to the query classifier 09a46e0 qc_sqlite: Add argument log_unrecognized_statements fd98153 qc: Allow arguments to be provided to the query classifier 313aa7e Fix Problems SSL assertion; non SSL connect to SSL 1d721e6 Fix DEB packaging errors 96bdc39 Fix RPM packaging failures on CentOS 7 6ba900d qc_sqlite: Recognize more SHOW commands 2869d0b qc_sqlite: Exclude support for sqlite's PRAGMA 0be68a3 qc_sqlite: Enhance SELECT syntax 28f3e1a Merge branch 'develop' into MXS-729 e18bd41 qc: Expose the result of the parsing 5896085 Add BUILD_AVRO to the CMake cache daeb896 Remove changes to blr_master.c memory handling d523821 Add comments 4eb9a66 Empty admin users file is now handled 52b46c6 qc: Update create.test db09711 qc_sqlite: Ignore case when looking for test language keywords f042a1d qc_sqlite: Extend CREATE TABLE syntax 177d2de qc_sqlite: Extend CREATE TABLE syntax d3ca8e6 qc_sqlite: Add some support for HANDLER 86c6a96 qc_sqlite: Recognize RENAME TABLE 471594f qc_sqlite: Accept more table options at CREATE TABLE 3da6cde qc_sqlite: Remove unused keywords bd89662 Fix crash on corrupted passwd file b5d1764 MXS-733: Always print session states 043e2db Remove unused CMake variables 5604fe2 Restore missing line, fixes logic error. 66d15a5 Added log message warning for old users found 5be9fca Changes in response to review by Johan 899e0e2 Removed password parameter from admin_user_add and admin_remove_user a2d9302 Merge branch 'develop' into MXS-729 bcaf82f Code review update e61c716 Nagios plugin update with Maxadmin using UNIX socket only d7150a2 qc_sqlite: Extend column syntax 3b78df0 qc_sqlite: Accept VALUE in addition to VALUES 85a705b qc_sqlite: Accept CHARSET in addition to CHARACTER SET db9cec8 qc_sqlite: Accept qualified column names in CREATE TABLE a9cabb0 qc_sqlite: Extend SELECT syntax f5e9878 qc_sqlite: Add set type 675cb93 qc_sqlite: Allow BINARY to turn into an identifier b04a760 qc_sqlite: Accept DROP TABLES 1075d9c qc_sqlite: Allow qualified name with LIKE in CREATE 420ac56 qc_sqlite: Extend EXPLAIN grammar 727d626 Add missing error message to readwritesplit f4fd09e Change templates and testing configurations to use sockets 1ef2e06 Add configurable default admin user a723731 Remove wrong file 7c3b02b Maxadmin/maxscaled UNIX socket update eed78d4 qc_sqlite: Pick out more information from select when CREATEing 267f091 qc_sqlite: Recognise DROP TEMPORARY TABLE 54fc29f qc_sqlite: Accept $ as a valid character in identifiers afa2ec9 qc_sqlite: Allow keywords to be used in qualified name db0427d MXS-729 code review update a3b3000 Merge branch 'develop' into MXS-729 e73d66c qc_sqlite: Identify qualified identifiers 5bacade Trailing space fix 3bc9be3 MXS-729 socket=default support in maxscale.cnf 1a5c23c Code review update for MXS-729 d6665c7 qc_sqlite: Extend CREATE TABLE grammar 91725ce qc_sqlite: Dequote table and database names cd7a022 qc: Add create test 1aa4e6b qc: Update test files 762b0c2 qc_mysqlembedded: Do not return "*" as table name cd9968f qc_sqlite: Update delete.test f16703d qc_sqlite: Add support for CALL e3ca9b4 qc_mysqlembedded: Do not return an array of empty strings 5878a22 qc_sqlite: Support selects in DELETE 1cf0444 qc_sqlite: Fix bug in DELETE grammar 0bf39a1 qc_sqlite: Add support for CHECK TABLE 4a8feca qc_sqlite: Add helper for catenating SrcLists ab299b3 qc_sqlite: Extend DELETE syntax 5778856 qc_sqlite: Extract database name as well 99901f1 qc_sqlite: Extend DELETE syntax 63396f8 qc_sqlite: Match "autocommit" caseinsensitively e804dd3 qc_sqlite: Add support for LOCK/UNLOCK c23e442 qc_sqlite: Extend DELETE syntax 5460e31 qc: Add delete test ab392ad qc_sqlite: Free unused data 598c6f0 qc: Measure time of parsing 2fa3844 qc_sqlite: Put all changes being {%|#}ifdefs 1b43992 qc_sqlite: Modified update.test 1676ea4 qc_sqlite: LEFT|RIGHT are not required with JOIN 224ebd3 qc_sqlite: Extend UPDATE grammar dbecca9 qc_sqlite: Extend UPDATE grammar b6ca3b3 MaxAdmin security modification MXS-729 8fb47dd Remove copying of MariaDB embedded library files 22e1257 Normalize whitespace when canonicalizing queries 269cff2 MXS-697: Fix dbfwfilter logging for matched queries 6344f6f Ignore Apple .DS_Store files. d606977 Improve comments in response to code review. 619aa13 Add configuration check flag to MaxScale 27c860b Drain write queue improvements. 33d4154 Read only one configuration file d104c19 Format more core files 83fdead Format part of core source code 311d5de Format gateway.c and config.c with Astyle 8cbb48e Don't build maxavro library if BUILD_AVRO is not defined 32bb77a Merge branch 'MXS-483' into develop db72c5d Format CDC/Avro related files 3c26e27 qc_sqlite: Use SrcList instead of Expr f96ad6a Merge branch 'develop' into MXS-729 0728734 Fix query canonical form tests e68262d Merge remote-tracking branch 'gpl-maxscale/master' into develop 65460dc Fix missing symbols from MySQLAuth 791c821 MaxAdmin listens on UNIX socket only and maxadmin can connect 89afed6 MXS-66: All configuration errors are fatal errors d613053 Add more details to galeramon documentation 22f4f57 qc: Add support for multi UPDATE 0dba25a Added default port to blr_make_registration 9d8248c qc_sqlit: Plug leaks and access errors 057551a qc_sqlite: Fix to small an allocation 1f73820 qc_sqlite: Free memory allocated during parsing 93fefb9 qc: Enable compare to run the same test repeatedly e52c578 qc_sqlite: Handle last_insert_id() 929e02a qc_sqlite: Extend UPDATE grammar de3b9f7 qc_sqlite: Defines provided when running cmake and make 4d5c3b2 qc_sqlite: Add support for multiple-table DELETE FROM 36a4296 qc_mysqlembedded: Handle SQLCOM_DELETE_MULTI 41f613a Fix DCB and SESSION removal from free object pools 00f2ddd Move some common code used in only one protocol into protocol. 6fbd0b0 Format Go source with gofmt abfbbcb Fix build failures and internal test suite 31de74a Merge branch 'develop' into MXS-483 20d461d Remove uniqueness constrain on oneshot tasks 6c09288 Add missing error message to converter task 0c2c389 Merge branch 'develop' into MXS-483 fa0accc Set freed memory to NULL after authentication failure 63f24e4 Install cdc_schema.go 5123c21 Fix ALTER TABLE parsing 004acc2 Merge branch 'develop' into MXS-483 f69a671 Remove array foreach macro use a159cd9 qc_sqlite: Add support for SHOW DATABASES 31a2118 Make qc_mysqlembedded optional 27ef30e Changed the default query classifier 359010d Add -h flag as the alias for --host bebc086 Fix minor bugs c7ca253 qc_sqlite: Recognize START [TRANSACTION] 240f8bf qc_sqlite: Collect info from nested SELECTs 93ea393 qc_sqlite: Pass along the relative position of a token cc960af qc_sqlite: Fix incorrect assigment 22a6fef Fix `gtid` avro index table 4c38bef qc_sqlite: STATUS is not a registered word cace998 qc_sqlite: Include all fields of UPDATE 997b19c qc: Add update tests 7601b3f qc_sqlite: Parse "INSERT INTO t VALUES (), ();" correctly ca426f1 qc_sqlite: Handle CREATE TRIGGER f54f963 qc_sqlite: Allow INSERT without INTO e4a1b6d Remove foreign keys from Avro index e4501a2 Merge branch 'develop' into MXS-483 82b9585 Fix MMMon never assigning master status a45a709 qc_mysqlembedded: Find the leaf name 2f3ca8f qc_mysqlembedded: Recognize SQLCOM_REPLACE cc7ad83 qc_mysqlembedded: Pick up fields for INSERT SELECT as well 0e6b39e qc: Cleanup of select.test 9113f4f qc_sqlite: Pickup more fields from INSERT 4d58f98 Dummy query classifier dfe824f Document `query_classifier` option 4aa329b MXS-718: Collect fields of INSERT 53818f2 Modify packet number for SSL backend connection 346f973 qc_sqlite: Accept qualified column names 8a83616 Fix in-memory SQLite table structure 6f2c884 Further backend SSL development 4444e92 qc_sqlite: Extend INSERT grammar 2aebcab qc_sqlite: Add support for TRUNCATE 1a6742e qc_sqlite: Accept DEFAULT as value in INSERT 07dec05 qc_sqlite: Crude classification made based on seen keywords a90a579 Add missing function documentation 72bd0cf qc_sqlite: Change CREATE TABLE grammar 6e04bc8 qc: Add INSERT tests 3666bda qc_sqlite: Add SELECT test d27e173 Add server/mysql-test/t/select.test to query_classifier 562d004 qc_sqlite: Cleanup error logging. 819cacb Merge branch 'develop' into MXS-483 0d3a789 Add warnings and comments to Avro row event processing 2fab570 Added support for SET autocommit=1 1aa83cf Code review fix c999f0a Addition of SELECT USER() 8c723da Clean up avro_client.c and avro_file.c eb21ee8 Clean up avro.c 946a284 Added Avro schema to table metadata processing 72f90be qc_sqlite: Add support for CREATE {FUNCTION|PROCEDURE} ... 4a4ab49 qc: Update line number also when skipping a block ffddb2a qc_sqlite: Allow queries using INTERVAL b8b03bd qc_sqlite: Add support for SELECT * FROM tbl2 = tbl1; 77a261a qc_sqlite: Add support for GROUP BY ... WITH ROLLUP 0ead41e cdc_schema now generates lowercase JSON 66e327a Classifier has to be specified explicitly 9074b91 Updated Avrorouter documentation cf06c7a qc_sqlite: Some comments added. f579eff Added simple Go based Avro schema generator f448e90 MXS-419: Added ulimit calls to init scripts b4ad257 Added FindAvro.cmake 56cc9b9 Added the last transaction script to installations 2d52da2 Added temporary avro-alpha package name 6ada071 Fixed cdc_users script 61f0206 Renaming and minor fixes to CDC Python scripts 9d77c32 Moved GTID table tracking to an in-memory database 8ae7cb0 MXS-704: Fixed `which` usage in post-install scripts 195e118 Readwritesplit sessions aren't created if master is down 2be91da Added affected tables to avro diagnostics b185320 QUERY-LAST-TRANSACTION now returns proper table names 90860b5 Log stale master message only once 4859c60 Table name to GTID mapping f77bd23 First steps to backend SSL, not yet working. 68b5bf0 qc_sqlite: Don't treat TRUE and FALSE as identifiers fca8e59 qc_sqlite: Collect database names as well 6b0e04d qc_sqlite: Add support for SHOW CREATE VIEW 77f4b34 qc_mysqlembedded: Report more, rather than less a73e033 qc_sqlite: Extend builtin functions 9d9650e qc_sqlite: SQL_BUFFER_RESULT must decay to an id 83fe99d qc_sqlite: Support INSERT IGNORE 9d1c9ca Added avrorouter limitations and tutorial 8dd094d qc_sqlite: Recognize builtin functions 2edc3d6 Moved write operations of the maxavro library to a different file 1364e54 Added more comments to the Avro RBR handling code f711588 Added warnign about unsupported field types df0d250 Added SQLite3 based indexing to avrorouter 0c55706 Added GTID event flag check in AVRO processing bfe28dd qc_sqlite: Accept SET GLOBAL|SESSION ... a8d2068 qc_mysqlembedded: Exlude code that won't compile on 5.5.42 16ea0b3 qc_sqlite: Add support for DROP FUNCTION 1c0f1fc qc: Report stats after comparison 02345b2 qc_sqlite: Recognize builtin readonly functions c7a5e75 qc_sqlite: Recognize := 0aa849d qc: Make compare undestand the delimiter command fb0a877 qc_mysqlembedded: Examine Item::SUBSELECT_ITEMs 045cf8d qc: Add missing mtl commands e5c6f45 qc_sqlite: Relax qc_get_type comparison ac3b2df qc_sqlite: Add support for SHOW STATUS 73a34fb qc_sqlite: Add initial support for FLUSH 4ffbe79 qc_sqlite: Extend CREATE TABLE syntax 009af81 qc_sqlite: Add support for SHOW WARNINGS 001de97 qc: Ignore mysqltest constructs 128307d Merge branch 'release-1.4.3' into gpl-master 5e8a06a SET NAMES XXX added 3ca12ba MXS-685: MMMon clears server state before setting it dc4d2b0 Further steps to connection limit, non-working. ef70257 MXS-636: Master failures are no longer fatal errors 99f4c64 Updated QUERY-LAST-TRANSACTION format d1ff157 Changed QUERY-LAST-TRANSACTION format to JSON 8b2f1ac Fixed formatting of the avrorouter 61543df Added QUERY-LAST-TRANSACTION command c10d10b qc_sqlite: Add support for SHOW CREATE TABLE 106a38f qc_sqlite: Add support for DROP INDEX 2a85421 qc_sqlite: Extend what can be stated about a table 794cd1c qc_sqlite: Add support for MATCH ... AGAINST dd7b747 qc_sqlite: Accept FULLTEXT and SPATIAL in CREATE TABLE a13d6ce qc_sqlite: Add support for PREPARE and EXECUTE 0c5d29f qc_sqlite: Add support for ANALYZE a6cd32b qc_sqlite: Extend SET syntax 5d47704 qc_sqlite: Pick out fields from UPDATE t SET i = ... 0e05735 qc: Understand --error in server test files 8535975 qc_sqlite: Extend CREATE VIEW syntax b35e638 qc: Igore read type bit if write bit is on 818a814 qc_sqlite: Add support for SHOW VARIABLES 1aa877b qc_sqlite: Add initial support for DO e92913a qc_sqlite: Add support for CREATE VIEW d53a46d qc_sqlite: Recognize bit field literals b'1010' 1fb7977 Added GTID event timestmap into struct gtid_pos 8f95b10 Added new fields in AVRO diagnostics cb4db54 Added tests with large SQL packets to modutil tests e4dbd6b MXS-621: More fixes to log messages at startup 4f1e9ee qc: compare tester can now read server MySQL tests cd8154b qc_sqlite: Allow CHARACTER SET to be specified for column 6f8d053 Added MariaDB 10.1 check for new flags in GTID event 71c471b qc_mysqlembedded: Fix type bits setting 26b00a7 qc_sqlite: Extend ALTER grammar ea6057c qc_sqlite: Handle also pInto when dupping a struct select 2271559 qc_sqlite: Add support for SHOW TABLE STATUS 9caaf27 qc_sqlite: Add support for CREATE ... LIKE oldtable cd19932 Merge tag '1.4.2' into master 9e9e4d8 Merge branch 'develop' of https://github.com/mariadb-corporation/maxscale-bsl into develop 267cb60 qc_mysqlembedded: Look into parenthesized comma expressions 77c6ca9 qc_sqlite: Recognize token "<=>" 5ca9a9f qc_sqlite: Allow comma expressions in where clause b08e910 qc_sqlite: Add SELECT options d11e581 qc_sqlite: Some recursion cleanup d53d063 Add but don't invoke connection queue functionality. 6818104 Fix logic error in connections limiter 3c61605 qc_sqlite: Find more affected fields 9af8dfd Allow the classifiers to be specified on the command line 5d4a134 Activate call to protocol for max connections error message. 16638e7 Fix another mistake 234f9e6 Fix mistake 843a6fc Fix mistake. 2c6e9ad Fix errors in config.c; enable call to protocol on connection limit. fd27849 Introduce configuration items for Maximum and Queued Service connections 60d198d Implement very simple connection limit. 84d8f0f Merge remote-tracking branch 'origin/develop' into MXS-177 8a58e63 Merge remote-tracking branch 'origin/develop' into develop 08487cd Add assertion to enforce number of free DCBs not being negative. f73af2f Added MariaDB 10.1 check for new flags in GTID event 23898ec Fix wrong sprintf specifier, trailing white space. ea6cfa3 readwritesplit: Cleaned up routeQuery 3858df0 Cleaned up select_connect_backend_servers c38ee13 Added more buffer tests 48816df Added more modutils tests 537eac2 Added tests for modutil_get_complete_packets 22a6095 MXS-669: modutil_get_complete_packets no longer makes the buffer contiguous 51af97e qc_sqlite: Add support for CREATE INDEX e50c573 qc_sqlite: Dig out fields for IN f58c6df qc_sqlite: Dequote table name 319422b qc_sqlite: Accept ENUM as type for a column 5d6a45c qc_sqlite: Allow UNSIGNED to fallback to an id 16a5f20 qc_sqlite: Extend CREATE TABLE syntax d6268da qc_sqlite: Accept RIGHT and FULL OUTER joins 2207415 qc_sqlite: Allow STRAIGHT_JOIN in SELECT 6fee546 qc_sqlite: Pick upp more table names 9de5f84 Remove trailing white space. 758f84d Improve comments and messages in dcb.c and session.c re recycle memory. 1c2de21 Merge remote-tracking branch 'origin/develop' into dcb-optimise 6614944 DCB code tidying. Fix missing spinlock release; remove redundant variables ecd5e5c Remove extra code introduced by merge. 877127a Merge commit '3c0d3e5ab6ddde59da764ec904b517759074a31e' into develop 4275bbe Updated the Connector-C version to 2.2.3 c71042b Some tentative list management code; provide for counting service clients. ad0c8a6 qc_sqlite: Allow empty insert statement 72e75e5 qc_sqlite: Add support for SELECT ... INTO cc553fa qc_sqlite: MAXSCALE define can now be used everywhere 3305c6e qc_sqlite: Handle CASE in SELECT 702f62e qc_sqlite: Extend CREATE TABLE grammar 941c212 qc_sqlite: Add support for SHOW [INDEX|INDEXES|KEYS] 6a79136 qc_sqlite: Extend grammar for SHOW TABLES and SHOW COLUMNS f175d2d qc_sqlite: Add SHOW COLUMNS support 6e47951 qc_sqlite: Add support for SHOW TABLES bcfa0e7 qc_mysqlembedded: Return the actual name and not as-name 3e19f2e Fixed qlafilter build failure 810b24e MXS-675: Standardized qlafilter output be92173 qc_sqlite: Exclude alias names from affected fields 9479280 qc_sqlite: Add support for explain EXTENDED 13b0e10 qc_sqlite: Add support for DELETE a6ccfea qc_mysqlembedded: Look at all conditional items b428041 qc_sqlite: Extend SELECT options 83f829f query_classifier: Correctly calculate the length of a GWBUF 2ddb24c query_classifier: Ensure that -- comments are handled fa7a746 qc_sqlite: Allow STRAIGHT_JOIN in SELECTS 6f47819 FindLibUUID update 5ed897b Added FindLibUUID cmake file 16e02bb Added FindLibUUID cmake file aff63e0 MXS-680: qc_mysqlembedded does not look into functions 8a0eeb4 query_classifier: Improve output of compare 6f08185 Query classifier can now convert enums to strings 124e2b9 MXS-679: Correctly collect fields of WHERE 353c97c transaction_safety default is off 896e37b qc_sqlite: Invert stop logic and be more verbose 7a44d4d qc_sqlite: Extend what is accepted in CREATE TABLE 4dbf499 qc_sqlite: Accept FIRST in ALTER TABLE 3f655c0 qc_sqlite: Update table and affected fields for INSERT 8e1e275 qc_sqlite: Make AS optional in CREATE statement 5f2084b qc_sqlite: Add support for ENGINE when creating a table 242f183 qc_sqlite: CREATE paramters handled in the correct place 8ed2e25 qc_sqlite: Trace only when needed 63d4531 qc_sqlite: Update affected fields also from functions 118cdc3 qc_sqlite: Allow multiple index names in USE|IGNORE INDEX 912da76 qc_sqlite: Add initial support for ...IGNORE INDEX... 0aa7de6 qc_sqlite: Log detailed message on error 3e3bf1a qc_sqlite: Extend create syntax. c4a4572 qc_sqlite: Exclude quoted values 1621f49 Removed MYSQL_EMBEDDED_LIBRARIES d3e324c UUID generation now comes from libuuid e8fe678 qc_sqlite: Enable confitional compilation a9522ba qc_sqlite: Handle X.Y selects 9bc9770 qc_sqlite: Use same stream when outputting padding 366257a qc_sqlite: Add support for UNSIGNED and ZEROFILL d4d90ff qc_sqlite: Add support for DROP VIEW d0519bd qc_sqlite: Extend DROP TABLE syntax c1e4894 qc_sqlite: Add flag to compare for stopping at first error 9fd6344 MXS-674: Maxinfo generates invalid JSON 3c0d3e5 Fix stupid errors. 9d32b2d Include read queue in buffer provided by dcb_read; changes to match. b690797 Fix double spinlock release in random_jkiss. 6a4328f Fix problems of memory not being freed in some error cases. 2112e56 Change DCB and Session handling to recycle memory; fix bug in random_jkiss. 3912f72 MXS-631, MXS-632: Cleaned up default value CMake files 383ccb8 Fixed build failure on MariaDB 5.5 a60bca5 Merge branch '1.2.1-binlog_router_trx' into develop 3c2a062 Fix to crashes in embedded library with MariaDB 10.0 d3fe938 MXS-662: Service protocol check no longer ignores bind address c3da49b qc_sqlite: Update affected fields from everywhere 7a0fab8 qc_sqlite: Allow verbosity of compare test to be controlled 81d6822 qc_sqlite: Cleanup handling of select columns 13e5c59 qc_sqlite: Introduce custom allocation functions 026f27d qc_sqlite: Add support for "USE database" 99079df qc_sqlite: Ignore duplicates when comparing affected fields ca45cd6 qc_sqlite: Add initial support for qc_get_database_names 75970b6 qc_sqlite: Add support for DROP TABLE. b97e45d qc_sqlite: Move get_affected_fields() to other helpers cb0fa96 qc_sqlite: Collect table names of INSERT 3a7c513 qc_mysqlembedded: Only look for created name if CREATE 308b0a4 qc_sqlite: Add support for gc_get_created_table_name. 0dc4af2 qc_sqlite: Add qc_has_clause() handling to update e9f2d1d qc_sqlite: Update now also provides table names c3192e4 qc_sqlite: Add initial support for get_table_names c51eafd qc_sqlite: Add support for qc_has_clause f318fb2 qc_mysqlembedded: Work around embedded lib bug 4ba2e11 qc_sqlite: Add initial support for qc_get_affected_fields 080dea5 qc_sqlite: Support is_read_query 3f94df1 Fixed compare.cc build failure 868a712 Updated freeing of buffer chains in readwritesplit 9bf7fca Formatted readwritesplit source code de4da2b Add assertion to spinlock release to detect release of already released spinlock. d30955a qc_sqlite: Handle the default case of affected fields. 5d02b3f qc_sqlite: Set operation when creating table 94a334d Add test for comparing qc-output aa6f5d6 Allow a specific query classifier to be loaded explicitly c799d37 Test both qc_mysqlembedded and qc_sqlite f8d9aa1 qc_sqlite: Enable "set @user_var=@@system_var" f190bdc qc_sqlite: Recognize /*!-comments b694b55 Fixed binary Avro format streaming c95fa86 qc_sqlite: Report correctly the type of set autocommit 9cb236c qc_sqlite: Add test case 77b4e62 Ensure classify test checks all types 962039e Change return type of qc_get_type ae00df8 qc_sqlite: Add initial support for the SET statement. 88253c5 qc_sqlite: Rename functions fa48043 Rework of MySQL backend protocol clean up to fix fault. 3851064 qc_sqlite: Correct recognition of system variables (@@xyz). 9d86f7f qc_sqlite: Detect user and system variables. a683297 qc_sqlite: Recognize and accept system variables (@@xyz). a4f64dd qc_sqlite: Add initial support for CREATE [TEMPORARY] TABLE f834b4f MXS-661: Only COM_QUERY packets are parsed 30077c1 CMake policies set only for correct versions a166f34 Suppress warning about unknown CMake target 1412730 Added more variables to launchable monitor scripts 358c194 MXS-656: Galera nodes with index 0 can be master again 842aec5 qc_sqlite: Add support for BEGIN, COMMIT, ROLLBACK b9cad6d Add initial support for UPDATE. 95741cb Add initial support for insert. 3796158 Re-install sqlite whenever parse.y has changed 5bcd8cf Ensure that the query is the one passed cf05533 Add support for obtaining the type of a query 400d8b4 Always log the outcome 45cf632 Fixed resource leaks and minor bugs fa9e970 Printout the query when there is a mismatch. 263cb07 All classify to be used with any query classifier ea381b9 Further cleanup of classify.c 23f6f30 Merge pull request #107 from godmodelabs/typo-dpkg 8c2a64e Fixed classify build failure 0c3070b Fixed binlog to Avro conversion bugs b827ba9 MXS-653: Silence maxpasswd 30d981c MXS-654: Add test for checking maxpasswd 984039b Rearrange classify.c 837e46d Add log initialization 1cc7a6e Reformat query_classifier/test/classify.c 065a4e5 Merge branch 'develop' into develop-MXS-544-b-merge ca27f13 Fixed binlog build failure fb81be2 fixed typo dpgk <-> dpkg 1e88d5d Added python based CDC user creation script 040bbdd MXS-633: Monitor permission checks moved to modules cde7595 Master-Slave clusters are now robust by default 158c776 Cleaned up core test suite 94c6e66 Fixed bugs resulting from merge a491e11 Merge remote-tracking branch 'origin/MXS-544-b' into develop-MXS-544-b-merge 30f9f25 Cleaned up avro.c 6286f64 Merge branch 'release-1.4.1' into develop 00206ac MXS-194: Added support for more query types to dbfwfilter 267832b Fixed diagnostic output a64b694 Fixed bugs in avrorouter 8faaba1 Fixed a bug in GTID seeking a5fafb7 Fixed typos in avrorouter documentation 8080379 Added avrorouter documentation fa07d8a Fixed dbfwfilter rule parser build failure 744ce0d Constraints are ignored in DDL statement processing 50808c6 Cleaned up avrorouter 47f6032 Merge branch '1.2.1-binlog_router_trx_lint' into develop caa0956 Added missing dependencies to maxscale-core 92df61a Remove parallel make from travis coverity builds fa2b2b4 Added more error logging to Avro record reading 9a98e8b Support for GTID requests and data bursts c2a787b Small diagnostic fix c4cee7e Added format output requested by client 50483c7 Cleaning up of Avro code d485379 Added support for binary Avro protocol c22cdbb Converted Avro GTID from string to integer representation 5795ca9 Added coverity notification email to .travis.yml a06e44d Added coverity_scan to Travis 6b94384 Fixed memory leak in avro_schema.c a11096c Support for db.table request for Avrorouter 4e5cbbf Fixed bugs in Avro record reading a99e427 Fixed minor bugs in avrorouter 01db8ae Fixed errors with CREATE TABLE statements f5f3d7a Diagnostic routine update 209324f Added missing include for log_manager.h e62f764 Added sending of schemas and file rotation 8c8fcbb Added missing log_manager.h include b13942d Changed printf calls in maxavro library to MXS_ERROR 1168962 More lint inspired changes, mainly in blr_master.c and blr_slave.c ced8f2f Fixed directory checks in avrorouter a8ae6be Minor fix to string processing fbd2d95 Fixed typo in dbfwfilter's CMakeLists.txt 29c3cf4 Merge pull request #106 from mariadb-corporation/willfong-patch-1 854d4e9 Add password column name to example 2f956df Moved server state change logging to a common function 007121f Fixed truncated string values 782892b Fix lint errors and warnings for blr_file.c 4f99fc5 Added Avro testing script 2820980 Small fix to help clear lint problems in blr.c 3afeda4 Fixed errors and warnings located by lint ecfff82 Fix most lint problems in blr.c 223689c Added ALTER TABLE support 80bc935 Fix final lint problems with mysql_common protocol functions. e068310 Added preliminary alter table parsing 8c723f1 Lint monitor modules fdb5620 Fix lint issues in authenticators. 84f0e04 Added function documentation and renamed files 365d9f5 Tidy up, mainly for lint 2ff3005 Added update rows event processing and event types to avro records 2ae0371 Fixed failing regex and improved data streaming f19206a Renamed avrorouter header aa7174b Moved relpacement and storage of ddl statements to a separate function 0c10be8 Improved client notification and added Avro block size managemet 91405a7 Cleaned up instance creation dd97485 Removed useless vars af64e9e Added CDC authentication with a db file b73a118 Streamline and lint MySQL backend protocol. 65034ce Merge branch 'release-1.4.0' into develop 28f7e4e Added callback for AVRO client async data transmission 628c27a Added MAXAVRO_FILE struct to AVRO_CLIENT 32b3645 Fixed slavelag build failure 7b15542 Added default authentication method for CDC protocol 5f8e20f Renamed maxavro types and formatted files that use them 882cf84 Added more function documentation to maxavro library 9532f0b Fixed CDC protocol build failure 35a1d3a Added support for offsets in client requests 94577ac Fixed, formatted and refactored CDC protocol da9bcad Use the maxavro library to read data from Avro files 3ececee Added low level error checking to maxavro library 01b0b8b Tidy and lint mysql_client.c 943f0a7 Added handling of Avro boolean data types to maxavro library 4c781f7 Cleaned up maxavro library and avrorouter 6b2e85d Renamed functions more consistently and cleaned up code e07158a Moved query event handling to its own function df7d4c0 Added avro_ prefix to rbr.c fcbfceb Added seeking to a position in an Avro file 068243a CDC auth decoding 3584d54 Add checks to simplify downstream logic. 9b2c323 Removed useless fprintf bd5cd52 Added missing authfunc setup e4aff59 Added record value processing 5cc8615 Added value length functions 7921ecc Merge branch 'MXS-615' into MXS-483 4b09cca Added Travis status to readme.md cca3a48 Simplify interface to max admin authentication. 4739838 Authenticator API update 233505f Maxavrocheck now accepts multiple files 3fdd137 Improved the Avro file handling a6ba913 Merge from MXS-615 417d742 Added maxavrocheck 014f9cf Remove obsolete second parameter from authenticate function in authenticators. ece7ece MaxAdmin authentication converted to a module. Fix quirk in SSL setup. 7c8b37e Moved contents of avro_schema.h into mxs_avro.h d6660cf Improvements to type handling 71ed0cf Protocol API to have entry point for obtaining default authenticator name. 9d35de2 Fixed transaction tracking 5be02a2 Avrorouter internal state is now stored in the Avro file directory 9293464 Added new info to avro diagnostics 06e0e93 Protocol modules can still handle the authentication outside authenticator modules 6d7108b Added JSON output when Requesting an avro file 6188211 Added new CDC protocol state c8af27f CDC authentication uses its own authenticator 6590f94 Factor out qc_get_qtype_str b7880f1 Fix qc_sqlite CMakeLists.txt bd4ff43 Fixed connector-c being updated and built after every make invokation 0d9e57b Fixed non-MariaDB connectors being used in builds 3d3b779 FIX BUG IN CLIENT DCB SHUTDOWN THAT CAN CAUSE CRASHES e45ba33 Fixed Connector-C .cmake files c130189 Fixed connector-c being updated and built after every make invokation 7f3cdf3 Fixed errors on binlog rotation 9d3c83a Remove qc_sqlite 15e8ba5 CDC protocol is now compliant with new protocol structure 4460869 Merge branch 'release-1.4.0' into MXS-483 ea40812 Cleaned up the binlog processing loop cb646ca Add minimal select recognition to qc_sqlite ac1a9c5 Fixed binlogrouter test 85dd227 Re-route sqlite's sqlite3Select. 7a2e6f3 Update CMakeLists.txt for qc_sqlite 7a751c3 Added timestamps to records and fixed minor bugs f73bdde Avrorouter state storage to disk fcf0488 Fixed Connector-C .cmake files 48b8e4e Merge branch 'MXS-615' into MXS-615-binlog-merge 7c8e19f Add missing dependencies for qc_sqlite bb9b667 Improvements to type handling and binlog position tracking dc66b74 Client UUID added f12fce4 AVRO registration is now handled by avro router 575b809 Add skeleton sqlite-based query classifier. d09d5fc Build sqlite 146d1f9 Fixed BLOB type handling and refined error messages 6e9e521 Added client user to diagnostics 4538bb8 Merge pull request #104 from rasmushoj/develop 7e18d95 Avro router diagnostics routine update 01e3f75 reverted changes in CMakeLists.txt 52f7c78 reverted changes in postinst.in eaed577 Added sqlite 3110100 a58cdda Travis configuration for MaxScale. ... 38b452d MIGRATE FREE CLIENT DATA TO AUTH MODULE; BUG FIXES; TIDY UP 6e64506 Fixed minor bugs aff2411 Enabled CDC protocol f669100 Fixed NULL Avro value being assigned to a field which cannot be NULL 8f6b16a Added row event processing to avrorouter 2939fe0 Updated Avro schema management to use actual column names 9e3b0cb Removed use of RBR related functions in binlogrouter d674903 Formatted avro files fe028d1 DEVELOPMENT OF AUTHENTICATION AS MODULE - WILL NOT WORK YET 977aded Added authenticator modules to the build a2b384f MOVE MYSQL AUTH CODE INTO AUTHENTICATOR MODULES DIRECTORY a5d7484 PRELIMINARY CHANGES TO CREATE AUTHENTICATORS AS MODULES 66cf802 Merge remote-tracking branch 'origin/develop' into MXS-615 bca0a7d MINOR CHANGES TO SATISFY LINT 5a9e397 Added Avrorouter binlog file walking fbc737f Fixed binlogrouter test 3c7c9d7 Added avrorouter main event handling loop 07ad81b Moved common binlogrouter code to a separate file 8c605ed Fixed avrorouter build failures aa1ba05 Moved binlog definitions to a separate header and fixed build failures eee7c55 Added create table statement detection e52b27e Added AVRO_INSTANCE and AVRO_CLIENT 0830caa Change test for client DCB to use role being DCB_ROLE_CLIENT_HANDLER. ... 997bbca Change protocols to continue looping if an accept fails; ... 522e42d Make use of dcb_accept and dcb_listen in httpd and telnetd protocols. 4e692b0 Generalise dcb_listen to tailor log messages to different protocols. ... 52c431d Remove support for passing default port number when handling ... afe5abc Fix bug in creation of SSL listener structure; fix bugs in ... 0bd6c77 Merge remote-tracking branch 'origin/MXS-544' into MXS-544-a ... 7598597 Add dcb_listen function to make a given DCB into a listener, ... a275d89 Maxbinlogcheck avro version can detect proper end of file 9bb55a5 Moved row event and table map event handling to a separate file b7d9e09 Add/improve comments, fix mistake with premature return. c598770 First attempt at extracting general code into dcb_accept, ... f20f28f Testing with maxbinlogcheck b3c60b7 Added mysql_binlog files 0ff9971 Added MariaDB/MySQL binary data processing functions 124560c Merge branch '1.2.1-binlog_router_trx' into MXS-483 4deccff New router fro cdc client 2c11434 Fixed test compiler errors c1f7d24 Obliged to merge remote-tracking branch 'origin/develop' ... 1775599 Merge remote-tracking branch 'origin/MXS-544' into Test-dev-544-merge c5317da Small modifications in comments 11c0666 Code cleanup 64a5e9a Merge branch 'release-1.3.0' into MXS-483 2c11e89 First Implementation of CDC
7294 lines
209 KiB
C
7294 lines
209 KiB
C
/*
|
|
** 2001 September 15
|
|
**
|
|
** 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.
|
|
**
|
|
*************************************************************************
|
|
** Code for testing all sorts of SQLite interfaces. This code
|
|
** is not included in the SQLite library. It is used for automated
|
|
** testing of the SQLite library.
|
|
*/
|
|
#include "sqliteInt.h"
|
|
#if SQLITE_OS_WIN
|
|
# include "os_win.h"
|
|
#endif
|
|
|
|
#include "vdbeInt.h"
|
|
#include "tcl.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
/*
|
|
** This is a copy of the first part of the SqliteDb structure in
|
|
** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
|
|
** can extract the sqlite3* pointer from an existing Tcl SQLite
|
|
** connection.
|
|
*/
|
|
struct SqliteDb {
|
|
sqlite3 *db;
|
|
};
|
|
|
|
/*
|
|
** Convert text generated by the "%p" conversion format back into
|
|
** a pointer.
|
|
*/
|
|
static int testHexToInt(int h){
|
|
if( h>='0' && h<='9' ){
|
|
return h - '0';
|
|
}else if( h>='a' && h<='f' ){
|
|
return h - 'a' + 10;
|
|
}else{
|
|
assert( h>='A' && h<='F' );
|
|
return h - 'A' + 10;
|
|
}
|
|
}
|
|
void *sqlite3TestTextToPtr(const char *z){
|
|
void *p;
|
|
u64 v;
|
|
u32 v2;
|
|
if( z[0]=='0' && z[1]=='x' ){
|
|
z += 2;
|
|
}
|
|
v = 0;
|
|
while( *z ){
|
|
v = (v<<4) + testHexToInt(*z);
|
|
z++;
|
|
}
|
|
if( sizeof(p)==sizeof(v) ){
|
|
memcpy(&p, &v, sizeof(p));
|
|
}else{
|
|
assert( sizeof(p)==sizeof(v2) );
|
|
v2 = (u32)v;
|
|
memcpy(&p, &v2, sizeof(p));
|
|
}
|
|
return p;
|
|
}
|
|
|
|
|
|
/*
|
|
** A TCL command that returns the address of the sqlite* pointer
|
|
** for an sqlite connection instance. Bad things happen if the
|
|
** input is not an sqlite connection.
|
|
*/
|
|
static int get_sqlite_pointer(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
struct SqliteDb *p;
|
|
Tcl_CmdInfo cmdInfo;
|
|
char zBuf[100];
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION");
|
|
return TCL_ERROR;
|
|
}
|
|
if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){
|
|
Tcl_AppendResult(interp, "command not found: ",
|
|
Tcl_GetString(objv[1]), (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
p = (struct SqliteDb*)cmdInfo.objClientData;
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p->db);
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Decode a pointer to an sqlite3 object.
|
|
*/
|
|
int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
|
|
struct SqliteDb *p;
|
|
Tcl_CmdInfo cmdInfo;
|
|
if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){
|
|
p = (struct SqliteDb*)cmdInfo.objClientData;
|
|
*ppDb = p->db;
|
|
}else{
|
|
*ppDb = (sqlite3*)sqlite3TestTextToPtr(zA);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
#if SQLITE_OS_WIN
|
|
/*
|
|
** Decode a Win32 HANDLE object.
|
|
*/
|
|
int getWin32Handle(Tcl_Interp *interp, const char *zA, LPHANDLE phFile){
|
|
*phFile = (HANDLE)sqlite3TestTextToPtr(zA);
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
extern const char *sqlite3ErrName(int);
|
|
#define t1ErrorName sqlite3ErrName
|
|
|
|
/*
|
|
** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
|
|
** fact that the sqlite3* is the first field in the Vdbe structure.
|
|
*/
|
|
#define StmtToDb(X) sqlite3_db_handle(X)
|
|
|
|
/*
|
|
** Check a return value to make sure it agrees with the results
|
|
** from sqlite3_errcode.
|
|
*/
|
|
int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){
|
|
if( sqlite3_threadsafe()==0 && rc!=SQLITE_MISUSE && rc!=SQLITE_OK
|
|
&& sqlite3_errcode(db)!=rc ){
|
|
char zBuf[200];
|
|
int r2 = sqlite3_errcode(db);
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf,
|
|
"error code %s (%d) does not match sqlite3_errcode %s (%d)",
|
|
t1ErrorName(rc), rc, t1ErrorName(r2), r2);
|
|
Tcl_ResetResult(interp);
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** Decode a pointer to an sqlite3_stmt object.
|
|
*/
|
|
static int getStmtPointer(
|
|
Tcl_Interp *interp,
|
|
const char *zArg,
|
|
sqlite3_stmt **ppStmt
|
|
){
|
|
*ppStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(zArg);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Generate a text representation of a pointer that can be understood
|
|
** by the getDbPointer and getVmPointer routines above.
|
|
**
|
|
** The problem is, on some machines (Solaris) if you do a printf with
|
|
** "%p" you cannot turn around and do a scanf with the same "%p" and
|
|
** get your pointer back. You have to prepend a "0x" before it will
|
|
** work. Or at least that is what is reported to me (drh). But this
|
|
** behavior varies from machine to machine. The solution used her is
|
|
** to test the string right after it is generated to see if it can be
|
|
** understood by scanf, and if not, try prepending an "0x" to see if
|
|
** that helps. If nothing works, a fatal error is generated.
|
|
*/
|
|
int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){
|
|
sqlite3_snprintf(100, zPtr, "%p", p);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** The callback routine for sqlite3_exec_printf().
|
|
*/
|
|
static int exec_printf_cb(void *pArg, int argc, char **argv, char **name){
|
|
Tcl_DString *str = (Tcl_DString*)pArg;
|
|
int i;
|
|
|
|
if( Tcl_DStringLength(str)==0 ){
|
|
for(i=0; i<argc; i++){
|
|
Tcl_DStringAppendElement(str, name[i] ? name[i] : "NULL");
|
|
}
|
|
}
|
|
for(i=0; i<argc; i++){
|
|
Tcl_DStringAppendElement(str, argv[i] ? argv[i] : "NULL");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** The I/O tracing callback.
|
|
*/
|
|
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
|
|
static FILE *iotrace_file = 0;
|
|
static void io_trace_callback(const char *zFormat, ...){
|
|
va_list ap;
|
|
va_start(ap, zFormat);
|
|
vfprintf(iotrace_file, zFormat, ap);
|
|
va_end(ap);
|
|
fflush(iotrace_file);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** Usage: io_trace FILENAME
|
|
**
|
|
** Turn I/O tracing on or off. If FILENAME is not an empty string,
|
|
** I/O tracing begins going into FILENAME. If FILENAME is an empty
|
|
** string, I/O tracing is turned off.
|
|
*/
|
|
static int test_io_trace(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FILENAME\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( iotrace_file ){
|
|
if( iotrace_file!=stdout && iotrace_file!=stderr ){
|
|
fclose(iotrace_file);
|
|
}
|
|
iotrace_file = 0;
|
|
sqlite3IoTrace = 0;
|
|
}
|
|
if( argv[1][0] ){
|
|
if( strcmp(argv[1],"stdout")==0 ){
|
|
iotrace_file = stdout;
|
|
}else if( strcmp(argv[1],"stderr")==0 ){
|
|
iotrace_file = stderr;
|
|
}else{
|
|
iotrace_file = fopen(argv[1], "w");
|
|
}
|
|
sqlite3IoTrace = io_trace_callback;
|
|
}
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: clang_sanitize_address
|
|
**
|
|
** Returns true if the program was compiled using clang with the
|
|
** -fsanitize=address switch on the command line. False otherwise.
|
|
**
|
|
** Also return true if the OMIT_MISUSE environment variable exists.
|
|
*/
|
|
static int clang_sanitize_address(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int res = 0;
|
|
#if defined(__has_feature)
|
|
# if __has_feature(address_sanitizer)
|
|
res = 1;
|
|
# endif
|
|
#endif
|
|
#ifdef __SANITIZE_ADDRESS__
|
|
res = 1;
|
|
#endif
|
|
if( res==0 && getenv("OMIT_MISUSE")!=0 ) res = 1;
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_exec_printf DB FORMAT STRING
|
|
**
|
|
** Invoke the sqlite3_exec_printf() interface using the open database
|
|
** DB. The SQL is the string FORMAT. The format string should contain
|
|
** one %s or %q. STRING is the value inserted into %s or %q.
|
|
*/
|
|
static int test_exec_printf(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
Tcl_DString str;
|
|
int rc;
|
|
char *zErr = 0;
|
|
char *zSql;
|
|
char zBuf[30];
|
|
if( argc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB FORMAT STRING", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
Tcl_DStringInit(&str);
|
|
zSql = sqlite3_mprintf(argv[2], argv[3]);
|
|
rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr);
|
|
sqlite3_free(zSql);
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc);
|
|
Tcl_AppendElement(interp, zBuf);
|
|
Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr);
|
|
Tcl_DStringFree(&str);
|
|
if( zErr ) sqlite3_free(zErr);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_exec_hex DB HEX
|
|
**
|
|
** Invoke the sqlite3_exec() on a string that is obtained by translating
|
|
** HEX into ASCII. Most characters are translated as is. %HH becomes
|
|
** a hex character.
|
|
*/
|
|
static int test_exec_hex(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
Tcl_DString str;
|
|
int rc, i, j;
|
|
char *zErr = 0;
|
|
char *zHex;
|
|
char zSql[501];
|
|
char zBuf[30];
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB HEX", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
zHex = argv[2];
|
|
for(i=j=0; i<(sizeof(zSql)-1) && zHex[j]; i++, j++){
|
|
if( zHex[j]=='%' && zHex[j+2] && zHex[j+2] ){
|
|
zSql[i] = (testHexToInt(zHex[j+1])<<4) + testHexToInt(zHex[j+2]);
|
|
j += 2;
|
|
}else{
|
|
zSql[i] = zHex[j];
|
|
}
|
|
}
|
|
zSql[i] = 0;
|
|
Tcl_DStringInit(&str);
|
|
rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr);
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc);
|
|
Tcl_AppendElement(interp, zBuf);
|
|
Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr);
|
|
Tcl_DStringFree(&str);
|
|
if( zErr ) sqlite3_free(zErr);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: db_enter DB
|
|
** db_leave DB
|
|
**
|
|
** Enter or leave the mutex on a database connection.
|
|
*/
|
|
static int db_enter(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
sqlite3_mutex_enter(db->mutex);
|
|
return TCL_OK;
|
|
}
|
|
static int db_leave(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_exec DB SQL
|
|
**
|
|
** Invoke the sqlite3_exec interface using the open database DB
|
|
*/
|
|
static int test_exec(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
Tcl_DString str;
|
|
int rc;
|
|
char *zErr = 0;
|
|
char *zSql;
|
|
int i, j;
|
|
char zBuf[30];
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB SQL", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
Tcl_DStringInit(&str);
|
|
zSql = sqlite3_mprintf("%s", argv[2]);
|
|
for(i=j=0; zSql[i];){
|
|
if( zSql[i]=='%' ){
|
|
zSql[j++] = (testHexToInt(zSql[i+1])<<4) + testHexToInt(zSql[i+2]);
|
|
i += 3;
|
|
}else{
|
|
zSql[j++] = zSql[i++];
|
|
}
|
|
}
|
|
zSql[j] = 0;
|
|
rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr);
|
|
sqlite3_free(zSql);
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc);
|
|
Tcl_AppendElement(interp, zBuf);
|
|
Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr);
|
|
Tcl_DStringFree(&str);
|
|
if( zErr ) sqlite3_free(zErr);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_exec_nr DB SQL
|
|
**
|
|
** Invoke the sqlite3_exec interface using the open database DB. Discard
|
|
** all results
|
|
*/
|
|
static int test_exec_nr(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
char *zErr = 0;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB SQL", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ...
|
|
**
|
|
** Test the %z format of sqlite_mprintf(). Use multiple mprintf() calls to
|
|
** concatenate arg0 through argn using separator as the separator.
|
|
** Return the result.
|
|
*/
|
|
static int test_mprintf_z(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
char *zResult = 0;
|
|
int i;
|
|
|
|
for(i=2; i<argc && (i==2 || zResult); i++){
|
|
zResult = sqlite3_mprintf("%z%s%s", zResult, argv[1], argv[i]);
|
|
}
|
|
Tcl_AppendResult(interp, zResult, 0);
|
|
sqlite3_free(zResult);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_n_test STRING
|
|
**
|
|
** Test the %n format of sqlite_mprintf(). Return the length of the
|
|
** input string.
|
|
*/
|
|
static int test_mprintf_n(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
char *zStr;
|
|
int n = 0;
|
|
zStr = sqlite3_mprintf("%s%n", argv[1], &n);
|
|
sqlite3_free(zStr);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(n));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_snprintf_int SIZE FORMAT INT
|
|
**
|
|
** Test the of sqlite3_snprintf() routine. SIZE is the size of the
|
|
** output buffer in bytes. The maximum size is 100. FORMAT is the
|
|
** format string. INT is a single integer argument. The FORMAT
|
|
** string must require no more than this one integer argument. If
|
|
** You pass in a format string that requires more than one argument,
|
|
** bad things will happen.
|
|
*/
|
|
static int test_snprintf_int(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
char zStr[100];
|
|
int n = atoi(argv[1]);
|
|
const char *zFormat = argv[2];
|
|
int a1 = atoi(argv[3]);
|
|
if( n>sizeof(zStr) ) n = sizeof(zStr);
|
|
sqlite3_snprintf(sizeof(zStr), zStr, "abcdefghijklmnopqrstuvwxyz");
|
|
sqlite3_snprintf(n, zStr, zFormat, a1);
|
|
Tcl_AppendResult(interp, zStr, 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_GET_TABLE
|
|
|
|
/*
|
|
** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts?
|
|
**
|
|
** Invoke the sqlite3_get_table_printf() interface using the open database
|
|
** DB. The SQL is the string FORMAT. The format string should contain
|
|
** one %s or %q. STRING is the value inserted into %s or %q.
|
|
*/
|
|
static int test_get_table_printf(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
Tcl_DString str;
|
|
int rc;
|
|
char *zErr = 0;
|
|
int nRow = 0, nCol = 0;
|
|
char **aResult;
|
|
int i;
|
|
char zBuf[30];
|
|
char *zSql;
|
|
int resCount = -1;
|
|
if( argc==5 ){
|
|
if( Tcl_GetInt(interp, argv[4], &resCount) ) return TCL_ERROR;
|
|
}
|
|
if( argc!=4 && argc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB FORMAT STRING ?COUNT?", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
Tcl_DStringInit(&str);
|
|
zSql = sqlite3_mprintf(argv[2],argv[3]);
|
|
if( argc==5 ){
|
|
rc = sqlite3_get_table(db, zSql, &aResult, 0, 0, &zErr);
|
|
}else{
|
|
rc = sqlite3_get_table(db, zSql, &aResult, &nRow, &nCol, &zErr);
|
|
resCount = (nRow+1)*nCol;
|
|
}
|
|
sqlite3_free(zSql);
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", rc);
|
|
Tcl_AppendElement(interp, zBuf);
|
|
if( rc==SQLITE_OK ){
|
|
if( argc==4 ){
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", nRow);
|
|
Tcl_AppendElement(interp, zBuf);
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", nCol);
|
|
Tcl_AppendElement(interp, zBuf);
|
|
}
|
|
for(i=0; i<resCount; i++){
|
|
Tcl_AppendElement(interp, aResult[i] ? aResult[i] : "NULL");
|
|
}
|
|
}else{
|
|
Tcl_AppendElement(interp, zErr);
|
|
}
|
|
sqlite3_free_table(aResult);
|
|
if( zErr ) sqlite3_free(zErr);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
#endif /* SQLITE_OMIT_GET_TABLE */
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_last_insert_rowid DB
|
|
**
|
|
** Returns the integer ROWID of the most recent insert.
|
|
*/
|
|
static int test_last_rowid(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
char zBuf[30];
|
|
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", sqlite3_last_insert_rowid(db));
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_key DB KEY
|
|
**
|
|
** Set the codec key.
|
|
*/
|
|
static int test_key(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
#ifdef SQLITE_HAS_CODEC
|
|
sqlite3 *db;
|
|
const char *zKey;
|
|
int nKey;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FILENAME\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
zKey = argv[2];
|
|
nKey = strlen(zKey);
|
|
sqlite3_key(db, zKey, nKey);
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_rekey DB KEY
|
|
**
|
|
** Change the codec key.
|
|
*/
|
|
static int test_rekey(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
#ifdef SQLITE_HAS_CODEC
|
|
sqlite3 *db;
|
|
const char *zKey;
|
|
int nKey;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FILENAME\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
zKey = argv[2];
|
|
nKey = strlen(zKey);
|
|
sqlite3_rekey(db, zKey, nKey);
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_close DB
|
|
**
|
|
** Closes the database opened by sqlite3_open.
|
|
*/
|
|
static int sqlite_test_close(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FILENAME\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_close(db);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_close_v2 DB
|
|
**
|
|
** Closes the database opened by sqlite3_open.
|
|
*/
|
|
static int sqlite_test_close_v2(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FILENAME\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_close_v2(db);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Implementation of the x_coalesce() function.
|
|
** Return the first argument non-NULL argument.
|
|
*/
|
|
static void t1_ifnullFunc(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
int i;
|
|
for(i=0; i<argc; i++){
|
|
if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){
|
|
int n = sqlite3_value_bytes(argv[i]);
|
|
sqlite3_result_text(context, (char*)sqlite3_value_text(argv[i]),
|
|
n, SQLITE_TRANSIENT);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
** These are test functions. hex8() interprets its argument as
|
|
** UTF8 and returns a hex encoding. hex16le() interprets its argument
|
|
** as UTF16le and returns a hex encoding.
|
|
*/
|
|
static void hex8Func(sqlite3_context *p, int argc, sqlite3_value **argv){
|
|
const unsigned char *z;
|
|
int i;
|
|
char zBuf[200];
|
|
z = sqlite3_value_text(argv[0]);
|
|
for(i=0; i<sizeof(zBuf)/2 - 2 && z[i]; i++){
|
|
sqlite3_snprintf(sizeof(zBuf)-i*2, &zBuf[i*2], "%02x", z[i]);
|
|
}
|
|
zBuf[i*2] = 0;
|
|
sqlite3_result_text(p, (char*)zBuf, -1, SQLITE_TRANSIENT);
|
|
}
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
static void hex16Func(sqlite3_context *p, int argc, sqlite3_value **argv){
|
|
const unsigned short int *z;
|
|
int i;
|
|
char zBuf[400];
|
|
z = sqlite3_value_text16(argv[0]);
|
|
for(i=0; i<sizeof(zBuf)/4 - 4 && z[i]; i++){
|
|
sqlite3_snprintf(sizeof(zBuf)-i*4, &zBuf[i*4],"%04x", z[i]&0xff);
|
|
}
|
|
zBuf[i*4] = 0;
|
|
sqlite3_result_text(p, (char*)zBuf, -1, SQLITE_TRANSIENT);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** A structure into which to accumulate text.
|
|
*/
|
|
struct dstr {
|
|
int nAlloc; /* Space allocated */
|
|
int nUsed; /* Space used */
|
|
char *z; /* The space */
|
|
};
|
|
|
|
/*
|
|
** Append text to a dstr
|
|
*/
|
|
static void dstrAppend(struct dstr *p, const char *z, int divider){
|
|
int n = (int)strlen(z);
|
|
if( p->nUsed + n + 2 > p->nAlloc ){
|
|
char *zNew;
|
|
p->nAlloc = p->nAlloc*2 + n + 200;
|
|
zNew = sqlite3_realloc(p->z, p->nAlloc);
|
|
if( zNew==0 ){
|
|
sqlite3_free(p->z);
|
|
memset(p, 0, sizeof(*p));
|
|
return;
|
|
}
|
|
p->z = zNew;
|
|
}
|
|
if( divider && p->nUsed>0 ){
|
|
p->z[p->nUsed++] = divider;
|
|
}
|
|
memcpy(&p->z[p->nUsed], z, n+1);
|
|
p->nUsed += n;
|
|
}
|
|
|
|
/*
|
|
** Invoked for each callback from sqlite3ExecFunc
|
|
*/
|
|
static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){
|
|
struct dstr *p = (struct dstr*)pData;
|
|
int i;
|
|
for(i=0; i<argc; i++){
|
|
if( argv[i]==0 ){
|
|
dstrAppend(p, "NULL", ' ');
|
|
}else{
|
|
dstrAppend(p, argv[i], ' ');
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** Implementation of the x_sqlite_exec() function. This function takes
|
|
** a single argument and attempts to execute that argument as SQL code.
|
|
** This is illegal and should set the SQLITE_MISUSE flag on the database.
|
|
**
|
|
** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec()
|
|
** from within a function call.
|
|
**
|
|
** This routine simulates the effect of having two threads attempt to
|
|
** use the same database at the same time.
|
|
*/
|
|
static void sqlite3ExecFunc(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
struct dstr x;
|
|
memset(&x, 0, sizeof(x));
|
|
(void)sqlite3_exec((sqlite3*)sqlite3_user_data(context),
|
|
(char*)sqlite3_value_text(argv[0]),
|
|
execFuncCallback, &x, 0);
|
|
sqlite3_result_text(context, x.z, x.nUsed, SQLITE_TRANSIENT);
|
|
sqlite3_free(x.z);
|
|
}
|
|
|
|
/*
|
|
** Implementation of tkt2213func(), a scalar function that takes exactly
|
|
** one argument. It has two interesting features:
|
|
**
|
|
** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*.
|
|
** If the three pointers returned are not the same an SQL error is raised.
|
|
**
|
|
** * Otherwise it returns a copy of the text representation of its
|
|
** argument in such a way as the VDBE representation is a Mem* cell
|
|
** with the MEM_Term flag clear.
|
|
**
|
|
** Ticket #2213 can therefore be tested by evaluating the following
|
|
** SQL expression:
|
|
**
|
|
** tkt2213func(tkt2213func('a string'));
|
|
*/
|
|
static void tkt2213Function(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
int nText;
|
|
unsigned char const *zText1;
|
|
unsigned char const *zText2;
|
|
unsigned char const *zText3;
|
|
|
|
nText = sqlite3_value_bytes(argv[0]);
|
|
zText1 = sqlite3_value_text(argv[0]);
|
|
zText2 = sqlite3_value_text(argv[0]);
|
|
zText3 = sqlite3_value_text(argv[0]);
|
|
|
|
if( zText1!=zText2 || zText2!=zText3 ){
|
|
sqlite3_result_error(context, "tkt2213 is not fixed", -1);
|
|
}else{
|
|
char *zCopy = (char *)sqlite3_malloc(nText);
|
|
memcpy(zCopy, zText1, nText);
|
|
sqlite3_result_text(context, zCopy, nText, sqlite3_free);
|
|
}
|
|
}
|
|
|
|
/*
|
|
** The following SQL function takes 4 arguments. The 2nd and
|
|
** 4th argument must be one of these strings: 'text', 'text16',
|
|
** or 'blob' corresponding to API functions
|
|
**
|
|
** sqlite3_value_text()
|
|
** sqlite3_value_text16()
|
|
** sqlite3_value_blob()
|
|
**
|
|
** The third argument is a string, either 'bytes' or 'bytes16' or 'noop',
|
|
** corresponding to APIs:
|
|
**
|
|
** sqlite3_value_bytes()
|
|
** sqlite3_value_bytes16()
|
|
** noop
|
|
**
|
|
** The APIs designated by the 2nd through 4th arguments are applied
|
|
** to the first argument in order. If the pointers returned by the
|
|
** second and fourth are different, this routine returns 1. Otherwise,
|
|
** this routine returns 0.
|
|
**
|
|
** This function is used to test to see when returned pointers from
|
|
** the _text(), _text16() and _blob() APIs become invalidated.
|
|
*/
|
|
static void ptrChngFunction(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
const void *p1, *p2;
|
|
const char *zCmd;
|
|
if( argc!=4 ) return;
|
|
zCmd = (const char*)sqlite3_value_text(argv[1]);
|
|
if( zCmd==0 ) return;
|
|
if( strcmp(zCmd,"text")==0 ){
|
|
p1 = (const void*)sqlite3_value_text(argv[0]);
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
}else if( strcmp(zCmd, "text16")==0 ){
|
|
p1 = (const void*)sqlite3_value_text16(argv[0]);
|
|
#endif
|
|
}else if( strcmp(zCmd, "blob")==0 ){
|
|
p1 = (const void*)sqlite3_value_blob(argv[0]);
|
|
}else{
|
|
return;
|
|
}
|
|
zCmd = (const char*)sqlite3_value_text(argv[2]);
|
|
if( zCmd==0 ) return;
|
|
if( strcmp(zCmd,"bytes")==0 ){
|
|
sqlite3_value_bytes(argv[0]);
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
}else if( strcmp(zCmd, "bytes16")==0 ){
|
|
sqlite3_value_bytes16(argv[0]);
|
|
#endif
|
|
}else if( strcmp(zCmd, "noop")==0 ){
|
|
/* do nothing */
|
|
}else{
|
|
return;
|
|
}
|
|
zCmd = (const char*)sqlite3_value_text(argv[3]);
|
|
if( zCmd==0 ) return;
|
|
if( strcmp(zCmd,"text")==0 ){
|
|
p2 = (const void*)sqlite3_value_text(argv[0]);
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
}else if( strcmp(zCmd, "text16")==0 ){
|
|
p2 = (const void*)sqlite3_value_text16(argv[0]);
|
|
#endif
|
|
}else if( strcmp(zCmd, "blob")==0 ){
|
|
p2 = (const void*)sqlite3_value_blob(argv[0]);
|
|
}else{
|
|
return;
|
|
}
|
|
sqlite3_result_int(context, p1!=p2);
|
|
}
|
|
|
|
/*
|
|
** This SQL function returns a different answer each time it is called, even if
|
|
** the arguments are the same.
|
|
*/
|
|
static void nondeterministicFunction(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
static int cnt = 0;
|
|
sqlite3_result_int(context, cnt++);
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_create_function DB
|
|
**
|
|
** Call the sqlite3_create_function API on the given database in order
|
|
** to create a function named "x_coalesce". This function does the same thing
|
|
** as the "coalesce" function. This function also registers an SQL function
|
|
** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec()
|
|
** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
|
|
** The effect is similar to trying to use the same database connection from
|
|
** two threads at the same time.
|
|
**
|
|
** The original motivation for this routine was to be able to call the
|
|
** sqlite3_create_function function while a query is in progress in order
|
|
** to test the SQLITE_MISUSE detection logic.
|
|
*/
|
|
static int test_create_function(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int rc;
|
|
sqlite3 *db;
|
|
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_create_function(db, "x_coalesce", -1, SQLITE_UTF8, 0,
|
|
t1_ifnullFunc, 0, 0);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "hex8", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC,
|
|
0, hex8Func, 0, 0);
|
|
}
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "hex16", 1, SQLITE_UTF16 | SQLITE_DETERMINISTIC,
|
|
0, hex16Func, 0, 0);
|
|
}
|
|
#endif
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "tkt2213func", 1, SQLITE_ANY, 0,
|
|
tkt2213Function, 0, 0);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "pointer_change", 4, SQLITE_ANY, 0,
|
|
ptrChngFunction, 0, 0);
|
|
}
|
|
|
|
/* Functions counter1() and counter2() have the same implementation - they
|
|
** both return an ascending integer with each call. But counter1() is marked
|
|
** as non-deterministic and counter2() is marked as deterministic.
|
|
*/
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "counter1", -1, SQLITE_UTF8,
|
|
0, nondeterministicFunction, 0, 0);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "counter2", -1, SQLITE_UTF8|SQLITE_DETERMINISTIC,
|
|
0, nondeterministicFunction, 0, 0);
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/* Use the sqlite3_create_function16() API here. Mainly for fun, but also
|
|
** because it is not tested anywhere else. */
|
|
if( rc==SQLITE_OK ){
|
|
const void *zUtf16;
|
|
sqlite3_value *pVal;
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pVal = sqlite3ValueNew(db);
|
|
sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC);
|
|
zUtf16 = sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
|
|
if( db->mallocFailed ){
|
|
rc = SQLITE_NOMEM;
|
|
}else{
|
|
rc = sqlite3_create_function16(db, zUtf16,
|
|
1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0);
|
|
}
|
|
sqlite3ValueFree(pVal);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
}
|
|
#endif
|
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Routines to implement the x_count() aggregate function.
|
|
**
|
|
** x_count() counts the number of non-null arguments. But there are
|
|
** some twists for testing purposes.
|
|
**
|
|
** If the argument to x_count() is 40 then a UTF-8 error is reported
|
|
** on the step function. If x_count(41) is seen, then a UTF-16 error
|
|
** is reported on the step function. If the total count is 42, then
|
|
** a UTF-8 error is reported on the finalize function.
|
|
*/
|
|
typedef struct t1CountCtx t1CountCtx;
|
|
struct t1CountCtx {
|
|
int n;
|
|
};
|
|
static void t1CountStep(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
t1CountCtx *p;
|
|
p = sqlite3_aggregate_context(context, sizeof(*p));
|
|
if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0]) ) && p ){
|
|
p->n++;
|
|
}
|
|
if( argc>0 ){
|
|
int v = sqlite3_value_int(argv[0]);
|
|
if( v==40 ){
|
|
sqlite3_result_error(context, "value of 40 handed to x_count", -1);
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
}else if( v==41 ){
|
|
const char zUtf16ErrMsg[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0};
|
|
sqlite3_result_error16(context, &zUtf16ErrMsg[1-SQLITE_BIGENDIAN], -1);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
static void t1CountFinalize(sqlite3_context *context){
|
|
t1CountCtx *p;
|
|
p = sqlite3_aggregate_context(context, sizeof(*p));
|
|
if( p ){
|
|
if( p->n==42 ){
|
|
sqlite3_result_error(context, "x_count totals to 42", -1);
|
|
}else{
|
|
sqlite3_result_int(context, p ? p->n : 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
static void legacyCountStep(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
/* no-op */
|
|
}
|
|
|
|
static void legacyCountFinalize(sqlite3_context *context){
|
|
sqlite3_result_int(context, sqlite3_aggregate_count(context));
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** Usage: sqlite3_create_aggregate DB
|
|
**
|
|
** Call the sqlite3_create_function API on the given database in order
|
|
** to create a function named "x_count". This function is similar
|
|
** to the built-in count() function, with a few special quirks
|
|
** for testing the sqlite3_result_error() APIs.
|
|
**
|
|
** The original motivation for this routine was to be able to call the
|
|
** sqlite3_create_aggregate function while a query is in progress in order
|
|
** to test the SQLITE_MISUSE detection logic. See misuse.test.
|
|
**
|
|
** This routine was later extended to test the use of sqlite3_result_error()
|
|
** within aggregate functions.
|
|
**
|
|
** Later: It is now also extended to register the aggregate function
|
|
** "legacy_count()" with the supplied database handle. This is used
|
|
** to test the deprecated sqlite3_aggregate_count() API.
|
|
*/
|
|
static int test_create_aggregate(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FILENAME\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0,
|
|
t1CountStep,t1CountFinalize);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0,
|
|
t1CountStep,t1CountFinalize);
|
|
}
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(db, "legacy_count", 0, SQLITE_ANY, 0, 0,
|
|
legacyCountStep, legacyCountFinalize
|
|
);
|
|
}
|
|
#endif
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** Usage: printf TEXT
|
|
**
|
|
** Send output to printf. Use this rather than puts to merge the output
|
|
** in the correct sequence with debugging printfs inserted into C code.
|
|
** Puts uses a separate buffer and debugging statements will be out of
|
|
** sequence if it is used.
|
|
*/
|
|
static int test_printf(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" TEXT\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
printf("%s\n", argv[1]);
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER
|
|
**
|
|
** Call mprintf with three integer arguments
|
|
*/
|
|
static int sqlite3_mprintf_int(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int a[3], i;
|
|
char *z;
|
|
if( argc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT INT INT INT\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=2; i<5; i++){
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
|
}
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER
|
|
**
|
|
** Call mprintf with three 64-bit integer arguments
|
|
*/
|
|
static int sqlite3_mprintf_int64(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int i;
|
|
sqlite_int64 a[3];
|
|
char *z;
|
|
if( argc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT INT INT INT\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=2; i<5; i++){
|
|
if( sqlite3Atoi64(argv[i], &a[i-2], 1000000, SQLITE_UTF8) ){
|
|
Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_long FORMAT INTEGER INTEGER INTEGER
|
|
**
|
|
** Call mprintf with three long integer arguments. This might be the
|
|
** same as sqlite3_mprintf_int or sqlite3_mprintf_int64, depending on
|
|
** platform.
|
|
*/
|
|
static int sqlite3_mprintf_long(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int i;
|
|
long int a[3];
|
|
int b[3];
|
|
char *z;
|
|
if( argc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT INT INT INT\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=2; i<5; i++){
|
|
if( Tcl_GetInt(interp, argv[i], &b[i-2]) ) return TCL_ERROR;
|
|
a[i-2] = (long int)b[i-2];
|
|
a[i-2] &= (((u64)1)<<(sizeof(int)*8))-1;
|
|
}
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING
|
|
**
|
|
** Call mprintf with two integer arguments and one string argument
|
|
*/
|
|
static int sqlite3_mprintf_str(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int a[3], i;
|
|
char *z;
|
|
if( argc<4 || argc>5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT INT INT ?STRING?\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=2; i<4; i++){
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
|
}
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING
|
|
**
|
|
** Call mprintf with two integer arguments and one string argument
|
|
*/
|
|
static int sqlite3_snprintf_str(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int a[3], i;
|
|
int n;
|
|
char *z;
|
|
if( argc<5 || argc>6 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" INT FORMAT INT INT ?STRING?\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
|
if( n<0 ){
|
|
Tcl_AppendResult(interp, "N must be non-negative", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=3; i<5; i++){
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-3]) ) return TCL_ERROR;
|
|
}
|
|
z = sqlite3_malloc( n+1 );
|
|
sqlite3_snprintf(n, z, argv[2], a[0], a[1], argc>4 ? argv[5] : NULL);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
|
|
**
|
|
** Call mprintf with two integer arguments and one double argument
|
|
*/
|
|
static int sqlite3_mprintf_double(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int a[3], i;
|
|
double r;
|
|
char *z;
|
|
if( argc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT INT INT DOUBLE\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=2; i<4; i++){
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR;
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], r);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
|
|
**
|
|
** Call mprintf with a single double argument which is the product of the
|
|
** two arguments given above. This is used to generate overflow and underflow
|
|
** doubles to test that they are converted properly.
|
|
*/
|
|
static int sqlite3_mprintf_scaled(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
int i;
|
|
double r[2];
|
|
char *z;
|
|
if( argc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT DOUBLE DOUBLE\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
for(i=2; i<4; i++){
|
|
if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR;
|
|
}
|
|
z = sqlite3_mprintf(argv[1], r[0]*r[1]);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_stronly FORMAT STRING
|
|
**
|
|
** Call mprintf with a single double argument which is the product of the
|
|
** two arguments given above. This is used to generate overflow and underflow
|
|
** doubles to test that they are converted properly.
|
|
*/
|
|
static int sqlite3_mprintf_stronly(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
char *z;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT STRING\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
z = sqlite3_mprintf(argv[1], argv[2]);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
|
|
**
|
|
** Call mprintf with a single double argument which is derived from the
|
|
** hexadecimal encoding of an IEEE double.
|
|
*/
|
|
static int sqlite3_mprintf_hexdouble(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
char *z;
|
|
double r;
|
|
unsigned int x1, x2;
|
|
sqlite_uint64 d;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" FORMAT STRING\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){
|
|
Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
d = x2;
|
|
d = (d<<32) + x1;
|
|
memcpy(&r, &d, sizeof(r));
|
|
z = sqlite3_mprintf(argv[1], r);
|
|
Tcl_AppendResult(interp, z, 0);
|
|
sqlite3_free(z);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_enable_shared_cache ?BOOLEAN?
|
|
**
|
|
*/
|
|
#if !defined(SQLITE_OMIT_SHARED_CACHE)
|
|
static int test_enable_shared(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int rc;
|
|
int enable;
|
|
int ret = 0;
|
|
|
|
if( objc!=2 && objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?");
|
|
return TCL_ERROR;
|
|
}
|
|
ret = sqlite3GlobalConfig.sharedCacheEnabled;
|
|
|
|
if( objc==2 ){
|
|
if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_enable_shared_cache(enable);
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC);
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret));
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_extended_result_codes DB BOOLEAN
|
|
**
|
|
*/
|
|
static int test_extended_result_codes(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int enable;
|
|
sqlite3 *db;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR;
|
|
sqlite3_extended_result_codes(db, enable);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_libversion_number
|
|
**
|
|
*/
|
|
static int test_libversion_number(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number()));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_table_column_metadata DB dbname tblname colname
|
|
**
|
|
*/
|
|
static int test_table_column_metadata(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
const char *zDb;
|
|
const char *zTbl;
|
|
const char *zCol;
|
|
int rc;
|
|
Tcl_Obj *pRet;
|
|
|
|
const char *zDatatype;
|
|
const char *zCollseq;
|
|
int notnull;
|
|
int primarykey;
|
|
int autoincrement;
|
|
|
|
if( objc!=5 && objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB dbname tblname colname");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zDb = Tcl_GetString(objv[2]);
|
|
zTbl = Tcl_GetString(objv[3]);
|
|
zCol = objc==5 ? Tcl_GetString(objv[4]) : 0;
|
|
|
|
if( strlen(zDb)==0 ) zDb = 0;
|
|
|
|
rc = sqlite3_table_column_metadata(db, zDb, zTbl, zCol,
|
|
&zDatatype, &zCollseq, ¬null, &primarykey, &autoincrement);
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_AppendResult(interp, sqlite3_errmsg(db), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
pRet = Tcl_NewObj();
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zDatatype, -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zCollseq, -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(notnull));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(primarykey));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(autoincrement));
|
|
Tcl_SetObjResult(interp, pRet);
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_INCRBLOB
|
|
|
|
static int blobHandleFromObj(
|
|
Tcl_Interp *interp,
|
|
Tcl_Obj *pObj,
|
|
sqlite3_blob **ppBlob
|
|
){
|
|
char *z;
|
|
int n;
|
|
|
|
z = Tcl_GetStringFromObj(pObj, &n);
|
|
if( n==0 ){
|
|
*ppBlob = 0;
|
|
}else{
|
|
int notUsed;
|
|
Tcl_Channel channel;
|
|
ClientData instanceData;
|
|
|
|
channel = Tcl_GetChannel(interp, z, ¬Used);
|
|
if( !channel ) return TCL_ERROR;
|
|
|
|
Tcl_Flush(channel);
|
|
Tcl_Seek(channel, 0, SEEK_SET);
|
|
|
|
instanceData = Tcl_GetChannelInstanceData(channel);
|
|
*ppBlob = *((sqlite3_blob **)instanceData);
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
static int test_blob_reopen(
|
|
ClientData clientData, /* Not used */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
Tcl_WideInt iRowid;
|
|
sqlite3_blob *pBlob;
|
|
int rc;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL ROWID");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( blobHandleFromObj(interp, objv[1], &pBlob) ) return TCL_ERROR;
|
|
if( Tcl_GetWideIntFromObj(interp, objv[2], &iRowid) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_blob_reopen(pBlob, iRowid);
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
|
|
}
|
|
|
|
return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
|
** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC
|
|
**
|
|
** This Tcl proc is used for testing the experimental
|
|
** sqlite3_create_collation_v2() interface.
|
|
*/
|
|
struct TestCollationX {
|
|
Tcl_Interp *interp;
|
|
Tcl_Obj *pCmp;
|
|
Tcl_Obj *pDel;
|
|
};
|
|
typedef struct TestCollationX TestCollationX;
|
|
static void testCreateCollationDel(void *pCtx){
|
|
TestCollationX *p = (TestCollationX *)pCtx;
|
|
|
|
int rc = Tcl_EvalObjEx(p->interp, p->pDel, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL);
|
|
if( rc!=TCL_OK ){
|
|
Tcl_BackgroundError(p->interp);
|
|
}
|
|
|
|
Tcl_DecrRefCount(p->pCmp);
|
|
Tcl_DecrRefCount(p->pDel);
|
|
sqlite3_free((void *)p);
|
|
}
|
|
static int testCreateCollationCmp(
|
|
void *pCtx,
|
|
int nLeft,
|
|
const void *zLeft,
|
|
int nRight,
|
|
const void *zRight
|
|
){
|
|
TestCollationX *p = (TestCollationX *)pCtx;
|
|
Tcl_Obj *pScript = Tcl_DuplicateObj(p->pCmp);
|
|
int iRes = 0;
|
|
|
|
Tcl_IncrRefCount(pScript);
|
|
Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zLeft, nLeft));
|
|
Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zRight,nRight));
|
|
|
|
if( TCL_OK!=Tcl_EvalObjEx(p->interp, pScript, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL)
|
|
|| TCL_OK!=Tcl_GetIntFromObj(p->interp, Tcl_GetObjResult(p->interp), &iRes)
|
|
){
|
|
Tcl_BackgroundError(p->interp);
|
|
}
|
|
Tcl_DecrRefCount(pScript);
|
|
|
|
return iRes;
|
|
}
|
|
static int test_create_collation_v2(
|
|
ClientData clientData, /* Not used */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
TestCollationX *p;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=5 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE NAME CMP-PROC DEL-PROC");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
p = (TestCollationX *)sqlite3_malloc(sizeof(TestCollationX));
|
|
p->pCmp = objv[3];
|
|
p->pDel = objv[4];
|
|
p->interp = interp;
|
|
Tcl_IncrRefCount(p->pCmp);
|
|
Tcl_IncrRefCount(p->pDel);
|
|
|
|
rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), 16,
|
|
(void *)p, testCreateCollationCmp, testCreateCollationDel
|
|
);
|
|
if( rc!=SQLITE_MISUSE ){
|
|
Tcl_AppendResult(interp, "sqlite3_create_collate_v2() failed to detect "
|
|
"an invalid encoding", (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8,
|
|
(void *)p, testCreateCollationCmp, testCreateCollationDel
|
|
);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** USAGE: sqlite3_create_function_v2 DB NAME NARG ENC ?SWITCHES?
|
|
**
|
|
** Available switches are:
|
|
**
|
|
** -func SCRIPT
|
|
** -step SCRIPT
|
|
** -final SCRIPT
|
|
** -destroy SCRIPT
|
|
*/
|
|
typedef struct CreateFunctionV2 CreateFunctionV2;
|
|
struct CreateFunctionV2 {
|
|
Tcl_Interp *interp;
|
|
Tcl_Obj *pFunc; /* Script for function invocation */
|
|
Tcl_Obj *pStep; /* Script for agg. step invocation */
|
|
Tcl_Obj *pFinal; /* Script for agg. finalization invocation */
|
|
Tcl_Obj *pDestroy; /* Destructor script */
|
|
};
|
|
static void cf2Func(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){
|
|
}
|
|
static void cf2Step(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){
|
|
}
|
|
static void cf2Final(sqlite3_context *ctx){
|
|
}
|
|
static void cf2Destroy(void *pUser){
|
|
CreateFunctionV2 *p = (CreateFunctionV2 *)pUser;
|
|
|
|
if( p->interp && p->pDestroy ){
|
|
int rc = Tcl_EvalObjEx(p->interp, p->pDestroy, 0);
|
|
if( rc!=TCL_OK ) Tcl_BackgroundError(p->interp);
|
|
}
|
|
|
|
if( p->pFunc ) Tcl_DecrRefCount(p->pFunc);
|
|
if( p->pStep ) Tcl_DecrRefCount(p->pStep);
|
|
if( p->pFinal ) Tcl_DecrRefCount(p->pFinal);
|
|
if( p->pDestroy ) Tcl_DecrRefCount(p->pDestroy);
|
|
sqlite3_free(p);
|
|
}
|
|
static int test_create_function_v2(
|
|
ClientData clientData, /* Not used */
|
|
Tcl_Interp *interp, /* The invoking TCL interpreter */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
const char *zFunc;
|
|
int nArg;
|
|
int enc;
|
|
CreateFunctionV2 *p;
|
|
int i;
|
|
int rc;
|
|
|
|
struct EncTable {
|
|
const char *zEnc;
|
|
int enc;
|
|
} aEnc[] = {
|
|
{"utf8", SQLITE_UTF8 },
|
|
{"utf16", SQLITE_UTF16 },
|
|
{"utf16le", SQLITE_UTF16LE },
|
|
{"utf16be", SQLITE_UTF16BE },
|
|
{"any", SQLITE_ANY },
|
|
{"0", 0 }
|
|
};
|
|
|
|
if( objc<5 || (objc%2)==0 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB NAME NARG ENC SWITCHES...");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zFunc = Tcl_GetString(objv[2]);
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &nArg) ) return TCL_ERROR;
|
|
if( Tcl_GetIndexFromObjStruct(interp, objv[4], aEnc, sizeof(aEnc[0]),
|
|
"encoding", 0, &enc)
|
|
){
|
|
return TCL_ERROR;
|
|
}
|
|
enc = aEnc[enc].enc;
|
|
|
|
p = sqlite3_malloc(sizeof(CreateFunctionV2));
|
|
assert( p );
|
|
memset(p, 0, sizeof(CreateFunctionV2));
|
|
p->interp = interp;
|
|
|
|
for(i=5; i<objc; i+=2){
|
|
int iSwitch;
|
|
const char *azSwitch[] = {"-func", "-step", "-final", "-destroy", 0};
|
|
if( Tcl_GetIndexFromObj(interp, objv[i], azSwitch, "switch", 0, &iSwitch) ){
|
|
sqlite3_free(p);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
switch( iSwitch ){
|
|
case 0: p->pFunc = objv[i+1]; break;
|
|
case 1: p->pStep = objv[i+1]; break;
|
|
case 2: p->pFinal = objv[i+1]; break;
|
|
case 3: p->pDestroy = objv[i+1]; break;
|
|
}
|
|
}
|
|
if( p->pFunc ) p->pFunc = Tcl_DuplicateObj(p->pFunc);
|
|
if( p->pStep ) p->pStep = Tcl_DuplicateObj(p->pStep);
|
|
if( p->pFinal ) p->pFinal = Tcl_DuplicateObj(p->pFinal);
|
|
if( p->pDestroy ) p->pDestroy = Tcl_DuplicateObj(p->pDestroy);
|
|
|
|
if( p->pFunc ) Tcl_IncrRefCount(p->pFunc);
|
|
if( p->pStep ) Tcl_IncrRefCount(p->pStep);
|
|
if( p->pFinal ) Tcl_IncrRefCount(p->pFinal);
|
|
if( p->pDestroy ) Tcl_IncrRefCount(p->pDestroy);
|
|
|
|
rc = sqlite3_create_function_v2(db, zFunc, nArg, enc, (void *)p,
|
|
(p->pFunc ? cf2Func : 0),
|
|
(p->pStep ? cf2Step : 0),
|
|
(p->pFinal ? cf2Final : 0),
|
|
cf2Destroy
|
|
);
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_ResetResult(interp);
|
|
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?
|
|
*/
|
|
static int test_load_extension(
|
|
ClientData clientData, /* Not used */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
Tcl_CmdInfo cmdInfo;
|
|
sqlite3 *db;
|
|
int rc;
|
|
char *zDb;
|
|
char *zFile;
|
|
char *zProc = 0;
|
|
char *zErr = 0;
|
|
|
|
if( objc!=4 && objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE FILE ?PROC?");
|
|
return TCL_ERROR;
|
|
}
|
|
zDb = Tcl_GetString(objv[1]);
|
|
zFile = Tcl_GetString(objv[2]);
|
|
if( objc==4 ){
|
|
zProc = Tcl_GetString(objv[3]);
|
|
}
|
|
|
|
/* Extract the C database handle from the Tcl command name */
|
|
if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
|
|
Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
|
|
assert(db);
|
|
|
|
/* Call the underlying C function. If an error occurs, set rc to
|
|
** TCL_ERROR and load any error string into the interpreter. If no
|
|
** error occurs, set rc to TCL_OK.
|
|
*/
|
|
#ifdef SQLITE_OMIT_LOAD_EXTENSION
|
|
rc = SQLITE_ERROR;
|
|
zErr = sqlite3_mprintf("this build omits sqlite3_load_extension()");
|
|
#else
|
|
rc = sqlite3_load_extension(db, zFile, zProc, &zErr);
|
|
#endif
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_SetResult(interp, zErr ? zErr : "", TCL_VOLATILE);
|
|
rc = TCL_ERROR;
|
|
}else{
|
|
rc = TCL_OK;
|
|
}
|
|
sqlite3_free(zErr);
|
|
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF
|
|
*/
|
|
static int test_enable_load(
|
|
ClientData clientData, /* Not used */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
Tcl_CmdInfo cmdInfo;
|
|
sqlite3 *db;
|
|
char *zDb;
|
|
int onoff;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE ONOFF");
|
|
return TCL_ERROR;
|
|
}
|
|
zDb = Tcl_GetString(objv[1]);
|
|
|
|
/* Extract the C database handle from the Tcl command name */
|
|
if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
|
|
Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
|
|
assert(db);
|
|
|
|
/* Get the onoff parameter */
|
|
if( Tcl_GetBooleanFromObj(interp, objv[2], &onoff) ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
#ifdef SQLITE_OMIT_LOAD_EXTENSION
|
|
Tcl_AppendResult(interp, "this build omits sqlite3_load_extension()");
|
|
return TCL_ERROR;
|
|
#else
|
|
sqlite3_enable_load_extension(db, onoff);
|
|
return TCL_OK;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite_abort
|
|
**
|
|
** Shutdown the process immediately. This is not a clean shutdown.
|
|
** This command is used to test the recoverability of a database in
|
|
** the event of a program crash.
|
|
*/
|
|
static int sqlite_abort(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
#if defined(_MSC_VER)
|
|
/* We do this, otherwise the test will halt with a popup message
|
|
* that we have to click away before the test will continue.
|
|
*/
|
|
_set_abort_behavior( 0, _CALL_REPORTFAULT );
|
|
#endif
|
|
exit(255);
|
|
assert( interp==0 ); /* This will always fail */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** The following routine is a user-defined SQL function whose purpose
|
|
** is to test the sqlite_set_result() API.
|
|
*/
|
|
static void testFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|
while( argc>=2 ){
|
|
const char *zArg0 = (char*)sqlite3_value_text(argv[0]);
|
|
if( zArg0 ){
|
|
if( 0==sqlite3StrICmp(zArg0, "int") ){
|
|
sqlite3_result_int(context, sqlite3_value_int(argv[1]));
|
|
}else if( sqlite3StrICmp(zArg0,"int64")==0 ){
|
|
sqlite3_result_int64(context, sqlite3_value_int64(argv[1]));
|
|
}else if( sqlite3StrICmp(zArg0,"string")==0 ){
|
|
sqlite3_result_text(context, (char*)sqlite3_value_text(argv[1]), -1,
|
|
SQLITE_TRANSIENT);
|
|
}else if( sqlite3StrICmp(zArg0,"double")==0 ){
|
|
sqlite3_result_double(context, sqlite3_value_double(argv[1]));
|
|
}else if( sqlite3StrICmp(zArg0,"null")==0 ){
|
|
sqlite3_result_null(context);
|
|
}else if( sqlite3StrICmp(zArg0,"value")==0 ){
|
|
sqlite3_result_value(context, argv[sqlite3_value_int(argv[1])]);
|
|
}else{
|
|
goto error_out;
|
|
}
|
|
}else{
|
|
goto error_out;
|
|
}
|
|
argc -= 2;
|
|
argv += 2;
|
|
}
|
|
return;
|
|
|
|
error_out:
|
|
sqlite3_result_error(context,"first argument should be one of: "
|
|
"int int64 string double null value", -1);
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite_register_test_function DB NAME
|
|
**
|
|
** Register the test SQL function on the database DB under the name NAME.
|
|
*/
|
|
static int test_register_func(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB FUNCTION-NAME", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0,
|
|
testFunc, 0, 0);
|
|
if( rc!=0 ){
|
|
Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_finalize STMT
|
|
**
|
|
** Finalize a statement handle.
|
|
*/
|
|
static int test_finalize(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int rc;
|
|
sqlite3 *db = 0;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( pStmt ){
|
|
db = StmtToDb(pStmt);
|
|
}
|
|
rc = sqlite3_finalize(pStmt);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
if( db && sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_stmt_status STMT CODE RESETFLAG
|
|
**
|
|
** Get the value of a status counter from a statement.
|
|
*/
|
|
static int test_stmt_status(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int iValue;
|
|
int i, op = 0, resetFlag;
|
|
const char *zOpName;
|
|
sqlite3_stmt *pStmt;
|
|
|
|
static const struct {
|
|
const char *zName;
|
|
int op;
|
|
} aOp[] = {
|
|
{ "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP },
|
|
{ "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT },
|
|
{ "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX },
|
|
{ "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP },
|
|
};
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT PARAMETER RESETFLAG");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
zOpName = Tcl_GetString(objv[2]);
|
|
for(i=0; i<ArraySize(aOp); i++){
|
|
if( strcmp(aOp[i].zName, zOpName)==0 ){
|
|
op = aOp[i].op;
|
|
break;
|
|
}
|
|
}
|
|
if( i>=ArraySize(aOp) ){
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &op) ) return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetBooleanFromObj(interp, objv[3], &resetFlag) ) return TCL_ERROR;
|
|
iValue = sqlite3_stmt_status(pStmt, op, resetFlag);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(iValue));
|
|
return TCL_OK;
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
|
/*
|
|
** Usage: sqlite3_stmt_scanstatus STMT IDX
|
|
*/
|
|
static int test_stmt_scanstatus(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt; /* First argument */
|
|
int idx; /* Second argument */
|
|
|
|
const char *zName;
|
|
const char *zExplain;
|
|
sqlite3_int64 nLoop;
|
|
sqlite3_int64 nVisit;
|
|
double rEst;
|
|
int res;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
res = sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop);
|
|
if( res==0 ){
|
|
Tcl_Obj *pRet = Tcl_NewObj();
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("nLoop", -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewWideIntObj(nLoop));
|
|
sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("nVisit", -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewWideIntObj(nVisit));
|
|
sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_EST, (void*)&rEst);
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("nEst", -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewDoubleObj(rEst));
|
|
sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_NAME, (void*)&zName);
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("zName", -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zName, -1));
|
|
sqlite3_stmt_scanstatus(pStmt, idx, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj("zExplain", -1));
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zExplain, -1));
|
|
Tcl_SetObjResult(interp, pRet);
|
|
}else{
|
|
Tcl_ResetResult(interp);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_stmt_scanstatus_reset STMT
|
|
*/
|
|
static int test_stmt_scanstatus_reset(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt; /* First argument */
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
sqlite3_stmt_scanstatus_reset(pStmt);
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
/*
|
|
** Usage: sqlite3_config_sqllog
|
|
**
|
|
** Zero the SQLITE_CONFIG_SQLLOG configuration
|
|
*/
|
|
static int test_config_sqllog(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
if( objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "");
|
|
return TCL_ERROR;
|
|
}
|
|
sqlite3_config(SQLITE_CONFIG_SQLLOG, 0, 0);
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** Usage: vfs_current_time_int64
|
|
**
|
|
** Return the value returned by the default VFS's xCurrentTimeInt64 method.
|
|
*/
|
|
static int vfsCurrentTimeInt64(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
i64 t;
|
|
sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
|
|
if( objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "");
|
|
return TCL_ERROR;
|
|
}
|
|
pVfs->xCurrentTimeInt64(pVfs, &t);
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(t));
|
|
return TCL_OK;
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
/*
|
|
** Usage: sqlite3_snapshot_get DB DBNAME
|
|
*/
|
|
static int test_snapshot_get(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int rc;
|
|
sqlite3 *db;
|
|
char *zName;
|
|
sqlite3_snapshot *pSnapshot = 0;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zName = Tcl_GetString(objv[2]);
|
|
|
|
rc = sqlite3_snapshot_get(db, zName, &pSnapshot);
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
|
|
return TCL_ERROR;
|
|
}else{
|
|
char zBuf[100];
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pSnapshot) ) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(zBuf, -1));
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_ENABLE_SNAPSHOT */
|
|
|
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
/*
|
|
** Usage: sqlite3_snapshot_open DB DBNAME SNAPSHOT
|
|
*/
|
|
static int test_snapshot_open(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int rc;
|
|
sqlite3 *db;
|
|
char *zName;
|
|
sqlite3_snapshot *pSnapshot;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SNAPSHOT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zName = Tcl_GetString(objv[2]);
|
|
pSnapshot = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[3]));
|
|
|
|
rc = sqlite3_snapshot_open(db, zName, pSnapshot);
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_ENABLE_SNAPSHOT */
|
|
|
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
/*
|
|
** Usage: sqlite3_snapshot_free SNAPSHOT
|
|
*/
|
|
static int test_snapshot_free(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_snapshot *pSnapshot;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "SNAPSHOT");
|
|
return TCL_ERROR;
|
|
}
|
|
pSnapshot = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
|
|
sqlite3_snapshot_free(pSnapshot);
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_ENABLE_SNAPSHOT */
|
|
|
|
/*
|
|
** Usage: sqlite3_next_stmt DB STMT
|
|
**
|
|
** Return the next statment in sequence after STMT.
|
|
*/
|
|
static int test_next_stmt(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
sqlite3 *db = 0;
|
|
char zBuf[50];
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB STMT", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt) ) return TCL_ERROR;
|
|
pStmt = sqlite3_next_stmt(db, pStmt);
|
|
if( pStmt ){
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_stmt_readonly STMT
|
|
**
|
|
** Return true if STMT is a NULL pointer or a pointer to a statement
|
|
** that is guaranteed to leave the database unmodified.
|
|
*/
|
|
static int test_stmt_readonly(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
rc = sqlite3_stmt_readonly(pStmt);
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_stmt_busy STMT
|
|
**
|
|
** Return true if STMT is a non-NULL pointer to a statement
|
|
** that has been stepped but not to completion.
|
|
*/
|
|
static int test_stmt_busy(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
rc = sqlite3_stmt_busy(pStmt);
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: uses_stmt_journal STMT
|
|
**
|
|
** Return true if STMT uses a statement journal.
|
|
*/
|
|
static int uses_stmt_journal(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
sqlite3_stmt_readonly(pStmt);
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(((Vdbe *)pStmt)->usesStmtJournal));
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_reset STMT
|
|
**
|
|
** Reset a statement handle.
|
|
*/
|
|
static int test_reset(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_reset(pStmt);
|
|
if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
/*
|
|
if( rc ){
|
|
return TCL_ERROR;
|
|
}
|
|
*/
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_expired STMT
|
|
**
|
|
** Return TRUE if a recompilation of the statement is recommended.
|
|
*/
|
|
static int test_expired(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
sqlite3_stmt *pStmt;
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt)));
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
|
|
**
|
|
** Transfer all bindings from FROMSTMT over to TOSTMT
|
|
*/
|
|
static int test_transfer_bind(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
sqlite3_stmt *pStmt1, *pStmt2;
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR;
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp,
|
|
Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2)));
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_changes DB
|
|
**
|
|
** Return the number of changes made to the database by the last SQL
|
|
** execution.
|
|
*/
|
|
static int test_changes(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
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;
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_changes(db)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** This is the "static_bind_value" that variables are bound to when
|
|
** the FLAG option of sqlite3_bind is "static"
|
|
*/
|
|
static char *sqlite_static_bind_value = 0;
|
|
static int sqlite_static_bind_nbyte = 0;
|
|
|
|
/*
|
|
** Usage: sqlite3_bind VM IDX VALUE FLAGS
|
|
**
|
|
** Sets the value of the IDX-th occurrence of "?" in the original SQL
|
|
** string. VALUE is the new value. If FLAGS=="null" then VALUE is
|
|
** ignored and the value is set to NULL. If FLAGS=="static" then
|
|
** the value is set to the value of a static variable named
|
|
** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
|
|
** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
|
|
** an a 10-byte blob "abc\000xyz\000pq" is inserted.
|
|
*/
|
|
static int test_bind(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int rc;
|
|
int idx;
|
|
if( argc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" VM IDX VALUE (null|static|normal)\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR;
|
|
if( strcmp(argv[4],"null")==0 ){
|
|
rc = sqlite3_bind_null(pStmt, idx);
|
|
}else if( strcmp(argv[4],"static")==0 ){
|
|
rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0);
|
|
}else if( strcmp(argv[4],"static-nbytes")==0 ){
|
|
rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value,
|
|
sqlite_static_bind_nbyte, 0);
|
|
}else if( strcmp(argv[4],"normal")==0 ){
|
|
rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT);
|
|
}else if( strcmp(argv[4],"blob10")==0 ){
|
|
rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC);
|
|
}else{
|
|
Tcl_AppendResult(interp, "4th argument should be "
|
|
"\"null\" or \"static\" or \"normal\"", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc ){
|
|
char zBuf[50];
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc);
|
|
Tcl_AppendResult(interp, zBuf, sqlite3ErrStr(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/*
|
|
** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>
|
|
**
|
|
** This function is used to test that SQLite selects the correct collation
|
|
** sequence callback when multiple versions (for different text encodings)
|
|
** are available.
|
|
**
|
|
** Calling this routine registers the collation sequence "test_collate"
|
|
** with database handle <db>. The second argument must be a list of three
|
|
** boolean values. If the first is true, then a version of test_collate is
|
|
** registered for UTF-8, if the second is true, a version is registered for
|
|
** UTF-16le, if the third is true, a UTF-16be version is available.
|
|
** Previous versions of test_collate are deleted.
|
|
**
|
|
** The collation sequence test_collate is implemented by calling the
|
|
** following TCL script:
|
|
**
|
|
** "test_collate <enc> <lhs> <rhs>"
|
|
**
|
|
** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.
|
|
** The <enc> parameter is the encoding of the collation function that
|
|
** SQLite selected to call. The TCL test script implements the
|
|
** "test_collate" proc.
|
|
**
|
|
** Note that this will only work with one interpreter at a time, as the
|
|
** interp pointer to use when evaluating the TCL script is stored in
|
|
** pTestCollateInterp.
|
|
*/
|
|
static Tcl_Interp* pTestCollateInterp;
|
|
static int test_collate_func(
|
|
void *pCtx,
|
|
int nA, const void *zA,
|
|
int nB, const void *zB
|
|
){
|
|
Tcl_Interp *i = pTestCollateInterp;
|
|
int encin = SQLITE_PTR_TO_INT(pCtx);
|
|
int res;
|
|
int n;
|
|
|
|
sqlite3_value *pVal;
|
|
Tcl_Obj *pX;
|
|
|
|
pX = Tcl_NewStringObj("test_collate", -1);
|
|
Tcl_IncrRefCount(pX);
|
|
|
|
switch( encin ){
|
|
case SQLITE_UTF8:
|
|
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-8",-1));
|
|
break;
|
|
case SQLITE_UTF16LE:
|
|
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16LE",-1));
|
|
break;
|
|
case SQLITE_UTF16BE:
|
|
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16BE",-1));
|
|
break;
|
|
default:
|
|
assert(0);
|
|
}
|
|
|
|
sqlite3BeginBenignMalloc();
|
|
pVal = sqlite3ValueNew(0);
|
|
if( pVal ){
|
|
sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC);
|
|
n = sqlite3_value_bytes(pVal);
|
|
Tcl_ListObjAppendElement(i,pX,
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n));
|
|
sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC);
|
|
n = sqlite3_value_bytes(pVal);
|
|
Tcl_ListObjAppendElement(i,pX,
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n));
|
|
sqlite3ValueFree(pVal);
|
|
}
|
|
sqlite3EndBenignMalloc();
|
|
|
|
Tcl_EvalObjEx(i, pX, 0);
|
|
Tcl_DecrRefCount(pX);
|
|
Tcl_GetIntFromObj(i, Tcl_GetObjResult(i), &res);
|
|
return res;
|
|
}
|
|
static int test_collate(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int val;
|
|
sqlite3_value *pVal;
|
|
int rc;
|
|
|
|
if( objc!=5 ) goto bad_args;
|
|
pTestCollateInterp = interp;
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
|
rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF8,
|
|
(void *)SQLITE_UTF8, val?test_collate_func:0);
|
|
if( rc==SQLITE_OK ){
|
|
const void *zUtf16;
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR;
|
|
rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE,
|
|
(void *)SQLITE_UTF16LE, val?test_collate_func:0);
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR;
|
|
|
|
#if 0
|
|
if( sqlite3_iMallocFail>0 ){
|
|
sqlite3_iMallocFail++;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pVal = sqlite3ValueNew(db);
|
|
sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC);
|
|
zUtf16 = sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
|
|
if( db->mallocFailed ){
|
|
rc = SQLITE_NOMEM;
|
|
}else{
|
|
rc = sqlite3_create_collation16(db, zUtf16, SQLITE_UTF16BE,
|
|
(void *)SQLITE_UTF16BE, val?test_collate_func:0);
|
|
}
|
|
sqlite3ValueFree(pVal);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
}
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
|
|
bad_args:
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
/*
|
|
** Usage: add_test_utf16bin_collate <db ptr>
|
|
**
|
|
** Add a utf-16 collation sequence named "utf16bin" to the database
|
|
** handle. This collation sequence compares arguments in the same way as the
|
|
** built-in collation "binary".
|
|
*/
|
|
static int test_utf16bin_collate_func(
|
|
void *pCtx,
|
|
int nA, const void *zA,
|
|
int nB, const void *zB
|
|
){
|
|
int nCmp = (nA>nB ? nB : nA);
|
|
int res = memcmp(zA, zB, nCmp);
|
|
if( res==0 ) res = nA - nB;
|
|
return res;
|
|
}
|
|
static int test_utf16bin_collate(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=2 ) goto bad_args;
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_create_collation(db, "utf16bin", SQLITE_UTF16, 0,
|
|
test_utf16bin_collate_func
|
|
);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
|
|
bad_args:
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
/*
|
|
** When the collation needed callback is invoked, record the name of
|
|
** the requested collating function here. The recorded name is linked
|
|
** to a TCL variable and used to make sure that the requested collation
|
|
** name is correct.
|
|
*/
|
|
static char zNeededCollation[200];
|
|
static char *pzNeededCollation = zNeededCollation;
|
|
|
|
|
|
/*
|
|
** Called when a collating sequence is needed. Registered using
|
|
** sqlite3_collation_needed16().
|
|
*/
|
|
static void test_collate_needed_cb(
|
|
void *pCtx,
|
|
sqlite3 *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;
|
|
sqlite3_create_collation(
|
|
db, "test_collate", ENC(db), SQLITE_INT_TO_PTR(enc), test_collate_func);
|
|
}
|
|
|
|
/*
|
|
** Usage: add_test_collate_needed DB
|
|
*/
|
|
static int test_collate_needed(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=2 ) goto bad_args;
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb);
|
|
zNeededCollation[0] = 0;
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
|
|
bad_args:
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: add_alignment_test_collations DB
|
|
**
|
|
** Add two new collating sequences to the database DB
|
|
**
|
|
** utf16_aligned
|
|
** utf16_unaligned
|
|
**
|
|
** Both collating sequences use the same sort order as BINARY.
|
|
** The only difference is that the utf16_aligned collating
|
|
** sequence is declared with the SQLITE_UTF16_ALIGNED flag.
|
|
** Both collating functions increment the unaligned utf16 counter
|
|
** whenever they see a string that begins on an odd byte boundary.
|
|
*/
|
|
static int unaligned_string_counter = 0;
|
|
static int alignmentCollFunc(
|
|
void *NotUsed,
|
|
int nKey1, const void *pKey1,
|
|
int nKey2, const void *pKey2
|
|
){
|
|
int rc, n;
|
|
n = nKey1<nKey2 ? nKey1 : nKey2;
|
|
if( nKey1>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey1))) ) unaligned_string_counter++;
|
|
if( nKey2>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey2))) ) unaligned_string_counter++;
|
|
rc = memcmp(pKey1, pKey2, n);
|
|
if( rc==0 ){
|
|
rc = nKey1 - nKey2;
|
|
}
|
|
return rc;
|
|
}
|
|
static int add_alignment_test_collations(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
if( objc>=2 ){
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
sqlite3_create_collation(db, "utf16_unaligned", SQLITE_UTF16,
|
|
0, alignmentCollFunc);
|
|
sqlite3_create_collation(db, "utf16_aligned", SQLITE_UTF16_ALIGNED,
|
|
0, alignmentCollFunc);
|
|
}
|
|
return SQLITE_OK;
|
|
}
|
|
#endif /* !defined(SQLITE_OMIT_UTF16) */
|
|
|
|
/*
|
|
** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
|
|
**
|
|
** This function is used to test that SQLite selects the correct user
|
|
** function callback when multiple versions (for different text encodings)
|
|
** are available.
|
|
**
|
|
** Calling this routine registers up to three versions of the user function
|
|
** "test_function" with database handle <db>. If the second argument is
|
|
** true, then a version of test_function is registered for UTF-8, if the
|
|
** third is true, a version is registered for UTF-16le, if the fourth is
|
|
** true, a UTF-16be version is available. Previous versions of
|
|
** test_function are deleted.
|
|
**
|
|
** The user function is implemented by calling the following TCL script:
|
|
**
|
|
** "test_function <enc> <arg>"
|
|
**
|
|
** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the
|
|
** single argument passed to the SQL function. The value returned by
|
|
** the TCL script is used as the return value of the SQL function. It
|
|
** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8
|
|
** for a UTF-16LE test_function(), and UTF-16LE for an implementation that
|
|
** prefers UTF-16BE.
|
|
*/
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
static void test_function_utf8(
|
|
sqlite3_context *pCtx,
|
|
int nArg,
|
|
sqlite3_value **argv
|
|
){
|
|
Tcl_Interp *interp;
|
|
Tcl_Obj *pX;
|
|
sqlite3_value *pVal;
|
|
interp = (Tcl_Interp *)sqlite3_user_data(pCtx);
|
|
pX = Tcl_NewStringObj("test_function", -1);
|
|
Tcl_IncrRefCount(pX);
|
|
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1));
|
|
Tcl_ListObjAppendElement(interp, pX,
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
|
Tcl_EvalObjEx(interp, pX, 0);
|
|
Tcl_DecrRefCount(pX);
|
|
sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT);
|
|
pVal = sqlite3ValueNew(0);
|
|
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
|
SQLITE_UTF8, SQLITE_STATIC);
|
|
sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal),
|
|
-1, SQLITE_TRANSIENT);
|
|
sqlite3ValueFree(pVal);
|
|
}
|
|
static void test_function_utf16le(
|
|
sqlite3_context *pCtx,
|
|
int nArg,
|
|
sqlite3_value **argv
|
|
){
|
|
Tcl_Interp *interp;
|
|
Tcl_Obj *pX;
|
|
sqlite3_value *pVal;
|
|
interp = (Tcl_Interp *)sqlite3_user_data(pCtx);
|
|
pX = Tcl_NewStringObj("test_function", -1);
|
|
Tcl_IncrRefCount(pX);
|
|
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1));
|
|
Tcl_ListObjAppendElement(interp, pX,
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
|
Tcl_EvalObjEx(interp, pX, 0);
|
|
Tcl_DecrRefCount(pX);
|
|
pVal = sqlite3ValueNew(0);
|
|
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
|
SQLITE_UTF8, SQLITE_STATIC);
|
|
sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT);
|
|
sqlite3ValueFree(pVal);
|
|
}
|
|
static void test_function_utf16be(
|
|
sqlite3_context *pCtx,
|
|
int nArg,
|
|
sqlite3_value **argv
|
|
){
|
|
Tcl_Interp *interp;
|
|
Tcl_Obj *pX;
|
|
sqlite3_value *pVal;
|
|
interp = (Tcl_Interp *)sqlite3_user_data(pCtx);
|
|
pX = Tcl_NewStringObj("test_function", -1);
|
|
Tcl_IncrRefCount(pX);
|
|
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1));
|
|
Tcl_ListObjAppendElement(interp, pX,
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
|
Tcl_EvalObjEx(interp, pX, 0);
|
|
Tcl_DecrRefCount(pX);
|
|
pVal = sqlite3ValueNew(0);
|
|
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
|
SQLITE_UTF8, SQLITE_STATIC);
|
|
sqlite3_result_text16(pCtx, sqlite3_value_text16le(pVal),
|
|
-1, SQLITE_TRANSIENT);
|
|
sqlite3_result_text16be(pCtx, sqlite3_value_text16le(pVal),
|
|
-1, SQLITE_TRANSIENT);
|
|
sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal),
|
|
-1, SQLITE_TRANSIENT);
|
|
sqlite3ValueFree(pVal);
|
|
}
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
static int test_function(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
sqlite3 *db;
|
|
int val;
|
|
|
|
if( objc!=5 ) goto bad_args;
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
|
if( val ){
|
|
sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8,
|
|
interp, test_function_utf8, 0, 0);
|
|
}
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR;
|
|
if( val ){
|
|
sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE,
|
|
interp, test_function_utf16le, 0, 0);
|
|
}
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR;
|
|
if( val ){
|
|
sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE,
|
|
interp, test_function_utf16be, 0, 0);
|
|
}
|
|
|
|
return TCL_OK;
|
|
bad_args:
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_test_errstr <err code>
|
|
**
|
|
** Test that the english language string equivalents for sqlite error codes
|
|
** are sane. The parameter is an integer representing an sqlite error code.
|
|
** The result is a list of two elements, the string representation of the
|
|
** error code and the english language explanation.
|
|
*/
|
|
static int test_errstr(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
char *zCode;
|
|
int i;
|
|
if( objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "<error code>");
|
|
}
|
|
|
|
zCode = Tcl_GetString(objv[1]);
|
|
for(i=0; i<200; i++){
|
|
if( 0==strcmp(t1ErrorName(i), zCode) ) break;
|
|
}
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: breakpoint
|
|
**
|
|
** This routine exists for one purpose - to provide a place to put a
|
|
** breakpoint with GDB that can be triggered using TCL code. The use
|
|
** for this is when a particular test fails on (say) the 1485th iteration.
|
|
** In the TCL test script, we can add code like this:
|
|
**
|
|
** if {$i==1485} breakpoint
|
|
**
|
|
** Then run testfixture in the debugger and wait for the breakpoint to
|
|
** fire. Then additional breakpoints can be set to trace down the bug.
|
|
*/
|
|
static int test_breakpoint(
|
|
void *NotUsed,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int argc, /* Number of arguments */
|
|
char **argv /* Text of each argument */
|
|
){
|
|
return TCL_OK; /* Do nothing */
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_zeroblob STMT IDX N
|
|
**
|
|
** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement.
|
|
** IDX is the index of a wildcard in the prepared statement. This command
|
|
** binds a N-byte zero-filled BLOB to the wildcard.
|
|
*/
|
|
static int test_bind_zeroblob(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
int n;
|
|
int rc;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX N");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &n) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_zeroblob(pStmt, idx, n);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_zeroblob64 STMT IDX N
|
|
**
|
|
** Test the sqlite3_bind_zeroblob64 interface. STMT is a prepared statement.
|
|
** IDX is the index of a wildcard in the prepared statement. This command
|
|
** binds a N-byte zero-filled BLOB to the wildcard.
|
|
*/
|
|
static int test_bind_zeroblob64(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
i64 n;
|
|
int rc;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT IDX N");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
if( Tcl_GetWideIntFromObj(interp, objv[3], &n) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_zeroblob64(pStmt, idx, n);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_int STMT N VALUE
|
|
**
|
|
** Test the sqlite3_bind_int interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a 32-bit integer VALUE to that wildcard.
|
|
*/
|
|
static int test_bind_int(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
int value;
|
|
int rc;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &value) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_int(pStmt, idx, value);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_int64 STMT N VALUE
|
|
**
|
|
** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a 64-bit integer VALUE to that wildcard.
|
|
*/
|
|
static int test_bind_int64(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
Tcl_WideInt value;
|
|
int rc;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
if( Tcl_GetWideIntFromObj(interp, objv[3], &value) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_int64(pStmt, idx, value);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_double STMT N VALUE
|
|
**
|
|
** Test the sqlite3_bind_double interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a 64-bit integer VALUE to that wildcard.
|
|
*/
|
|
static int test_bind_double(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
double value = 0;
|
|
int rc;
|
|
const char *zVal;
|
|
int i;
|
|
static const struct {
|
|
const char *zName; /* Name of the special floating point value */
|
|
unsigned int iUpper; /* Upper 32 bits */
|
|
unsigned int iLower; /* Lower 32 bits */
|
|
} aSpecialFp[] = {
|
|
{ "NaN", 0x7fffffff, 0xffffffff },
|
|
{ "SNaN", 0x7ff7ffff, 0xffffffff },
|
|
{ "-NaN", 0xffffffff, 0xffffffff },
|
|
{ "-SNaN", 0xfff7ffff, 0xffffffff },
|
|
{ "+Inf", 0x7ff00000, 0x00000000 },
|
|
{ "-Inf", 0xfff00000, 0x00000000 },
|
|
{ "Epsilon", 0x00000000, 0x00000001 },
|
|
{ "-Epsilon", 0x80000000, 0x00000001 },
|
|
{ "NaN0", 0x7ff80000, 0x00000000 },
|
|
{ "-NaN0", 0xfff80000, 0x00000000 },
|
|
};
|
|
|
|
if( objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
/* Intercept the string "NaN" and generate a NaN value for it.
|
|
** All other strings are passed through to Tcl_GetDoubleFromObj().
|
|
** Tcl_GetDoubleFromObj() should understand "NaN" but some versions
|
|
** contain a bug.
|
|
*/
|
|
zVal = Tcl_GetString(objv[3]);
|
|
for(i=0; i<sizeof(aSpecialFp)/sizeof(aSpecialFp[0]); i++){
|
|
if( strcmp(aSpecialFp[i].zName, zVal)==0 ){
|
|
sqlite3_uint64 x;
|
|
x = aSpecialFp[i].iUpper;
|
|
x <<= 32;
|
|
x |= aSpecialFp[i].iLower;
|
|
assert( sizeof(value)==8 );
|
|
assert( sizeof(x)==8 );
|
|
memcpy(&value, &x, 8);
|
|
break;
|
|
}
|
|
}
|
|
if( i>=sizeof(aSpecialFp)/sizeof(aSpecialFp[0]) &&
|
|
Tcl_GetDoubleFromObj(interp, objv[3], &value) ){
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_bind_double(pStmt, idx, value);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_null STMT N
|
|
**
|
|
** Test the sqlite3_bind_null interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a NULL to the wildcard.
|
|
*/
|
|
static int test_bind_null(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
int rc;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_null(pStmt, idx);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_text STMT N STRING BYTES
|
|
**
|
|
** Test the sqlite3_bind_text interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes
|
|
** long.
|
|
*/
|
|
static int test_bind_text(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
int bytes;
|
|
char *value;
|
|
int rc;
|
|
|
|
if( objc!=5 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
value = (char*)Tcl_GetByteArrayFromObj(objv[3], &bytes);
|
|
if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES
|
|
**
|
|
** Test the sqlite3_bind_text16 interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes
|
|
** long.
|
|
*/
|
|
static int test_bind_text16(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
int bytes;
|
|
char *value;
|
|
int rc;
|
|
|
|
void (*xDel)(void*) = (objc==6?SQLITE_STATIC:SQLITE_TRANSIENT);
|
|
Tcl_Obj *oStmt = objv[objc-4];
|
|
Tcl_Obj *oN = objv[objc-3];
|
|
Tcl_Obj *oString = objv[objc-2];
|
|
Tcl_Obj *oBytes = objv[objc-1];
|
|
|
|
if( objc!=5 && objc!=6){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(oStmt), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR;
|
|
value = (char*)Tcl_GetByteArrayFromObj(oString, 0);
|
|
if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES
|
|
**
|
|
** Test the sqlite3_bind_blob interface. STMT is a prepared statement.
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size.
|
|
*/
|
|
static int test_bind_blob(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int idx;
|
|
int bytes;
|
|
char *value;
|
|
int rc;
|
|
sqlite3_destructor_type xDestructor = SQLITE_TRANSIENT;
|
|
|
|
if( objc!=5 && objc!=6 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N DATA BYTES", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( objc==6 ){
|
|
xDestructor = SQLITE_STATIC;
|
|
objv++;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
value = Tcl_GetString(objv[3]);
|
|
if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_bind_blob(pStmt, idx, value, bytes, xDestructor);
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_parameter_count STMT
|
|
**
|
|
** Return the number of wildcards in the given statement.
|
|
*/
|
|
static int test_bind_parameter_count(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_parameter_name STMT N
|
|
**
|
|
** Return the name of the Nth wildcard. The first wildcard is 1.
|
|
** An empty string is returned if N is out of range or if the wildcard
|
|
** is nameless.
|
|
*/
|
|
static int test_bind_parameter_name(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int i;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT N");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &i) ) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp,
|
|
Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt,i),-1)
|
|
);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_bind_parameter_index STMT NAME
|
|
**
|
|
** Return the index of the wildcard called NAME. Return 0 if there is
|
|
** no such wildcard.
|
|
*/
|
|
static int test_bind_parameter_index(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT NAME");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp,
|
|
Tcl_NewIntObj(
|
|
sqlite3_bind_parameter_index(pStmt,Tcl_GetString(objv[2]))
|
|
)
|
|
);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_clear_bindings STMT
|
|
**
|
|
*/
|
|
static int test_clear_bindings(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_sleep MILLISECONDS
|
|
*/
|
|
static int test_sleep(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int ms;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "MILLISECONDS");
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[1], &ms) ){
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_sleep(ms)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_extended_errcode DB
|
|
**
|
|
** Return the string representation of the most recent sqlite3_* API
|
|
** error code. e.g. "SQLITE_ERROR".
|
|
*/
|
|
static int test_ex_errcode(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
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;
|
|
rc = sqlite3_extended_errcode(db);
|
|
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_errcode DB
|
|
**
|
|
** Return the string representation of the most recent sqlite3_* API
|
|
** error code. e.g. "SQLITE_ERROR".
|
|
*/
|
|
static int test_errcode(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
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;
|
|
rc = sqlite3_errcode(db);
|
|
Tcl_AppendResult(interp, (char *)t1ErrorName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_errmsg DB
|
|
**
|
|
** Returns the UTF-8 representation of the error message string for the
|
|
** most recent sqlite3_* API call.
|
|
*/
|
|
static int test_errmsg(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
const char *zErr;
|
|
|
|
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 = sqlite3_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 sqlite3_* 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 SQLITE_OMIT_UTF16
|
|
sqlite3 *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 = sqlite3_errmsg16(db);
|
|
if( zErr ){
|
|
z = zErr;
|
|
for(bytes=0; z[bytes] || z[bytes+1]; bytes+=2){}
|
|
}
|
|
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes));
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_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.
|
|
*/
|
|
static int test_prepare(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
const char *zSql;
|
|
int bytes;
|
|
const char *zTail = 0;
|
|
sqlite3_stmt *pStmt = 0;
|
|
char zBuf[50];
|
|
int rc;
|
|
|
|
if( objc!=5 && objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " DB sql bytes ?tailvar?", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zSql = Tcl_GetString(objv[2]);
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_prepare(db, zSql, bytes, &pStmt, objc>=5 ? &zTail : 0);
|
|
Tcl_ResetResult(interp);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
if( zTail && objc>=5 ){
|
|
if( bytes>=0 ){
|
|
bytes = bytes - (int)(zTail-zSql);
|
|
}
|
|
if( (int)strlen(zTail)<bytes ){
|
|
bytes = (int)strlen(zTail);
|
|
}
|
|
Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
|
|
}
|
|
if( rc!=SQLITE_OK ){
|
|
assert( pStmt==0 );
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc);
|
|
Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( pStmt ){
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_prepare_v2 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.
|
|
*/
|
|
static int test_prepare_v2(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
const char *zSql;
|
|
char *zCopy = 0; /* malloc() copy of zSql */
|
|
int bytes;
|
|
const char *zTail = 0;
|
|
sqlite3_stmt *pStmt = 0;
|
|
char zBuf[50];
|
|
int rc;
|
|
|
|
if( objc!=5 && objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zSql = Tcl_GetString(objv[2]);
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
|
|
|
|
/* Instead of using zSql directly, make a copy into a buffer obtained
|
|
** directly from malloc(). The idea is to make it easier for valgrind
|
|
** to spot buffer overreads. */
|
|
if( bytes>=0 ){
|
|
zCopy = malloc(bytes);
|
|
memcpy(zCopy, zSql, bytes);
|
|
}else{
|
|
int n = (int)strlen(zSql) + 1;
|
|
zCopy = malloc(n);
|
|
memcpy(zCopy, zSql, n);
|
|
}
|
|
rc = sqlite3_prepare_v2(db, zCopy, bytes, &pStmt, objc>=5 ? &zTail : 0);
|
|
free(zCopy);
|
|
zTail = &zSql[(zTail - zCopy)];
|
|
|
|
assert(rc==SQLITE_OK || pStmt==0);
|
|
Tcl_ResetResult(interp);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
if( rc==SQLITE_OK && zTail && objc>=5 ){
|
|
if( bytes>=0 ){
|
|
bytes = bytes - (int)(zTail-zSql);
|
|
}
|
|
Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
|
|
}
|
|
if( rc!=SQLITE_OK ){
|
|
assert( pStmt==0 );
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc);
|
|
Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( pStmt ){
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_prepare_tkt3134 DB
|
|
**
|
|
** Generate a prepared statement for a zero-byte string as a test
|
|
** for ticket #3134. The string should be preceded by a zero byte.
|
|
*/
|
|
static int test_prepare_tkt3134(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
static const char zSql[] = "\000SELECT 1";
|
|
sqlite3_stmt *pStmt = 0;
|
|
char zBuf[50];
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
rc = sqlite3_prepare_v2(db, &zSql[1], 0, &pStmt, 0);
|
|
assert(rc==SQLITE_OK || pStmt==0);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
if( rc!=SQLITE_OK ){
|
|
assert( pStmt==0 );
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "(%d) ", rc);
|
|
Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( pStmt ){
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_prepare16 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.
|
|
*/
|
|
static int test_prepare16(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
sqlite3 *db;
|
|
const void *zSql;
|
|
const void *zTail = 0;
|
|
Tcl_Obj *pTail = 0;
|
|
sqlite3_stmt *pStmt = 0;
|
|
char zBuf[50];
|
|
int rc;
|
|
int bytes; /* The integer specified as arg 3 */
|
|
int objlen; /* The byte-array length of arg 2 */
|
|
|
|
if( objc!=5 && objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " DB sql bytes ?tailvar?", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen);
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_prepare16(db, zSql, bytes, &pStmt, objc>=5 ? &zTail : 0);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
if( rc ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( objc>=5 ){
|
|
if( zTail ){
|
|
objlen = objlen - (int)((u8 *)zTail-(u8 *)zSql);
|
|
}else{
|
|
objlen = 0;
|
|
}
|
|
pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen);
|
|
Tcl_IncrRefCount(pTail);
|
|
Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0);
|
|
Tcl_DecrRefCount(pTail);
|
|
}
|
|
|
|
if( pStmt ){
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
|
}
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_prepare16_v2 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.
|
|
*/
|
|
static int test_prepare16_v2(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
sqlite3 *db;
|
|
const void *zSql;
|
|
const void *zTail = 0;
|
|
Tcl_Obj *pTail = 0;
|
|
sqlite3_stmt *pStmt = 0;
|
|
char zBuf[50];
|
|
int rc;
|
|
int bytes; /* The integer specified as arg 3 */
|
|
int objlen; /* The byte-array length of arg 2 */
|
|
|
|
if( objc!=5 && objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " DB sql bytes ?tailvar?", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen);
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_prepare16_v2(db, zSql, bytes, &pStmt, objc>=5 ? &zTail : 0);
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
if( rc ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( objc>=5 ){
|
|
if( zTail ){
|
|
objlen = objlen - (int)((u8 *)zTail-(u8 *)zSql);
|
|
}else{
|
|
objlen = 0;
|
|
}
|
|
pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen);
|
|
Tcl_IncrRefCount(pTail);
|
|
Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0);
|
|
Tcl_DecrRefCount(pTail);
|
|
}
|
|
|
|
if( pStmt ){
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
|
}
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_open filename ?options-list?
|
|
*/
|
|
static int test_open(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
const char *zFilename;
|
|
sqlite3 *db;
|
|
char zBuf[100];
|
|
|
|
if( objc!=3 && objc!=2 && objc!=1 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " filename options-list", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
zFilename = objc>1 ? Tcl_GetString(objv[1]) : 0;
|
|
sqlite3_open(zFilename, &db);
|
|
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_open_v2 FILENAME FLAGS VFS
|
|
*/
|
|
static int test_open_v2(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
const char *zFilename;
|
|
const char *zVfs;
|
|
int flags = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
char zBuf[100];
|
|
|
|
int nFlag;
|
|
Tcl_Obj **apFlag;
|
|
int i;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "FILENAME FLAGS VFS");
|
|
return TCL_ERROR;
|
|
}
|
|
zFilename = Tcl_GetString(objv[1]);
|
|
zVfs = Tcl_GetString(objv[3]);
|
|
if( zVfs[0]==0x00 ) zVfs = 0;
|
|
|
|
rc = Tcl_ListObjGetElements(interp, objv[2], &nFlag, &apFlag);
|
|
if( rc!=TCL_OK ) return rc;
|
|
for(i=0; i<nFlag; i++){
|
|
int iFlag;
|
|
struct OpenFlag {
|
|
const char *zFlag;
|
|
int flag;
|
|
} aFlag[] = {
|
|
{ "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY },
|
|
{ "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE },
|
|
{ "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE },
|
|
{ "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE },
|
|
{ "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE },
|
|
{ "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY },
|
|
{ "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB },
|
|
{ "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB },
|
|
{ "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB },
|
|
{ "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL },
|
|
{ "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL },
|
|
{ "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL },
|
|
{ "SQLITE_OPEN_MASTER_JOURNAL", SQLITE_OPEN_MASTER_JOURNAL },
|
|
{ "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX },
|
|
{ "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX },
|
|
{ "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE },
|
|
{ "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE },
|
|
{ "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL },
|
|
{ "SQLITE_OPEN_URI", SQLITE_OPEN_URI },
|
|
{ 0, 0 }
|
|
};
|
|
rc = Tcl_GetIndexFromObjStruct(interp, apFlag[i], aFlag, sizeof(aFlag[0]),
|
|
"flag", 0, &iFlag
|
|
);
|
|
if( rc!=TCL_OK ) return rc;
|
|
flags |= aFlag[iFlag].flag;
|
|
}
|
|
|
|
rc = sqlite3_open_v2(zFilename, &db, flags, zVfs);
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_open16 filename options
|
|
*/
|
|
static int test_open16(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
const void *zFilename;
|
|
sqlite3 *db;
|
|
char zBuf[100];
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " filename options-list", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
zFilename = Tcl_GetByteArrayFromObj(objv[1], 0);
|
|
sqlite3_open16(zFilename, &db);
|
|
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_complete16 <UTF-16 string>
|
|
**
|
|
** Return 1 if the supplied argument is a complete SQL statement, or zero
|
|
** otherwise.
|
|
*/
|
|
static int test_complete16(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
|
|
char *zBuf;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "<utf-16 sql>");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
zBuf = (char*)Tcl_GetByteArrayFromObj(objv[1], 0);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf)));
|
|
#endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_step STMT
|
|
**
|
|
** Advance the statement to the next row.
|
|
*/
|
|
static int test_step(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetString(objv[0]), " STMT", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
rc = sqlite3_step(pStmt);
|
|
|
|
/* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
static int test_sql(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
Tcl_SetResult(interp, (char *)sqlite3_sql(pStmt), TCL_VOLATILE);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_count STMT
|
|
**
|
|
** Return the number of columns returned by the sql statement STMT.
|
|
*/
|
|
static int test_column_count(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
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;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_column_count(pStmt)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_type STMT column
|
|
**
|
|
** Return the type of the data in column 'column' of the current row.
|
|
*/
|
|
static int test_column_type(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
int tp;
|
|
|
|
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;
|
|
|
|
tp = sqlite3_column_type(pStmt, col);
|
|
switch( tp ){
|
|
case SQLITE_INTEGER:
|
|
Tcl_SetResult(interp, "INTEGER", TCL_STATIC);
|
|
break;
|
|
case SQLITE_NULL:
|
|
Tcl_SetResult(interp, "NULL", TCL_STATIC);
|
|
break;
|
|
case SQLITE_FLOAT:
|
|
Tcl_SetResult(interp, "FLOAT", TCL_STATIC);
|
|
break;
|
|
case SQLITE_TEXT:
|
|
Tcl_SetResult(interp, "TEXT", TCL_STATIC);
|
|
break;
|
|
case SQLITE_BLOB:
|
|
Tcl_SetResult(interp, "BLOB", TCL_STATIC);
|
|
break;
|
|
default:
|
|
assert(0);
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_int64 STMT column
|
|
**
|
|
** Return the data in column 'column' of the current row cast as an
|
|
** wide (64-bit) integer.
|
|
*/
|
|
static int test_column_int64(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
i64 iVal;
|
|
|
|
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;
|
|
|
|
iVal = sqlite3_column_int64(pStmt, col);
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_blob STMT column
|
|
*/
|
|
static int test_column_blob(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
|
|
int len;
|
|
const void *pBlob;
|
|
|
|
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;
|
|
|
|
len = sqlite3_column_bytes(pStmt, col);
|
|
pBlob = sqlite3_column_blob(pStmt, col);
|
|
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_double STMT column
|
|
**
|
|
** Return the data in column 'column' of the current row cast as a double.
|
|
*/
|
|
static int test_column_double(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
double rVal;
|
|
|
|
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;
|
|
|
|
rVal = sqlite3_column_double(pStmt, col);
|
|
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(rVal));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_data_count STMT
|
|
**
|
|
** Return the number of columns returned by the sql statement STMT.
|
|
*/
|
|
static int test_data_count(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
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;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_data_count(pStmt)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_text STMT column
|
|
**
|
|
** Usage: sqlite3_column_decltype STMT column
|
|
**
|
|
** Usage: sqlite3_column_name STMT column
|
|
*/
|
|
static int test_stmt_utf8(
|
|
void * clientData, /* Pointer to SQLite API function to be invoke */
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
const char *(*xFunc)(sqlite3_stmt*, int);
|
|
const char *zRet;
|
|
|
|
xFunc = (const char *(*)(sqlite3_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;
|
|
zRet = xFunc(pStmt, col);
|
|
if( zRet ){
|
|
Tcl_SetResult(interp, (char *)zRet, 0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
static int test_global_recover(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
int rc;
|
|
if( objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "");
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_global_recover();
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_text STMT column
|
|
**
|
|
** Usage: sqlite3_column_decltype STMT column
|
|
**
|
|
** Usage: sqlite3_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 SQLITE_OMIT_UTF16
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
Tcl_Obj *pRet;
|
|
const void *zName16;
|
|
const void *(*xFunc)(sqlite3_stmt*, int);
|
|
|
|
xFunc = (const void *(*)(sqlite3_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 /* SQLITE_OMIT_UTF16 */
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_column_int STMT column
|
|
**
|
|
** Usage: sqlite3_column_bytes STMT column
|
|
**
|
|
** Usage: sqlite3_column_bytes16 STMT column
|
|
**
|
|
*/
|
|
static int test_stmt_int(
|
|
void * clientData, /* Pointer to SQLite API function to be invoked */
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_stmt *pStmt;
|
|
int col;
|
|
int (*xFunc)(sqlite3_stmt*, int);
|
|
|
|
xFunc = (int (*)(sqlite3_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;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(xFunc(pStmt, col)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite_set_magic DB MAGIC-NUMBER
|
|
**
|
|
** Set the db->magic value. This is used to test error recovery logic.
|
|
*/
|
|
static int sqlite_set_magic(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
sqlite3 *db;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB MAGIC", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){
|
|
db->magic = SQLITE_MAGIC_OPEN;
|
|
}else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){
|
|
db->magic = SQLITE_MAGIC_CLOSED;
|
|
}else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){
|
|
db->magic = SQLITE_MAGIC_BUSY;
|
|
}else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){
|
|
db->magic = SQLITE_MAGIC_ERROR;
|
|
}else if( Tcl_GetInt(interp, argv[2], (int*)&db->magic) ){
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_interrupt DB
|
|
**
|
|
** Trigger an interrupt on DB
|
|
*/
|
|
static int test_interrupt(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
sqlite3 *db;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
sqlite3_interrupt(db);
|
|
return TCL_OK;
|
|
}
|
|
|
|
static u8 *sqlite3_stack_baseline = 0;
|
|
|
|
/*
|
|
** Fill the stack with a known bitpattern.
|
|
*/
|
|
static void prepStack(void){
|
|
int i;
|
|
u32 bigBuf[65536];
|
|
for(i=0; i<sizeof(bigBuf)/sizeof(bigBuf[0]); i++) bigBuf[i] = 0xdeadbeef;
|
|
sqlite3_stack_baseline = (u8*)&bigBuf[65536];
|
|
}
|
|
|
|
/*
|
|
** Get the current stack depth. Used for debugging only.
|
|
*/
|
|
u64 sqlite3StackDepth(void){
|
|
u8 x;
|
|
return (u64)(sqlite3_stack_baseline - &x);
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_stack_used DB SQL
|
|
**
|
|
** Try to measure the amount of stack space used by a call to sqlite3_exec
|
|
*/
|
|
static int test_stack_used(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
sqlite3 *db;
|
|
int i;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB SQL", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
prepStack();
|
|
(void)sqlite3_exec(db, argv[2], 0, 0, 0);
|
|
for(i=65535; i>=0 && ((u32*)sqlite3_stack_baseline)[-i]==0xdeadbeef; i--){}
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(i*4));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite_delete_function DB function-name
|
|
**
|
|
** Delete the user function 'function-name' from database handle DB. It
|
|
** is assumed that the user function was created as UTF8, any number of
|
|
** arguments (the way the TCL interface does it).
|
|
*/
|
|
static int delete_function(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
int rc;
|
|
sqlite3 *db;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB function-name", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, 0, 0, 0);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite_delete_collation DB collation-name
|
|
**
|
|
** Delete the collation sequence 'collation-name' from database handle
|
|
** DB. It is assumed that the collation sequence was created as UTF8 (the
|
|
** way the TCL interface does it).
|
|
*/
|
|
static int delete_collation(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
int rc;
|
|
sqlite3 *db;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB function-name", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
rc = sqlite3_create_collation(db, argv[2], SQLITE_UTF8, 0, 0);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_get_autocommit DB
|
|
**
|
|
** Return true if the database DB is currently in auto-commit mode.
|
|
** Return false if not.
|
|
*/
|
|
static int get_autocommit(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
char zBuf[30];
|
|
sqlite3 *db;
|
|
if( argc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3_get_autocommit(db));
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_busy_timeout DB MS
|
|
**
|
|
** Set the busy timeout. This is more easily done using the timeout
|
|
** method of the TCL interface. But we need a way to test the case
|
|
** where it returns SQLITE_MISUSE.
|
|
*/
|
|
static int test_busy_timeout(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int argc,
|
|
char **argv
|
|
){
|
|
int rc, ms;
|
|
sqlite3 *db;
|
|
if( argc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
" DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
if( Tcl_GetInt(interp, argv[2], &ms) ) return TCL_ERROR;
|
|
rc = sqlite3_busy_timeout(db, ms);
|
|
Tcl_AppendResult(interp, sqlite3ErrName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: tcl_variable_type VARIABLENAME
|
|
**
|
|
** Return the name of the internal representation for the
|
|
** value of the given variable.
|
|
*/
|
|
static int tcl_variable_type(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
Tcl_Obj *pVar;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "VARIABLE");
|
|
return TCL_ERROR;
|
|
}
|
|
pVar = Tcl_GetVar2Ex(interp, Tcl_GetString(objv[1]), 0, TCL_LEAVE_ERR_MSG);
|
|
if( pVar==0 ) return TCL_ERROR;
|
|
if( pVar->typePtr ){
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(pVar->typePtr->name, -1));
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_release_memory ?N?
|
|
**
|
|
** Attempt to release memory currently held but not actually required.
|
|
** The integer N is the number of bytes we are trying to release. The
|
|
** return value is the amount of memory actually released.
|
|
*/
|
|
static int test_release_memory(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
|
|
int N;
|
|
int amt;
|
|
if( objc!=1 && objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
|
return TCL_ERROR;
|
|
}
|
|
if( objc==2 ){
|
|
if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
|
}else{
|
|
N = -1;
|
|
}
|
|
amt = sqlite3_release_memory(N);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** Usage: sqlite3_db_release_memory DB
|
|
**
|
|
** Attempt to release memory currently held by database DB. Return the
|
|
** result code (which in the current implementation is always zero).
|
|
*/
|
|
static int test_db_release_memory(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
rc = sqlite3_db_release_memory(db);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_db_cacheflush DB
|
|
**
|
|
** Attempt to flush any dirty pages to disk.
|
|
*/
|
|
static int test_db_cacheflush(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
rc = sqlite3_db_cacheflush(db);
|
|
if( rc ){
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
Tcl_ResetResult(interp);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_db_filename DB DBNAME
|
|
**
|
|
** Return the name of a file associated with a database.
|
|
*/
|
|
static int test_db_filename(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
const char *zDbName;
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zDbName = Tcl_GetString(objv[2]);
|
|
Tcl_AppendResult(interp, sqlite3_db_filename(db, zDbName), (void*)0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_db_readonly DB DBNAME
|
|
**
|
|
** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does
|
|
** not exist.
|
|
*/
|
|
static int test_db_readonly(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
const char *zDbName;
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zDbName = Tcl_GetString(objv[2]);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_db_readonly(db, zDbName)));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_soft_heap_limit ?N?
|
|
**
|
|
** Query or set the soft heap limit for the current thread. The
|
|
** limit is only changed if the N is present. The previous limit
|
|
** is returned.
|
|
*/
|
|
static int test_soft_heap_limit(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3_int64 amt;
|
|
Tcl_WideInt N = -1;
|
|
if( objc!=1 && objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
|
return TCL_ERROR;
|
|
}
|
|
if( objc==2 ){
|
|
if( Tcl_GetWideIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
|
}
|
|
amt = sqlite3_soft_heap_limit64(N);
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(amt));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_thread_cleanup
|
|
**
|
|
** Call the sqlite3_thread_cleanup API.
|
|
*/
|
|
static int test_thread_cleanup(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
sqlite3_thread_cleanup();
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Usage: sqlite3_pager_refcounts DB
|
|
**
|
|
** Return a list of numbers which are the PagerRefcount for all
|
|
** pagers on each database connection.
|
|
*/
|
|
static int test_pager_refcounts(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
sqlite3 *db;
|
|
int i;
|
|
int v, *a;
|
|
Tcl_Obj *pResult;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
pResult = Tcl_NewObj();
|
|
for(i=0; i<db->nDb; i++){
|
|
if( db->aDb[i].pBt==0 ){
|
|
v = -1;
|
|
}else{
|
|
sqlite3_mutex_enter(db->mutex);
|
|
a = sqlite3PagerStats(sqlite3BtreePager(db->aDb[i].pBt));
|
|
v = a[0];
|
|
sqlite3_mutex_leave(db->mutex);
|
|
}
|
|
Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(v));
|
|
}
|
|
Tcl_SetObjResult(interp, pResult);
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: working_64bit_int
|
|
**
|
|
** Some TCL builds (ex: cygwin) do not support 64-bit integers. This
|
|
** leads to a number of test failures. The present command checks the
|
|
** TCL build to see whether or not it supports 64-bit integers. It
|
|
** returns TRUE if it does and FALSE if not.
|
|
**
|
|
** This command is used to warn users that their TCL build is defective
|
|
** and that the errors they are seeing in the test scripts might be
|
|
** a result of their defective TCL rather than problems in SQLite.
|
|
*/
|
|
static int working_64bit_int(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
Tcl_Obj *pTestObj;
|
|
int working = 0;
|
|
|
|
pTestObj = Tcl_NewWideIntObj(1000000*(i64)1234567890);
|
|
working = strcmp(Tcl_GetString(pTestObj), "1234567890000000")==0;
|
|
Tcl_DecrRefCount(pTestObj);
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(working));
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: vfs_unlink_test
|
|
**
|
|
** This TCL command unregisters the primary VFS and then registers
|
|
** it back again. This is used to test the ability to register a
|
|
** VFS when none are previously registered, and the ability to
|
|
** unregister the only available VFS. Ticket #2738
|
|
*/
|
|
static int vfs_unlink_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int i;
|
|
sqlite3_vfs *pMain;
|
|
sqlite3_vfs *apVfs[20];
|
|
sqlite3_vfs one, two;
|
|
|
|
sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */
|
|
one.zName = "__one";
|
|
two.zName = "__two";
|
|
|
|
/* Calling sqlite3_vfs_register with 2nd argument of 0 does not
|
|
** change the default VFS
|
|
*/
|
|
pMain = sqlite3_vfs_find(0);
|
|
sqlite3_vfs_register(&one, 0);
|
|
assert( pMain==0 || pMain==sqlite3_vfs_find(0) );
|
|
sqlite3_vfs_register(&two, 0);
|
|
assert( pMain==0 || pMain==sqlite3_vfs_find(0) );
|
|
|
|
/* We can find a VFS by its name */
|
|
assert( sqlite3_vfs_find("__one")==&one );
|
|
assert( sqlite3_vfs_find("__two")==&two );
|
|
|
|
/* Calling sqlite_vfs_register with non-zero second parameter changes the
|
|
** default VFS, even if the 1st parameter is an existig VFS that is
|
|
** previously registered as the non-default.
|
|
*/
|
|
sqlite3_vfs_register(&one, 1);
|
|
assert( sqlite3_vfs_find("__one")==&one );
|
|
assert( sqlite3_vfs_find("__two")==&two );
|
|
assert( sqlite3_vfs_find(0)==&one );
|
|
sqlite3_vfs_register(&two, 1);
|
|
assert( sqlite3_vfs_find("__one")==&one );
|
|
assert( sqlite3_vfs_find("__two")==&two );
|
|
assert( sqlite3_vfs_find(0)==&two );
|
|
if( pMain ){
|
|
sqlite3_vfs_register(pMain, 1);
|
|
assert( sqlite3_vfs_find("__one")==&one );
|
|
assert( sqlite3_vfs_find("__two")==&two );
|
|
assert( sqlite3_vfs_find(0)==pMain );
|
|
}
|
|
|
|
/* Unlink the default VFS. Repeat until there are no more VFSes
|
|
** registered.
|
|
*/
|
|
for(i=0; i<sizeof(apVfs)/sizeof(apVfs[0]); i++){
|
|
apVfs[i] = sqlite3_vfs_find(0);
|
|
if( apVfs[i] ){
|
|
assert( apVfs[i]==sqlite3_vfs_find(apVfs[i]->zName) );
|
|
sqlite3_vfs_unregister(apVfs[i]);
|
|
assert( 0==sqlite3_vfs_find(apVfs[i]->zName) );
|
|
}
|
|
}
|
|
assert( 0==sqlite3_vfs_find(0) );
|
|
|
|
/* Register the main VFS as non-default (will be made default, since
|
|
** it'll be the only one in existence).
|
|
*/
|
|
sqlite3_vfs_register(pMain, 0);
|
|
assert( sqlite3_vfs_find(0)==pMain );
|
|
|
|
/* Un-register the main VFS again to restore an empty VFS list */
|
|
sqlite3_vfs_unregister(pMain);
|
|
assert( 0==sqlite3_vfs_find(0) );
|
|
|
|
/* Relink all VFSes in reverse order. */
|
|
for(i=sizeof(apVfs)/sizeof(apVfs[0])-1; i>=0; i--){
|
|
if( apVfs[i] ){
|
|
sqlite3_vfs_register(apVfs[i], 1);
|
|
assert( apVfs[i]==sqlite3_vfs_find(0) );
|
|
assert( apVfs[i]==sqlite3_vfs_find(apVfs[i]->zName) );
|
|
}
|
|
}
|
|
|
|
/* Unregister out sample VFSes. */
|
|
sqlite3_vfs_unregister(&one);
|
|
sqlite3_vfs_unregister(&two);
|
|
|
|
/* Unregistering a VFS that is not currently registered is harmless */
|
|
sqlite3_vfs_unregister(&one);
|
|
sqlite3_vfs_unregister(&two);
|
|
assert( sqlite3_vfs_find("__one")==0 );
|
|
assert( sqlite3_vfs_find("__two")==0 );
|
|
|
|
/* We should be left with the original default VFS back as the
|
|
** original */
|
|
assert( sqlite3_vfs_find(0)==pMain );
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: vfs_initfail_test
|
|
**
|
|
** This TCL command attempts to vfs_find and vfs_register when the
|
|
** sqlite3_initialize() interface is failing. All calls should fail.
|
|
*/
|
|
static int vfs_initfail_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3_vfs one;
|
|
one.zName = "__one";
|
|
|
|
if( sqlite3_vfs_find(0) ) return TCL_ERROR;
|
|
sqlite3_vfs_register(&one, 0);
|
|
if( sqlite3_vfs_find(0) ) return TCL_ERROR;
|
|
sqlite3_vfs_register(&one, 1);
|
|
if( sqlite3_vfs_find(0) ) return TCL_ERROR;
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** Saved VFSes
|
|
*/
|
|
static sqlite3_vfs *apVfs[20];
|
|
static int nVfs = 0;
|
|
|
|
/*
|
|
** tclcmd: vfs_unregister_all
|
|
**
|
|
** Unregister all VFSes.
|
|
*/
|
|
static int vfs_unregister_all(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int i;
|
|
for(i=0; i<ArraySize(apVfs); i++){
|
|
apVfs[i] = sqlite3_vfs_find(0);
|
|
if( apVfs[i]==0 ) break;
|
|
sqlite3_vfs_unregister(apVfs[i]);
|
|
}
|
|
nVfs = i;
|
|
return TCL_OK;
|
|
}
|
|
/*
|
|
** tclcmd: vfs_reregister_all
|
|
**
|
|
** Restore all VFSes that were removed using vfs_unregister_all
|
|
*/
|
|
static int vfs_reregister_all(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int i;
|
|
for(i=0; i<nVfs; i++){
|
|
sqlite3_vfs_register(apVfs[i], i==0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: file_control_test DB
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface and
|
|
** verifies correct operation of the same.
|
|
*/
|
|
static int file_control_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int iArg = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
rc = sqlite3_file_control(db, 0, 0, &iArg);
|
|
assert( rc==SQLITE_NOTFOUND );
|
|
rc = sqlite3_file_control(db, "notadatabase", SQLITE_FCNTL_LOCKSTATE, &iArg);
|
|
assert( rc==SQLITE_ERROR );
|
|
rc = sqlite3_file_control(db, "main", -1, &iArg);
|
|
assert( rc==SQLITE_NOTFOUND );
|
|
rc = sqlite3_file_control(db, "temp", -1, &iArg);
|
|
assert( rc==SQLITE_NOTFOUND || rc==SQLITE_ERROR );
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: file_control_lasterrno_test DB
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface and
|
|
** verifies correct operation of the SQLITE_LAST_ERRNO verb.
|
|
*/
|
|
static int file_control_lasterrno_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int iArg = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_LAST_ERRNO, &iArg);
|
|
if( rc ){
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
|
return TCL_ERROR;
|
|
}
|
|
if( iArg!=0 ) {
|
|
Tcl_AppendResult(interp, "Unexpected non-zero errno: ",
|
|
Tcl_GetStringFromObj(Tcl_NewIntObj(iArg), 0), " ", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: file_control_chunksize_test DB DBNAME SIZE
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface and
|
|
** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
|
|
** SQLITE_SET_LOCKPROXYFILE verbs.
|
|
*/
|
|
static int file_control_chunksize_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int nSize; /* New chunk size */
|
|
char *zDb; /* Db name ("main", "temp" etc.) */
|
|
sqlite3 *db; /* Database handle */
|
|
int rc; /* file_control() return code */
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SIZE");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|
|
|| Tcl_GetIntFromObj(interp, objv[3], &nSize)
|
|
){
|
|
return TCL_ERROR;
|
|
}
|
|
zDb = Tcl_GetString(objv[2]);
|
|
if( zDb[0]=='\0' ) zDb = NULL;
|
|
|
|
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_CHUNK_SIZE, (void *)&nSize);
|
|
if( rc ){
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: file_control_sizehint_test DB DBNAME SIZE
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface
|
|
** with SQLITE_FCNTL_SIZE_HINT
|
|
*/
|
|
static int file_control_sizehint_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
Tcl_WideInt nSize; /* Hinted size */
|
|
char *zDb; /* Db name ("main", "temp" etc.) */
|
|
sqlite3 *db; /* Database handle */
|
|
int rc; /* file_control() return code */
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SIZE");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|
|
|| Tcl_GetWideIntFromObj(interp, objv[3], &nSize)
|
|
){
|
|
return TCL_ERROR;
|
|
}
|
|
zDb = Tcl_GetString(objv[2]);
|
|
if( zDb[0]=='\0' ) zDb = NULL;
|
|
|
|
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_SIZE_HINT, (void *)&nSize);
|
|
if( rc ){
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
|
|
return TCL_ERROR;
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: file_control_lockproxy_test DB PWD
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface and
|
|
** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
|
|
** SQLITE_SET_LOCKPROXYFILE verbs.
|
|
*/
|
|
static int file_control_lockproxy_test(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB PWD", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
|
|
# if defined(__APPLE__)
|
|
# define SQLITE_ENABLE_LOCKING_STYLE 1
|
|
# else
|
|
# define SQLITE_ENABLE_LOCKING_STYLE 0
|
|
# endif
|
|
#endif
|
|
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
|
|
{
|
|
char *testPath;
|
|
int rc;
|
|
int nPwd;
|
|
const char *zPwd;
|
|
char proxyPath[400];
|
|
|
|
zPwd = Tcl_GetStringFromObj(objv[2], &nPwd);
|
|
if( sizeof(proxyPath)<nPwd+20 ){
|
|
Tcl_AppendResult(interp, "PWD too big", (void*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
sqlite3_snprintf(sizeof(proxyPath), proxyPath, "%s/test.proxy", zPwd);
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath);
|
|
if( rc ){
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_GET_LOCKPROXYFILE, &testPath);
|
|
if( strncmp(proxyPath,testPath,11) ){
|
|
Tcl_AppendResult(interp, "Lock proxy file did not match the "
|
|
"previously assigned value", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( rc ){
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath);
|
|
if( rc ){
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
#endif
|
|
return TCL_OK;
|
|
}
|
|
|
|
#if SQLITE_OS_WIN
|
|
/*
|
|
** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface with
|
|
** the SQLITE_FCNTL_WIN32_AV_RETRY opcode.
|
|
*/
|
|
static int file_control_win32_av_retry(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
int a[2];
|
|
char z[100];
|
|
|
|
if( objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB NRETRY DELAY", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &a[0]) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &a[1]) ) return TCL_ERROR;
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_AV_RETRY, (void*)a);
|
|
sqlite3_snprintf(sizeof(z), z, "%d %d %d", rc, a[0], a[1]);
|
|
Tcl_AppendResult(interp, z, (char*)0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: file_control_win32_set_handle DB HANDLE
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface with
|
|
** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
|
|
*/
|
|
static int file_control_win32_set_handle(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
HANDLE hFile = NULL;
|
|
char z[100];
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB HANDLE", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( getWin32Handle(interp, Tcl_GetString(objv[2]), &hFile) ){
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_SET_HANDLE,
|
|
(void*)&hFile);
|
|
sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile);
|
|
Tcl_AppendResult(interp, z, (char*)0);
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** tclcmd: file_control_persist_wal DB PERSIST-FLAG
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface with
|
|
** the SQLITE_FCNTL_PERSIST_WAL opcode.
|
|
*/
|
|
static int file_control_persist_wal(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
int bPersist;
|
|
char z[100];
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB FLAG", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &bPersist) ) return TCL_ERROR;
|
|
rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_PERSIST_WAL, (void*)&bPersist);
|
|
sqlite3_snprintf(sizeof(z), z, "%d %d", rc, bPersist);
|
|
Tcl_AppendResult(interp, z, (char*)0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG
|
|
**
|
|
** This TCL command runs the sqlite3_file_control interface with
|
|
** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
|
|
*/
|
|
static int file_control_powersafe_overwrite(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
int b;
|
|
char z[100];
|
|
|
|
if( objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB FLAG", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &b) ) return TCL_ERROR;
|
|
rc = sqlite3_file_control(db,NULL,SQLITE_FCNTL_POWERSAFE_OVERWRITE,(void*)&b);
|
|
sqlite3_snprintf(sizeof(z), z, "%d %d", rc, b);
|
|
Tcl_AppendResult(interp, z, (char*)0);
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: file_control_vfsname DB ?AUXDB?
|
|
**
|
|
** Return a string that describes the stack of VFSes.
|
|
*/
|
|
static int file_control_vfsname(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
const char *zDbName = "main";
|
|
char *zVfsName = 0;
|
|
|
|
if( objc!=2 && objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB ?AUXDB?", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( objc==3 ){
|
|
zDbName = Tcl_GetString(objv[2]);
|
|
}
|
|
sqlite3_file_control(db, zDbName, SQLITE_FCNTL_VFSNAME,(void*)&zVfsName);
|
|
Tcl_AppendResult(interp, zVfsName, (char*)0);
|
|
sqlite3_free(zVfsName);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: file_control_tempfilename DB ?AUXDB?
|
|
**
|
|
** Return a string that is a temporary filename
|
|
*/
|
|
static int file_control_tempfilename(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
const char *zDbName = "main";
|
|
char *zTName = 0;
|
|
|
|
if( objc!=2 && objc!=3 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB ?AUXDB?", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( objc==3 ){
|
|
zDbName = Tcl_GetString(objv[2]);
|
|
}
|
|
sqlite3_file_control(db, zDbName, SQLITE_FCNTL_TEMPFILENAME, (void*)&zTName);
|
|
Tcl_AppendResult(interp, zTName, (char*)0);
|
|
sqlite3_free(zTName);
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: sqlite3_vfs_list
|
|
**
|
|
** Return a tcl list containing the names of all registered vfs's.
|
|
*/
|
|
static int vfs_list(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3_vfs *pVfs;
|
|
Tcl_Obj *pRet = Tcl_NewObj();
|
|
if( objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "");
|
|
return TCL_ERROR;
|
|
}
|
|
for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(pVfs->zName, -1));
|
|
}
|
|
Tcl_SetObjResult(interp, pRet);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: sqlite3_limit DB ID VALUE
|
|
**
|
|
** This TCL command runs the sqlite3_limit interface and
|
|
** verifies correct operation of the same.
|
|
*/
|
|
static int test_limit(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
static const struct {
|
|
char *zName;
|
|
int id;
|
|
} aId[] = {
|
|
{ "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH },
|
|
{ "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH },
|
|
{ "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN },
|
|
{ "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH },
|
|
{ "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT },
|
|
{ "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP },
|
|
{ "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG },
|
|
{ "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED },
|
|
{ "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
|
|
{ "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER },
|
|
{ "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH },
|
|
{ "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS },
|
|
|
|
/* Out of range test cases */
|
|
{ "SQLITE_LIMIT_TOOSMALL", -1, },
|
|
{ "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS+1 },
|
|
};
|
|
int i, id = 0;
|
|
int val;
|
|
const char *zId;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
Tcl_GetStringFromObj(objv[0], 0), " DB ID VALUE", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zId = Tcl_GetString(objv[2]);
|
|
for(i=0; i<sizeof(aId)/sizeof(aId[0]); i++){
|
|
if( strcmp(zId, aId[i].zName)==0 ){
|
|
id = aId[i].id;
|
|
break;
|
|
}
|
|
}
|
|
if( i>=sizeof(aId)/sizeof(aId[0]) ){
|
|
Tcl_AppendResult(interp, "unknown limit type: ", zId, (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR;
|
|
rc = sqlite3_limit(db, id, val);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: save_prng_state
|
|
**
|
|
** Save the state of the pseudo-random number generator.
|
|
** At the same time, verify that sqlite3_test_control works even when
|
|
** called with an out-of-range opcode.
|
|
*/
|
|
static int save_prng_state(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int rc = sqlite3_test_control(9999);
|
|
assert( rc==0 );
|
|
rc = sqlite3_test_control(-1);
|
|
assert( rc==0 );
|
|
sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE);
|
|
return TCL_OK;
|
|
}
|
|
/*
|
|
** tclcmd: restore_prng_state
|
|
*/
|
|
static int restore_prng_state(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE);
|
|
return TCL_OK;
|
|
}
|
|
/*
|
|
** tclcmd: reset_prng_state
|
|
*/
|
|
static int reset_prng_state(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: database_may_be_corrupt
|
|
**
|
|
** Indicate that database files might be corrupt. In other words, set the normal
|
|
** state of operation.
|
|
*/
|
|
static int database_may_be_corrupt(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 0);
|
|
return TCL_OK;
|
|
}
|
|
/*
|
|
** tclcmd: database_never_corrupt
|
|
**
|
|
** Indicate that database files are always well-formed. This enables extra assert()
|
|
** statements that test conditions that are always true for well-formed databases.
|
|
*/
|
|
static int database_never_corrupt(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 1);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: pcache_stats
|
|
*/
|
|
static int test_pcache_stats(
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int nMin;
|
|
int nMax;
|
|
int nCurrent;
|
|
int nRecyclable;
|
|
Tcl_Obj *pRet;
|
|
|
|
sqlite3PcacheStats(&nCurrent, &nMax, &nMin, &nRecyclable);
|
|
|
|
pRet = Tcl_NewObj();
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("current", -1));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nCurrent));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("max", -1));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nMax));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("min", -1));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nMin));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj("recyclable", -1));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nRecyclable));
|
|
|
|
Tcl_SetObjResult(interp, pRet);
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
|
static void test_unlock_notify_cb(void **aArg, int nArg){
|
|
int ii;
|
|
for(ii=0; ii<nArg; ii++){
|
|
Tcl_EvalEx((Tcl_Interp *)aArg[ii], "unlock_notify", -1, TCL_EVAL_GLOBAL);
|
|
}
|
|
}
|
|
#endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */
|
|
|
|
/*
|
|
** tclcmd: sqlite3_unlock_notify db
|
|
*/
|
|
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
|
static int test_unlock_notify(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
rc = sqlite3_unlock_notify(db, test_unlock_notify_cb, (void *)interp);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** tclcmd: sqlite3_wal_checkpoint db ?NAME?
|
|
*/
|
|
static int test_wal_checkpoint(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
char *zDb = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=3 && objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB ?NAME?");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
if( objc==3 ){
|
|
zDb = Tcl_GetString(objv[2]);
|
|
}
|
|
rc = sqlite3_wal_checkpoint(db, zDb);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME?
|
|
**
|
|
** This command calls the wal_checkpoint_v2() function with the specified
|
|
** mode argument (passive, full or restart). If present, the database name
|
|
** NAME is passed as the second argument to wal_checkpoint_v2(). If it the
|
|
** NAME argument is not present, a NULL pointer is passed instead.
|
|
**
|
|
** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or
|
|
** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set
|
|
** to the error message obtained from sqlite3_errmsg().
|
|
**
|
|
** Otherwise, this command returns a list of three integers. The first integer
|
|
** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
|
|
** are the values returned via the output parameters by wal_checkpoint_v2() -
|
|
** the number of frames in the log and the number of frames in the log
|
|
** that have been checkpointed.
|
|
*/
|
|
static int test_wal_checkpoint_v2(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
char *zDb = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
int eMode;
|
|
int nLog = -555;
|
|
int nCkpt = -555;
|
|
Tcl_Obj *pRet;
|
|
|
|
const char * aMode[] = { "passive", "full", "restart", "truncate", 0 };
|
|
assert( SQLITE_CHECKPOINT_PASSIVE==0 );
|
|
assert( SQLITE_CHECKPOINT_FULL==1 );
|
|
assert( SQLITE_CHECKPOINT_RESTART==2 );
|
|
assert( SQLITE_CHECKPOINT_TRUNCATE==3 );
|
|
|
|
if( objc!=3 && objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB MODE ?NAME?");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( objc==4 ){
|
|
zDb = Tcl_GetString(objv[3]);
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) || (
|
|
TCL_OK!=Tcl_GetIntFromObj(0, objv[2], &eMode)
|
|
&& TCL_OK!=Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode)
|
|
)){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
rc = sqlite3_wal_checkpoint_v2(db, zDb, eMode, &nLog, &nCkpt);
|
|
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
|
const char *zErrCode = sqlite3ErrName(rc);
|
|
Tcl_ResetResult(interp);
|
|
Tcl_AppendResult(interp, zErrCode, " - ", (char *)sqlite3_errmsg(db), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
pRet = Tcl_NewObj();
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(rc==SQLITE_BUSY?1:0));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nLog));
|
|
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(nCkpt));
|
|
Tcl_SetObjResult(interp, pRet);
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: sqlite3_wal_autocheckpoint db VALUE
|
|
*/
|
|
static int test_wal_autocheckpoint(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
sqlite3 *db;
|
|
int rc;
|
|
int iVal;
|
|
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB VALUE");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|
|
|| Tcl_GetIntFromObj(0, objv[2], &iVal)
|
|
){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
rc = sqlite3_wal_autocheckpoint(db, iVal);
|
|
Tcl_ResetResult(interp);
|
|
if( rc!=SQLITE_OK ){
|
|
const char *zErrCode = sqlite3ErrName(rc);
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(zErrCode, -1));
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** tclcmd: test_sqlite3_log ?SCRIPT?
|
|
*/
|
|
static struct LogCallback {
|
|
Tcl_Interp *pInterp;
|
|
Tcl_Obj *pObj;
|
|
} logcallback = {0, 0};
|
|
static void xLogcallback(void *unused, int err, char *zMsg){
|
|
Tcl_Obj *pNew = Tcl_DuplicateObj(logcallback.pObj);
|
|
Tcl_IncrRefCount(pNew);
|
|
Tcl_ListObjAppendElement(
|
|
0, pNew, Tcl_NewStringObj(sqlite3ErrName(err), -1)
|
|
);
|
|
Tcl_ListObjAppendElement(0, pNew, Tcl_NewStringObj(zMsg, -1));
|
|
Tcl_EvalObjEx(logcallback.pInterp, pNew, TCL_EVAL_GLOBAL|TCL_EVAL_DIRECT);
|
|
Tcl_DecrRefCount(pNew);
|
|
}
|
|
static int test_sqlite3_log(
|
|
ClientData clientData,
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
if( objc>2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "SCRIPT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( logcallback.pObj ){
|
|
Tcl_DecrRefCount(logcallback.pObj);
|
|
logcallback.pObj = 0;
|
|
logcallback.pInterp = 0;
|
|
sqlite3_config(SQLITE_CONFIG_LOG, (void*)0, (void*)0);
|
|
}
|
|
if( objc>1 ){
|
|
logcallback.pObj = objv[1];
|
|
Tcl_IncrRefCount(logcallback.pObj);
|
|
logcallback.pInterp = interp;
|
|
sqlite3_config(SQLITE_CONFIG_LOG, xLogcallback, (void*)0);
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tcl_objproc COMMANDNAME ARGS...
|
|
**
|
|
** Run a TCL command using its objProc interface. Throw an error if
|
|
** the command has no objProc interface.
|
|
*/
|
|
static int runAsObjProc(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
Tcl_CmdInfo cmdInfo;
|
|
if( objc<2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "COMMAND ...");
|
|
return TCL_ERROR;
|
|
}
|
|
if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){
|
|
Tcl_AppendResult(interp, "command not found: ",
|
|
Tcl_GetString(objv[1]), (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( cmdInfo.objProc==0 ){
|
|
Tcl_AppendResult(interp, "command has no objProc: ",
|
|
Tcl_GetString(objv[1]), (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
return cmdInfo.objProc(cmdInfo.objClientData, interp, objc-1, objv+1);
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_EXPLAIN
|
|
/*
|
|
** WARNING: The following function, printExplainQueryPlan() is an exact
|
|
** copy of example code from eqp.in (eqp.html). If this code is modified,
|
|
** then the documentation copy needs to be modified as well.
|
|
*/
|
|
/*
|
|
** Argument pStmt is a prepared SQL statement. This function compiles
|
|
** an EXPLAIN QUERY PLAN command to report on the prepared statement,
|
|
** and prints the report to stdout using printf().
|
|
*/
|
|
int printExplainQueryPlan(sqlite3_stmt *pStmt){
|
|
const char *zSql; /* Input SQL */
|
|
char *zExplain; /* SQL with EXPLAIN QUERY PLAN prepended */
|
|
sqlite3_stmt *pExplain; /* Compiled EXPLAIN QUERY PLAN command */
|
|
int rc; /* Return code from sqlite3_prepare_v2() */
|
|
|
|
zSql = sqlite3_sql(pStmt);
|
|
if( zSql==0 ) return SQLITE_ERROR;
|
|
|
|
zExplain = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql);
|
|
if( zExplain==0 ) return SQLITE_NOMEM;
|
|
|
|
rc = sqlite3_prepare_v2(sqlite3_db_handle(pStmt), zExplain, -1, &pExplain, 0);
|
|
sqlite3_free(zExplain);
|
|
if( rc!=SQLITE_OK ) return rc;
|
|
|
|
while( SQLITE_ROW==sqlite3_step(pExplain) ){
|
|
int iSelectid = sqlite3_column_int(pExplain, 0);
|
|
int iOrder = sqlite3_column_int(pExplain, 1);
|
|
int iFrom = sqlite3_column_int(pExplain, 2);
|
|
const char *zDetail = (const char *)sqlite3_column_text(pExplain, 3);
|
|
|
|
printf("%d %d %d %s\n", iSelectid, iOrder, iFrom, zDetail);
|
|
}
|
|
|
|
return sqlite3_finalize(pExplain);
|
|
}
|
|
|
|
static int test_print_eqp(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int rc;
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
rc = printExplainQueryPlan(pStmt);
|
|
/* This is needed on Windows so that a test case using this
|
|
** function can open a read pipe and get the output of
|
|
** printExplainQueryPlan() immediately.
|
|
*/
|
|
fflush(stdout);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_OMIT_EXPLAIN */
|
|
|
|
/*
|
|
** sqlite3_test_control VERB ARGS...
|
|
*/
|
|
static int test_test_control(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
struct Verb {
|
|
const char *zName;
|
|
int i;
|
|
} aVerb[] = {
|
|
{ "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT },
|
|
{ "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP },
|
|
{ "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER },
|
|
};
|
|
int iVerb;
|
|
int iFlag;
|
|
int rc;
|
|
|
|
if( objc<2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "VERB ARGS...");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
rc = Tcl_GetIndexFromObjStruct(
|
|
interp, objv[1], aVerb, sizeof(aVerb[0]), "VERB", 0, &iVerb
|
|
);
|
|
if( rc!=TCL_OK ) return rc;
|
|
|
|
iFlag = aVerb[iVerb].i;
|
|
switch( iFlag ){
|
|
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
|
|
int val;
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 2, objv, "ONOFF");
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
|
sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, val);
|
|
break;
|
|
}
|
|
|
|
case SQLITE_TESTCTRL_SORTER_MMAP: {
|
|
int val;
|
|
sqlite3 *db;
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 2, objv, "DB LIMIT");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR;
|
|
sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, val);
|
|
break;
|
|
}
|
|
|
|
case SQLITE_TESTCTRL_IMPOSTER: {
|
|
int onOff, tnum;
|
|
const char *zDbName;
|
|
sqlite3 *db;
|
|
if( objc!=6 ){
|
|
Tcl_WrongNumArgs(interp, 2, objv, "DB dbName onOff tnum");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR;
|
|
zDbName = Tcl_GetString(objv[3]);
|
|
if( Tcl_GetIntFromObj(interp, objv[4], &onOff) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[5], &tnum) ) return TCL_ERROR;
|
|
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zDbName, onOff, tnum);
|
|
break;
|
|
}
|
|
}
|
|
|
|
Tcl_ResetResult(interp);
|
|
return TCL_OK;
|
|
}
|
|
|
|
#if SQLITE_OS_UNIX
|
|
#include <sys/time.h>
|
|
#include <sys/resource.h>
|
|
|
|
static int test_getrusage(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
char buf[1024];
|
|
struct rusage r;
|
|
memset(&r, 0, sizeof(r));
|
|
getrusage(RUSAGE_SELF, &r);
|
|
|
|
sqlite3_snprintf(sizeof(buf), buf,
|
|
"ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
|
|
(int)r.ru_utime.tv_sec, (int)r.ru_utime.tv_usec,
|
|
(int)r.ru_stime.tv_sec, (int)r.ru_stime.tv_usec,
|
|
(int)r.ru_minflt, (int)r.ru_majflt
|
|
);
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, -1));
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
#if SQLITE_OS_WIN
|
|
/*
|
|
** Information passed from the main thread into the windows file locker
|
|
** background thread.
|
|
*/
|
|
struct win32FileLocker {
|
|
char *evName; /* Name of event to signal thread startup */
|
|
HANDLE h; /* Handle of the file to be locked */
|
|
int delay1; /* Delay before locking */
|
|
int delay2; /* Delay before unlocking */
|
|
int ok; /* Finished ok */
|
|
int err; /* True if an error occurs */
|
|
};
|
|
#endif
|
|
|
|
|
|
#if SQLITE_OS_WIN
|
|
#include <process.h>
|
|
/*
|
|
** The background thread that does file locking.
|
|
*/
|
|
static void win32_file_locker(void *pAppData){
|
|
struct win32FileLocker *p = (struct win32FileLocker*)pAppData;
|
|
if( p->evName ){
|
|
HANDLE ev = OpenEvent(EVENT_MODIFY_STATE, FALSE, p->evName);
|
|
if ( ev ){
|
|
SetEvent(ev);
|
|
CloseHandle(ev);
|
|
}
|
|
}
|
|
if( p->delay1 ) Sleep(p->delay1);
|
|
if( LockFile(p->h, 0, 0, 100000000, 0) ){
|
|
Sleep(p->delay2);
|
|
UnlockFile(p->h, 0, 0, 100000000, 0);
|
|
p->ok = 1;
|
|
}else{
|
|
p->err = 1;
|
|
}
|
|
CloseHandle(p->h);
|
|
p->h = 0;
|
|
p->delay1 = 0;
|
|
p->delay2 = 0;
|
|
}
|
|
#endif
|
|
|
|
#if SQLITE_OS_WIN
|
|
/*
|
|
** lock_win32_file FILENAME DELAY1 DELAY2
|
|
**
|
|
** Get an exclusive manditory lock on file for DELAY2 milliseconds.
|
|
** Wait DELAY1 milliseconds before acquiring the lock.
|
|
*/
|
|
static int win32_file_lock(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
static struct win32FileLocker x = { "win32_file_lock", 0, 0, 0, 0, 0 };
|
|
const char *zFilename;
|
|
char zBuf[200];
|
|
int retry = 0;
|
|
HANDLE ev;
|
|
DWORD wResult;
|
|
|
|
if( objc!=4 && objc!=1 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "FILENAME DELAY1 DELAY2");
|
|
return TCL_ERROR;
|
|
}
|
|
if( objc==1 ){
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d %d %d %d %d",
|
|
x.ok, x.err, x.delay1, x.delay2, x.h);
|
|
Tcl_AppendResult(interp, zBuf, (char*)0);
|
|
return TCL_OK;
|
|
}
|
|
while( x.h && retry<30 ){
|
|
retry++;
|
|
Sleep(100);
|
|
}
|
|
if( x.h ){
|
|
Tcl_AppendResult(interp, "busy", (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &x.delay1) ) return TCL_ERROR;
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &x.delay2) ) return TCL_ERROR;
|
|
zFilename = Tcl_GetString(objv[1]);
|
|
x.h = CreateFile(zFilename, GENERIC_READ|GENERIC_WRITE,
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_ALWAYS,
|
|
FILE_ATTRIBUTE_NORMAL, 0);
|
|
if( !x.h ){
|
|
Tcl_AppendResult(interp, "cannot open file: ", zFilename, (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
ev = CreateEvent(NULL, TRUE, FALSE, x.evName);
|
|
if ( !ev ){
|
|
Tcl_AppendResult(interp, "cannot create event: ", x.evName, (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
_beginthread(win32_file_locker, 0, (void*)&x);
|
|
Sleep(0);
|
|
if ( (wResult = WaitForSingleObject(ev, 10000))!=WAIT_OBJECT_0 ){
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "0x%x", wResult);
|
|
Tcl_AppendResult(interp, "wait failed: ", zBuf, (char*)0);
|
|
CloseHandle(ev);
|
|
return TCL_ERROR;
|
|
}
|
|
CloseHandle(ev);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** exists_win32_path PATH
|
|
**
|
|
** Returns non-zero if the specified path exists, whose fully qualified name
|
|
** may exceed 260 characters if it is prefixed with "\\?\".
|
|
*/
|
|
static int win32_exists_path(
|
|
void *clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "PATH");
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
|
|
GetFileAttributesW( Tcl_GetUnicode(objv[1]))!=INVALID_FILE_ATTRIBUTES ));
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** find_win32_file PATTERN
|
|
**
|
|
** Returns a list of entries in a directory that match the specified pattern,
|
|
** whose fully qualified name may exceed 248 characters if it is prefixed with
|
|
** "\\?\".
|
|
*/
|
|
static int win32_find_file(
|
|
void *clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
HANDLE hFindFile = INVALID_HANDLE_VALUE;
|
|
WIN32_FIND_DATAW findData;
|
|
Tcl_Obj *listObj;
|
|
DWORD lastErrno;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "PATTERN");
|
|
return TCL_ERROR;
|
|
}
|
|
hFindFile = FindFirstFileW(Tcl_GetUnicode(objv[1]), &findData);
|
|
if( hFindFile==INVALID_HANDLE_VALUE ){
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
|
|
return TCL_ERROR;
|
|
}
|
|
listObj = Tcl_NewObj();
|
|
Tcl_IncrRefCount(listObj);
|
|
do {
|
|
Tcl_ListObjAppendElement(interp, listObj, Tcl_NewUnicodeObj(
|
|
findData.cFileName, -1));
|
|
Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(
|
|
findData.dwFileAttributes));
|
|
} while( FindNextFileW(hFindFile, &findData) );
|
|
lastErrno = GetLastError();
|
|
if( lastErrno!=NO_ERROR && lastErrno!=ERROR_NO_MORE_FILES ){
|
|
FindClose(hFindFile);
|
|
Tcl_DecrRefCount(listObj);
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
|
|
return TCL_ERROR;
|
|
}
|
|
FindClose(hFindFile);
|
|
Tcl_SetObjResult(interp, listObj);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** delete_win32_file FILENAME
|
|
**
|
|
** Deletes the specified file, whose fully qualified name may exceed 260
|
|
** characters if it is prefixed with "\\?\".
|
|
*/
|
|
static int win32_delete_file(
|
|
void *clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "FILENAME");
|
|
return TCL_ERROR;
|
|
}
|
|
if( !DeleteFileW(Tcl_GetUnicode(objv[1])) ){
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_ResetResult(interp);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** make_win32_dir DIRECTORY
|
|
**
|
|
** Creates the specified directory, whose fully qualified name may exceed 248
|
|
** characters if it is prefixed with "\\?\".
|
|
*/
|
|
static int win32_mkdir(
|
|
void *clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DIRECTORY");
|
|
return TCL_ERROR;
|
|
}
|
|
if( !CreateDirectoryW(Tcl_GetUnicode(objv[1]), NULL) ){
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_ResetResult(interp);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** remove_win32_dir DIRECTORY
|
|
**
|
|
** Removes the specified directory, whose fully qualified name may exceed 248
|
|
** characters if it is prefixed with "\\?\".
|
|
*/
|
|
static int win32_rmdir(
|
|
void *clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DIRECTORY");
|
|
return TCL_ERROR;
|
|
}
|
|
if( !RemoveDirectoryW(Tcl_GetUnicode(objv[1])) ){
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
|
|
return TCL_ERROR;
|
|
}
|
|
Tcl_ResetResult(interp);
|
|
return TCL_OK;
|
|
}
|
|
#endif
|
|
|
|
|
|
/*
|
|
** optimization_control DB OPT BOOLEAN
|
|
**
|
|
** Enable or disable query optimizations using the sqlite3_test_control()
|
|
** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true.
|
|
** OPT is the name of the optimization to be disabled.
|
|
*/
|
|
static int optimization_control(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int i;
|
|
sqlite3 *db;
|
|
const char *zOpt;
|
|
int onoff;
|
|
int mask = 0;
|
|
static const struct {
|
|
const char *zOptName;
|
|
int mask;
|
|
} aOpt[] = {
|
|
{ "all", SQLITE_AllOpts },
|
|
{ "none", 0 },
|
|
{ "query-flattener", SQLITE_QueryFlattener },
|
|
{ "column-cache", SQLITE_ColumnCache },
|
|
{ "groupby-order", SQLITE_GroupByOrder },
|
|
{ "factor-constants", SQLITE_FactorOutConst },
|
|
{ "distinct-opt", SQLITE_DistinctOpt },
|
|
{ "cover-idx-scan", SQLITE_CoverIdxScan },
|
|
{ "order-by-idx-join", SQLITE_OrderByIdxJoin },
|
|
{ "transitive", SQLITE_Transitive },
|
|
{ "subquery-coroutine", SQLITE_SubqCoroutine },
|
|
{ "omit-noop-join", SQLITE_OmitNoopJoin },
|
|
{ "stat3", SQLITE_Stat34 },
|
|
{ "stat4", SQLITE_Stat34 },
|
|
};
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB OPT BOOLEAN");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
if( Tcl_GetBooleanFromObj(interp, objv[3], &onoff) ) return TCL_ERROR;
|
|
zOpt = Tcl_GetString(objv[2]);
|
|
for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
|
|
if( strcmp(zOpt, aOpt[i].zOptName)==0 ){
|
|
mask = aOpt[i].mask;
|
|
break;
|
|
}
|
|
}
|
|
if( onoff ) mask = ~mask;
|
|
if( i>=sizeof(aOpt)/sizeof(aOpt[0]) ){
|
|
Tcl_AppendResult(interp, "unknown optimization - should be one of:",
|
|
(char*)0);
|
|
for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
|
|
Tcl_AppendResult(interp, " ", aOpt[i].zOptName, (char*)0);
|
|
}
|
|
return TCL_ERROR;
|
|
}
|
|
sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, mask);
|
|
return TCL_OK;
|
|
}
|
|
|
|
typedef struct sqlite3_api_routines sqlite3_api_routines;
|
|
/*
|
|
** load_static_extension DB NAME ...
|
|
**
|
|
** Load one or more statically linked extensions.
|
|
*/
|
|
static int tclLoadStaticExtensionCmd(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
extern int sqlite3_amatch_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_closure_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_eval_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_fileio_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_fuzzer_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_ieee_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_nextchar_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_percentile_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_series_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_spellfix_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_totype_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
extern int sqlite3_wholenumber_init(sqlite3*,char**,const sqlite3_api_routines*);
|
|
static const struct {
|
|
const char *zExtName;
|
|
int (*pInit)(sqlite3*,char**,const sqlite3_api_routines*);
|
|
} aExtension[] = {
|
|
{ "amatch", sqlite3_amatch_init },
|
|
{ "closure", sqlite3_closure_init },
|
|
{ "eval", sqlite3_eval_init },
|
|
{ "fileio", sqlite3_fileio_init },
|
|
{ "fuzzer", sqlite3_fuzzer_init },
|
|
{ "ieee754", sqlite3_ieee_init },
|
|
{ "nextchar", sqlite3_nextchar_init },
|
|
{ "percentile", sqlite3_percentile_init },
|
|
{ "regexp", sqlite3_regexp_init },
|
|
{ "series", sqlite3_series_init },
|
|
{ "spellfix", sqlite3_spellfix_init },
|
|
{ "totype", sqlite3_totype_init },
|
|
{ "wholenumber", sqlite3_wholenumber_init },
|
|
};
|
|
sqlite3 *db;
|
|
const char *zName;
|
|
int i, j, rc;
|
|
char *zErrMsg = 0;
|
|
if( objc<3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB NAME ...");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
for(j=2; j<objc; j++){
|
|
zName = Tcl_GetString(objv[j]);
|
|
for(i=0; i<ArraySize(aExtension); i++){
|
|
if( strcmp(zName, aExtension[i].zExtName)==0 ) break;
|
|
}
|
|
if( i>=ArraySize(aExtension) ){
|
|
Tcl_AppendResult(interp, "no such extension: ", zName, (char*)0);
|
|
return TCL_ERROR;
|
|
}
|
|
if( aExtension[i].pInit ){
|
|
rc = aExtension[i].pInit(db, &zErrMsg, 0);
|
|
}else{
|
|
rc = SQLITE_OK;
|
|
}
|
|
if( rc!=SQLITE_OK || zErrMsg ){
|
|
Tcl_AppendResult(interp, "initialization of ", zName, " failed: ", zErrMsg,
|
|
(char*)0);
|
|
sqlite3_free(zErrMsg);
|
|
return TCL_ERROR;
|
|
}
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** sorter_test_fakeheap BOOL
|
|
**
|
|
*/
|
|
static int sorter_test_fakeheap(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
int bArg;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( Tcl_GetBooleanFromObj(interp, objv[1], &bArg) ){
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( bArg ){
|
|
if( sqlite3GlobalConfig.pHeap==0 ){
|
|
sqlite3GlobalConfig.pHeap = SQLITE_INT_TO_PTR(-1);
|
|
}
|
|
}else{
|
|
if( sqlite3GlobalConfig.pHeap==SQLITE_INT_TO_PTR(-1) ){
|
|
sqlite3GlobalConfig.pHeap = 0;
|
|
}
|
|
}
|
|
|
|
Tcl_ResetResult(interp);
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
|
|
**
|
|
** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
|
|
** check that the leftmost and rightmost columns returned are both integers,
|
|
** and that both contain the same value.
|
|
**
|
|
** Then execute statement $SQL2. Check that the statement returns the same
|
|
** set of integers in the same order as in the previous step (using $SQL1).
|
|
*/
|
|
static int sorter_test_sort4_helper(
|
|
void * clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
const char *zSql1;
|
|
const char *zSql2;
|
|
int nStep;
|
|
int iStep;
|
|
int iCksum1 = 0;
|
|
int iCksum2 = 0;
|
|
int rc;
|
|
int iB;
|
|
sqlite3 *db;
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=5 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB SQL1 NSTEP SQL2");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
zSql1 = Tcl_GetString(objv[2]);
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &nStep) ) return TCL_ERROR;
|
|
zSql2 = Tcl_GetString(objv[4]);
|
|
|
|
rc = sqlite3_prepare_v2(db, zSql1, -1, &pStmt, 0);
|
|
if( rc!=SQLITE_OK ) goto sql_error;
|
|
|
|
iB = sqlite3_column_count(pStmt)-1;
|
|
for(iStep=0; iStep<nStep && SQLITE_ROW==sqlite3_step(pStmt); iStep++){
|
|
int a = sqlite3_column_int(pStmt, 0);
|
|
if( a!=sqlite3_column_int(pStmt, iB) ){
|
|
Tcl_AppendResult(interp, "data error: (a!=b)", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
iCksum1 += (iCksum1 << 3) + a;
|
|
}
|
|
rc = sqlite3_finalize(pStmt);
|
|
if( rc!=SQLITE_OK ) goto sql_error;
|
|
|
|
rc = sqlite3_prepare_v2(db, zSql2, -1, &pStmt, 0);
|
|
if( rc!=SQLITE_OK ) goto sql_error;
|
|
for(iStep=0; SQLITE_ROW==sqlite3_step(pStmt); iStep++){
|
|
int a = sqlite3_column_int(pStmt, 0);
|
|
iCksum2 += (iCksum2 << 3) + a;
|
|
}
|
|
rc = sqlite3_finalize(pStmt);
|
|
if( rc!=SQLITE_OK ) goto sql_error;
|
|
|
|
if( iCksum1!=iCksum2 ){
|
|
Tcl_AppendResult(interp, "checksum mismatch", 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
return TCL_OK;
|
|
sql_error:
|
|
Tcl_AppendResult(interp, "sql error: ", sqlite3_errmsg(db), 0);
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
|
|
#ifdef SQLITE_USER_AUTHENTICATION
|
|
#include "sqlite3userauth.h"
|
|
/*
|
|
** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD
|
|
*/
|
|
static int test_user_authenticate(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
char *zUser = 0;
|
|
char *zPasswd = 0;
|
|
int nPasswd = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=4 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME PASSWORD");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
zUser = Tcl_GetString(objv[2]);
|
|
zPasswd = Tcl_GetStringFromObj(objv[3], &nPasswd);
|
|
rc = sqlite3_user_authenticate(db, zUser, zPasswd, nPasswd);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_USER_AUTHENTICATION */
|
|
|
|
#ifdef SQLITE_USER_AUTHENTICATION
|
|
/*
|
|
** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN
|
|
*/
|
|
static int test_user_add(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
char *zUser = 0;
|
|
char *zPasswd = 0;
|
|
int nPasswd = 0;
|
|
int isAdmin = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=5 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME PASSWORD ISADMIN");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
zUser = Tcl_GetString(objv[2]);
|
|
zPasswd = Tcl_GetStringFromObj(objv[3], &nPasswd);
|
|
Tcl_GetBooleanFromObj(interp, objv[4], &isAdmin);
|
|
rc = sqlite3_user_add(db, zUser, zPasswd, nPasswd, isAdmin);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_USER_AUTHENTICATION */
|
|
|
|
#ifdef SQLITE_USER_AUTHENTICATION
|
|
/*
|
|
** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN
|
|
*/
|
|
static int test_user_change(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
char *zUser = 0;
|
|
char *zPasswd = 0;
|
|
int nPasswd = 0;
|
|
int isAdmin = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=5 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME PASSWORD ISADMIN");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
zUser = Tcl_GetString(objv[2]);
|
|
zPasswd = Tcl_GetStringFromObj(objv[3], &nPasswd);
|
|
Tcl_GetBooleanFromObj(interp, objv[4], &isAdmin);
|
|
rc = sqlite3_user_change(db, zUser, zPasswd, nPasswd, isAdmin);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_USER_AUTHENTICATION */
|
|
|
|
#ifdef SQLITE_USER_AUTHENTICATION
|
|
/*
|
|
** tclcmd: sqlite3_user_delete DB USERNAME
|
|
*/
|
|
static int test_user_delete(
|
|
ClientData clientData, /* Unused */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
char *zUser = 0;
|
|
sqlite3 *db;
|
|
int rc;
|
|
|
|
if( objc!=3 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB USERNAME");
|
|
return TCL_ERROR;
|
|
}
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
|
return TCL_ERROR;
|
|
}
|
|
zUser = Tcl_GetString(objv[2]);
|
|
rc = sqlite3_user_delete(db, zUser);
|
|
Tcl_SetResult(interp, (char *)t1ErrorName(rc), TCL_STATIC);
|
|
return TCL_OK;
|
|
}
|
|
#endif /* SQLITE_USER_AUTHENTICATION */
|
|
|
|
/*
|
|
** tclcmd: bad_behavior TYPE
|
|
**
|
|
** Do some things that should trigger a valgrind or -fsanitize=undefined
|
|
** warning. This is used to verify that errors and warnings output by those
|
|
** tools are detected by the test scripts.
|
|
**
|
|
** TYPE BEHAVIOR
|
|
** 1 Overflow a signed integer
|
|
** 2 Jump based on an uninitialized variable
|
|
** 3 Read after free
|
|
** 4 Panic
|
|
*/
|
|
static int test_bad_behavior(
|
|
ClientData clientData, /* Pointer to an integer containing zero */
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
int objc, /* Number of arguments */
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
){
|
|
int iType;
|
|
int xyz;
|
|
int i = *(int*)clientData;
|
|
int j;
|
|
int w[10];
|
|
int *a;
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "TYPE");
|
|
return TCL_ERROR;
|
|
}
|
|
if( Tcl_GetIntFromObj(interp, objv[1], &iType) ) return TCL_ERROR;
|
|
switch( iType ){
|
|
case 1: {
|
|
xyz = 0x7fffff00 - i;
|
|
xyz += 0x100;
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(xyz));
|
|
break;
|
|
}
|
|
case 2: {
|
|
w[1] = 5;
|
|
if( w[i]>0 ) w[1]++;
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(w[1]));
|
|
break;
|
|
}
|
|
case 3: {
|
|
a = malloc( sizeof(int)*10 );
|
|
for(j=0; j<10; j++) a[j] = j;
|
|
free(a);
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(a[i]));
|
|
break;
|
|
}
|
|
case 4: {
|
|
Tcl_Panic("Deliberate panic");
|
|
break;
|
|
}
|
|
}
|
|
return TCL_OK;
|
|
}
|
|
|
|
/*
|
|
** tclcmd: register_dbstat_vtab DB
|
|
**
|
|
** Cause the dbstat virtual table to be available on the connection DB
|
|
*/
|
|
static int test_register_dbstat_vtab(
|
|
void *clientData,
|
|
Tcl_Interp *interp,
|
|
int objc,
|
|
Tcl_Obj *CONST objv[]
|
|
){
|
|
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
|
Tcl_AppendResult(interp, "dbstat not available because of "
|
|
"SQLITE_OMIT_VIRTUALTABLE", (void*)0);
|
|
return TCL_ERROR;
|
|
#else
|
|
struct SqliteDb { sqlite3 *db; };
|
|
char *zDb;
|
|
Tcl_CmdInfo cmdInfo;
|
|
|
|
if( objc!=2 ){
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
return TCL_ERROR;
|
|
}
|
|
|
|
zDb = Tcl_GetString(objv[1]);
|
|
if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
|
|
sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
|
|
sqlite3DbstatRegister(db);
|
|
}
|
|
return TCL_OK;
|
|
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
|
}
|
|
|
|
/*
|
|
** Register commands with the TCL interpreter.
|
|
*/
|
|
int Sqlitetest1_Init(Tcl_Interp *interp){
|
|
extern int sqlite3_search_count;
|
|
extern int sqlite3_found_count;
|
|
extern int sqlite3_interrupt_count;
|
|
extern int sqlite3_open_file_count;
|
|
extern int sqlite3_sort_count;
|
|
extern int sqlite3_current_time;
|
|
#if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
|
|
extern int sqlite3_hostid_num;
|
|
#endif
|
|
extern int sqlite3_max_blobsize;
|
|
extern int sqlite3BtreeSharedCacheReport(void*,
|
|
Tcl_Interp*,int,Tcl_Obj*CONST*);
|
|
static int iZero = 0;
|
|
static struct {
|
|
char *zName;
|
|
Tcl_CmdProc *xProc;
|
|
} aCmd[] = {
|
|
{ "db_enter", (Tcl_CmdProc*)db_enter },
|
|
{ "db_leave", (Tcl_CmdProc*)db_leave },
|
|
{ "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int },
|
|
{ "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 },
|
|
{ "sqlite3_mprintf_long", (Tcl_CmdProc*)sqlite3_mprintf_long },
|
|
{ "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str },
|
|
{ "sqlite3_snprintf_str", (Tcl_CmdProc*)sqlite3_snprintf_str },
|
|
{ "sqlite3_mprintf_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly},
|
|
{ "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double },
|
|
{ "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled },
|
|
{ "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble},
|
|
{ "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z },
|
|
{ "sqlite3_mprintf_n_test", (Tcl_CmdProc*)test_mprintf_n },
|
|
{ "sqlite3_snprintf_int", (Tcl_CmdProc*)test_snprintf_int },
|
|
{ "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid },
|
|
{ "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf },
|
|
{ "sqlite3_exec_hex", (Tcl_CmdProc*)test_exec_hex },
|
|
{ "sqlite3_exec", (Tcl_CmdProc*)test_exec },
|
|
{ "sqlite3_exec_nr", (Tcl_CmdProc*)test_exec_nr },
|
|
#ifndef SQLITE_OMIT_GET_TABLE
|
|
{ "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf },
|
|
#endif
|
|
{ "sqlite3_close", (Tcl_CmdProc*)sqlite_test_close },
|
|
{ "sqlite3_close_v2", (Tcl_CmdProc*)sqlite_test_close_v2 },
|
|
{ "sqlite3_create_function", (Tcl_CmdProc*)test_create_function },
|
|
{ "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate },
|
|
{ "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func },
|
|
{ "sqlite_abort", (Tcl_CmdProc*)sqlite_abort },
|
|
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },
|
|
{ "breakpoint", (Tcl_CmdProc*)test_breakpoint },
|
|
{ "sqlite3_key", (Tcl_CmdProc*)test_key },
|
|
{ "sqlite3_rekey", (Tcl_CmdProc*)test_rekey },
|
|
{ "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic },
|
|
{ "sqlite3_interrupt", (Tcl_CmdProc*)test_interrupt },
|
|
{ "sqlite_delete_function", (Tcl_CmdProc*)delete_function },
|
|
{ "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation },
|
|
{ "sqlite3_get_autocommit", (Tcl_CmdProc*)get_autocommit },
|
|
{ "sqlite3_stack_used", (Tcl_CmdProc*)test_stack_used },
|
|
{ "sqlite3_busy_timeout", (Tcl_CmdProc*)test_busy_timeout },
|
|
{ "printf", (Tcl_CmdProc*)test_printf },
|
|
{ "sqlite3IoTrace", (Tcl_CmdProc*)test_io_trace },
|
|
{ "clang_sanitize_address", (Tcl_CmdProc*)clang_sanitize_address },
|
|
};
|
|
static struct {
|
|
char *zName;
|
|
Tcl_ObjCmdProc *xProc;
|
|
void *clientData;
|
|
} aObjCmd[] = {
|
|
{ "bad_behavior", test_bad_behavior, (void*)&iZero },
|
|
{ "register_dbstat_vtab", test_register_dbstat_vtab },
|
|
{ "sqlite3_connection_pointer", get_sqlite_pointer, 0 },
|
|
{ "sqlite3_bind_int", test_bind_int, 0 },
|
|
{ "sqlite3_bind_zeroblob", test_bind_zeroblob, 0 },
|
|
{ "sqlite3_bind_zeroblob64", test_bind_zeroblob64, 0 },
|
|
{ "sqlite3_bind_int64", test_bind_int64, 0 },
|
|
{ "sqlite3_bind_double", test_bind_double, 0 },
|
|
{ "sqlite3_bind_null", test_bind_null ,0 },
|
|
{ "sqlite3_bind_text", test_bind_text ,0 },
|
|
{ "sqlite3_bind_text16", test_bind_text16 ,0 },
|
|
{ "sqlite3_bind_blob", test_bind_blob ,0 },
|
|
{ "sqlite3_bind_parameter_count", test_bind_parameter_count, 0},
|
|
{ "sqlite3_bind_parameter_name", test_bind_parameter_name, 0},
|
|
{ "sqlite3_bind_parameter_index", test_bind_parameter_index, 0},
|
|
{ "sqlite3_clear_bindings", test_clear_bindings, 0},
|
|
{ "sqlite3_sleep", test_sleep, 0},
|
|
{ "sqlite3_errcode", test_errcode ,0 },
|
|
{ "sqlite3_extended_errcode", test_ex_errcode ,0 },
|
|
{ "sqlite3_errmsg", test_errmsg ,0 },
|
|
{ "sqlite3_errmsg16", test_errmsg16 ,0 },
|
|
{ "sqlite3_open", test_open ,0 },
|
|
{ "sqlite3_open16", test_open16 ,0 },
|
|
{ "sqlite3_open_v2", test_open_v2 ,0 },
|
|
{ "sqlite3_complete16", test_complete16 ,0 },
|
|
|
|
{ "sqlite3_prepare", test_prepare ,0 },
|
|
{ "sqlite3_prepare16", test_prepare16 ,0 },
|
|
{ "sqlite3_prepare_v2", test_prepare_v2 ,0 },
|
|
{ "sqlite3_prepare_tkt3134", test_prepare_tkt3134, 0},
|
|
{ "sqlite3_prepare16_v2", test_prepare16_v2 ,0 },
|
|
{ "sqlite3_finalize", test_finalize ,0 },
|
|
{ "sqlite3_stmt_status", test_stmt_status ,0 },
|
|
{ "sqlite3_reset", test_reset ,0 },
|
|
{ "sqlite3_expired", test_expired ,0 },
|
|
{ "sqlite3_transfer_bindings", test_transfer_bind ,0 },
|
|
{ "sqlite3_changes", test_changes ,0 },
|
|
{ "sqlite3_step", test_step ,0 },
|
|
{ "sqlite3_sql", test_sql ,0 },
|
|
{ "sqlite3_next_stmt", test_next_stmt ,0 },
|
|
{ "sqlite3_stmt_readonly", test_stmt_readonly ,0 },
|
|
{ "sqlite3_stmt_busy", test_stmt_busy ,0 },
|
|
{ "uses_stmt_journal", uses_stmt_journal ,0 },
|
|
|
|
{ "sqlite3_release_memory", test_release_memory, 0},
|
|
{ "sqlite3_db_release_memory", test_db_release_memory, 0},
|
|
{ "sqlite3_db_cacheflush", test_db_cacheflush, 0},
|
|
{ "sqlite3_db_filename", test_db_filename, 0},
|
|
{ "sqlite3_db_readonly", test_db_readonly, 0},
|
|
{ "sqlite3_soft_heap_limit", test_soft_heap_limit, 0},
|
|
{ "sqlite3_thread_cleanup", test_thread_cleanup, 0},
|
|
{ "sqlite3_pager_refcounts", test_pager_refcounts, 0},
|
|
|
|
{ "sqlite3_load_extension", test_load_extension, 0},
|
|
{ "sqlite3_enable_load_extension", test_enable_load, 0},
|
|
{ "sqlite3_extended_result_codes", test_extended_result_codes, 0},
|
|
{ "sqlite3_limit", test_limit, 0},
|
|
|
|
{ "save_prng_state", save_prng_state, 0 },
|
|
{ "restore_prng_state", restore_prng_state, 0 },
|
|
{ "reset_prng_state", reset_prng_state, 0 },
|
|
{ "database_never_corrupt", database_never_corrupt, 0},
|
|
{ "database_may_be_corrupt", database_may_be_corrupt, 0},
|
|
{ "optimization_control", optimization_control,0},
|
|
#if SQLITE_OS_WIN
|
|
{ "lock_win32_file", win32_file_lock, 0 },
|
|
{ "exists_win32_path", win32_exists_path, 0 },
|
|
{ "find_win32_file", win32_find_file, 0 },
|
|
{ "delete_win32_file", win32_delete_file, 0 },
|
|
{ "make_win32_dir", win32_mkdir, 0 },
|
|
{ "remove_win32_dir", win32_rmdir, 0 },
|
|
#endif
|
|
{ "tcl_objproc", runAsObjProc, 0 },
|
|
|
|
/* sqlite3_column_*() API */
|
|
{ "sqlite3_column_count", test_column_count ,0 },
|
|
{ "sqlite3_data_count", test_data_count ,0 },
|
|
{ "sqlite3_column_type", test_column_type ,0 },
|
|
{ "sqlite3_column_blob", test_column_blob ,0 },
|
|
{ "sqlite3_column_double", test_column_double ,0 },
|
|
{ "sqlite3_column_int64", test_column_int64 ,0 },
|
|
{ "sqlite3_column_text", test_stmt_utf8, (void*)sqlite3_column_text },
|
|
{ "sqlite3_column_name", test_stmt_utf8, (void*)sqlite3_column_name },
|
|
{ "sqlite3_column_int", test_stmt_int, (void*)sqlite3_column_int },
|
|
{ "sqlite3_column_bytes", test_stmt_int, (void*)sqlite3_column_bytes},
|
|
#ifndef SQLITE_OMIT_DECLTYPE
|
|
{ "sqlite3_column_decltype",test_stmt_utf8,(void*)sqlite3_column_decltype},
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
|
{ "sqlite3_column_database_name",test_stmt_utf8,(void*)sqlite3_column_database_name},
|
|
{ "sqlite3_column_table_name",test_stmt_utf8,(void*)sqlite3_column_table_name},
|
|
{ "sqlite3_column_origin_name",test_stmt_utf8,(void*)sqlite3_column_origin_name},
|
|
#endif
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
{ "sqlite3_column_bytes16", test_stmt_int, (void*)sqlite3_column_bytes16 },
|
|
{ "sqlite3_column_text16", test_stmt_utf16, (void*)sqlite3_column_text16},
|
|
{ "sqlite3_column_name16", test_stmt_utf16, (void*)sqlite3_column_name16},
|
|
{ "add_alignment_test_collations", add_alignment_test_collations, 0 },
|
|
#ifndef SQLITE_OMIT_DECLTYPE
|
|
{ "sqlite3_column_decltype16",test_stmt_utf16,(void*)sqlite3_column_decltype16},
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
|
{"sqlite3_column_database_name16",
|
|
test_stmt_utf16, (void*)sqlite3_column_database_name16},
|
|
{"sqlite3_column_table_name16", test_stmt_utf16, (void*)sqlite3_column_table_name16},
|
|
{"sqlite3_column_origin_name16", test_stmt_utf16, (void*)sqlite3_column_origin_name16},
|
|
#endif
|
|
#endif
|
|
{ "sqlite3_create_collation_v2", test_create_collation_v2, 0 },
|
|
{ "sqlite3_global_recover", test_global_recover, 0 },
|
|
{ "working_64bit_int", working_64bit_int, 0 },
|
|
{ "vfs_unlink_test", vfs_unlink_test, 0 },
|
|
{ "vfs_initfail_test", vfs_initfail_test, 0 },
|
|
{ "vfs_unregister_all", vfs_unregister_all, 0 },
|
|
{ "vfs_reregister_all", vfs_reregister_all, 0 },
|
|
{ "file_control_test", file_control_test, 0 },
|
|
{ "file_control_lasterrno_test", file_control_lasterrno_test, 0 },
|
|
{ "file_control_lockproxy_test", file_control_lockproxy_test, 0 },
|
|
{ "file_control_chunksize_test", file_control_chunksize_test, 0 },
|
|
{ "file_control_sizehint_test", file_control_sizehint_test, 0 },
|
|
#if SQLITE_OS_WIN
|
|
{ "file_control_win32_av_retry", file_control_win32_av_retry, 0 },
|
|
{ "file_control_win32_set_handle", file_control_win32_set_handle, 0 },
|
|
#endif
|
|
{ "file_control_persist_wal", file_control_persist_wal, 0 },
|
|
{ "file_control_powersafe_overwrite",file_control_powersafe_overwrite,0},
|
|
{ "file_control_vfsname", file_control_vfsname, 0 },
|
|
{ "file_control_tempfilename", file_control_tempfilename, 0 },
|
|
{ "sqlite3_vfs_list", vfs_list, 0 },
|
|
{ "sqlite3_create_function_v2", test_create_function_v2, 0 },
|
|
|
|
/* Functions from os.h */
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
{ "add_test_collate", test_collate, 0 },
|
|
{ "add_test_collate_needed", test_collate_needed, 0 },
|
|
{ "add_test_function", test_function, 0 },
|
|
{ "add_test_utf16bin_collate", test_utf16bin_collate, 0 },
|
|
#endif
|
|
{ "sqlite3_test_errstr", test_errstr, 0 },
|
|
{ "tcl_variable_type", tcl_variable_type, 0 },
|
|
#ifndef SQLITE_OMIT_SHARED_CACHE
|
|
{ "sqlite3_enable_shared_cache", test_enable_shared, 0 },
|
|
{ "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport, 0},
|
|
#endif
|
|
{ "sqlite3_libversion_number", test_libversion_number, 0 },
|
|
{ "sqlite3_table_column_metadata", test_table_column_metadata, 0 },
|
|
#ifndef SQLITE_OMIT_INCRBLOB
|
|
{ "sqlite3_blob_reopen", test_blob_reopen, 0 },
|
|
#endif
|
|
{ "pcache_stats", test_pcache_stats, 0 },
|
|
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
|
{ "sqlite3_unlock_notify", test_unlock_notify, 0 },
|
|
#endif
|
|
{ "sqlite3_wal_checkpoint", test_wal_checkpoint, 0 },
|
|
{ "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2, 0 },
|
|
{ "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint, 0 },
|
|
{ "test_sqlite3_log", test_sqlite3_log, 0 },
|
|
#ifndef SQLITE_OMIT_EXPLAIN
|
|
{ "print_explain_query_plan", test_print_eqp, 0 },
|
|
#endif
|
|
{ "sqlite3_test_control", test_test_control },
|
|
#if SQLITE_OS_UNIX
|
|
{ "getrusage", test_getrusage },
|
|
#endif
|
|
{ "load_static_extension", tclLoadStaticExtensionCmd },
|
|
{ "sorter_test_fakeheap", sorter_test_fakeheap },
|
|
{ "sorter_test_sort4_helper", sorter_test_sort4_helper },
|
|
#ifdef SQLITE_USER_AUTHENTICATION
|
|
{ "sqlite3_user_authenticate", test_user_authenticate, 0 },
|
|
{ "sqlite3_user_add", test_user_add, 0 },
|
|
{ "sqlite3_user_change", test_user_change, 0 },
|
|
{ "sqlite3_user_delete", test_user_delete, 0 },
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
|
|
{ "sqlite3_stmt_scanstatus", test_stmt_scanstatus, 0 },
|
|
{ "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset, 0 },
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
{ "sqlite3_config_sqllog", test_config_sqllog, 0 },
|
|
#endif
|
|
{ "vfs_current_time_int64", vfsCurrentTimeInt64, 0 },
|
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
{ "sqlite3_snapshot_get", test_snapshot_get, 0 },
|
|
{ "sqlite3_snapshot_open", test_snapshot_open, 0 },
|
|
{ "sqlite3_snapshot_free", test_snapshot_free, 0 },
|
|
#endif
|
|
};
|
|
static int bitmask_size = sizeof(Bitmask)*8;
|
|
static int longdouble_size = sizeof(LONGDOUBLE_TYPE);
|
|
int i;
|
|
extern int sqlite3_sync_count, sqlite3_fullsync_count;
|
|
extern int sqlite3_opentemp_count;
|
|
extern int sqlite3_like_count;
|
|
extern int sqlite3_xferopt_count;
|
|
extern int sqlite3_pager_readdb_count;
|
|
extern int sqlite3_pager_writedb_count;
|
|
extern int sqlite3_pager_writej_count;
|
|
#if SQLITE_OS_WIN
|
|
extern LONG volatile sqlite3_os_type;
|
|
#endif
|
|
#ifdef SQLITE_DEBUG
|
|
extern int sqlite3WhereTrace;
|
|
extern int sqlite3OSTrace;
|
|
extern int sqlite3WalTrace;
|
|
#endif
|
|
#ifdef SQLITE_TEST
|
|
#ifdef SQLITE_ENABLE_FTS3
|
|
extern int sqlite3_fts3_enable_parentheses;
|
|
#endif
|
|
#endif
|
|
|
|
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
|
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
|
}
|
|
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
|
Tcl_CreateObjCommand(interp, aObjCmd[i].zName,
|
|
aObjCmd[i].xProc, aObjCmd[i].clientData, 0);
|
|
}
|
|
Tcl_LinkVar(interp, "sqlite_search_count",
|
|
(char*)&sqlite3_search_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_found_count",
|
|
(char*)&sqlite3_found_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_sort_count",
|
|
(char*)&sqlite3_sort_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite3_max_blobsize",
|
|
(char*)&sqlite3_max_blobsize, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_like_count",
|
|
(char*)&sqlite3_like_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_interrupt_count",
|
|
(char*)&sqlite3_interrupt_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_open_file_count",
|
|
(char*)&sqlite3_open_file_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_current_time",
|
|
(char*)&sqlite3_current_time, TCL_LINK_INT);
|
|
#if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
|
|
Tcl_LinkVar(interp, "sqlite_hostid_num",
|
|
(char*)&sqlite3_hostid_num, TCL_LINK_INT);
|
|
#endif
|
|
Tcl_LinkVar(interp, "sqlite3_xferopt_count",
|
|
(char*)&sqlite3_xferopt_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite3_pager_readdb_count",
|
|
(char*)&sqlite3_pager_readdb_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite3_pager_writedb_count",
|
|
(char*)&sqlite3_pager_writedb_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite3_pager_writej_count",
|
|
(char*)&sqlite3_pager_writej_count, TCL_LINK_INT);
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
Tcl_LinkVar(interp, "unaligned_string_counter",
|
|
(char*)&unaligned_string_counter, TCL_LINK_INT);
|
|
#endif
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
Tcl_LinkVar(interp, "sqlite_last_needed_collation",
|
|
(char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
|
|
#endif
|
|
#if SQLITE_OS_WIN
|
|
Tcl_LinkVar(interp, "sqlite_os_type",
|
|
(char*)&sqlite3_os_type, TCL_LINK_LONG);
|
|
#endif
|
|
#ifdef SQLITE_TEST
|
|
{
|
|
static const char *query_plan = "*** OBSOLETE VARIABLE ***";
|
|
Tcl_LinkVar(interp, "sqlite_query_plan",
|
|
(char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
|
|
}
|
|
#endif
|
|
#ifdef SQLITE_DEBUG
|
|
Tcl_LinkVar(interp, "sqlite_where_trace",
|
|
(char*)&sqlite3WhereTrace, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_os_trace",
|
|
(char*)&sqlite3OSTrace, TCL_LINK_INT);
|
|
#ifndef SQLITE_OMIT_WAL
|
|
Tcl_LinkVar(interp, "sqlite_wal_trace",
|
|
(char*)&sqlite3WalTrace, TCL_LINK_INT);
|
|
#endif
|
|
#endif
|
|
#ifndef SQLITE_OMIT_DISKIO
|
|
Tcl_LinkVar(interp, "sqlite_opentemp_count",
|
|
(char*)&sqlite3_opentemp_count, TCL_LINK_INT);
|
|
#endif
|
|
Tcl_LinkVar(interp, "sqlite_static_bind_value",
|
|
(char*)&sqlite_static_bind_value, TCL_LINK_STRING);
|
|
Tcl_LinkVar(interp, "sqlite_static_bind_nbyte",
|
|
(char*)&sqlite_static_bind_nbyte, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_temp_directory",
|
|
(char*)&sqlite3_temp_directory, TCL_LINK_STRING);
|
|
Tcl_LinkVar(interp, "sqlite_data_directory",
|
|
(char*)&sqlite3_data_directory, TCL_LINK_STRING);
|
|
Tcl_LinkVar(interp, "bitmask_size",
|
|
(char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
|
|
Tcl_LinkVar(interp, "longdouble_size",
|
|
(char*)&longdouble_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
|
|
Tcl_LinkVar(interp, "sqlite_sync_count",
|
|
(char*)&sqlite3_sync_count, TCL_LINK_INT);
|
|
Tcl_LinkVar(interp, "sqlite_fullsync_count",
|
|
(char*)&sqlite3_fullsync_count, TCL_LINK_INT);
|
|
#if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST)
|
|
Tcl_LinkVar(interp, "sqlite_fts3_enable_parentheses",
|
|
(char*)&sqlite3_fts3_enable_parentheses, TCL_LINK_INT);
|
|
#endif
|
|
return TCL_OK;
|
|
}
|