
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
3953 lines
126 KiB
C
3953 lines
126 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.
|
|
**
|
|
*************************************************************************
|
|
** Main file for the SQLite library. The routines in this file
|
|
** implement the programmer interface to the library. Routines in
|
|
** other files are for internal use by SQLite and should not be
|
|
** accessed by users of the library.
|
|
*/
|
|
#include "sqliteInt.h"
|
|
|
|
#ifdef SQLITE_ENABLE_FTS3
|
|
# include "fts3.h"
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_RTREE
|
|
# include "rtree.h"
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_ICU
|
|
# include "sqliteicu.h"
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_JSON1
|
|
int sqlite3Json1Init(sqlite3*);
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_FTS5
|
|
int sqlite3Fts5Init(sqlite3*);
|
|
#endif
|
|
|
|
#ifndef SQLITE_AMALGAMATION
|
|
/* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
|
|
** contains the text of SQLITE_VERSION macro.
|
|
*/
|
|
const char sqlite3_version[] = SQLITE_VERSION;
|
|
#endif
|
|
|
|
/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
|
|
** a pointer to the to the sqlite3_version[] string constant.
|
|
*/
|
|
const char *sqlite3_libversion(void){ return sqlite3_version; }
|
|
|
|
/* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
|
|
** pointer to a string constant whose value is the same as the
|
|
** SQLITE_SOURCE_ID C preprocessor macro.
|
|
*/
|
|
const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
|
|
|
|
/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
|
|
** returns an integer equal to SQLITE_VERSION_NUMBER.
|
|
*/
|
|
int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
|
|
|
|
/* IMPLEMENTATION-OF: R-20790-14025 The sqlite3_threadsafe() function returns
|
|
** zero if and only if SQLite was compiled with mutexing code omitted due to
|
|
** the SQLITE_THREADSAFE compile-time option being set to 0.
|
|
*/
|
|
int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }
|
|
|
|
/*
|
|
** When compiling the test fixture or with debugging enabled (on Win32),
|
|
** this variable being set to non-zero will cause OSTRACE macros to emit
|
|
** extra diagnostic information.
|
|
*/
|
|
#ifdef SQLITE_HAVE_OS_TRACE
|
|
# ifndef SQLITE_DEBUG_OS_TRACE
|
|
# define SQLITE_DEBUG_OS_TRACE 0
|
|
# endif
|
|
int sqlite3OSTrace = SQLITE_DEBUG_OS_TRACE;
|
|
#endif
|
|
|
|
#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
|
|
/*
|
|
** If the following function pointer is not NULL and if
|
|
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
|
|
** I/O active are written using this function. These messages
|
|
** are intended for debugging activity only.
|
|
*/
|
|
SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;
|
|
#endif
|
|
|
|
/*
|
|
** If the following global variable points to a string which is the
|
|
** name of a directory, then that directory will be used to store
|
|
** temporary files.
|
|
**
|
|
** See also the "PRAGMA temp_store_directory" SQL command.
|
|
*/
|
|
char *sqlite3_temp_directory = 0;
|
|
|
|
/*
|
|
** If the following global variable points to a string which is the
|
|
** name of a directory, then that directory will be used to store
|
|
** all database files specified with a relative pathname.
|
|
**
|
|
** See also the "PRAGMA data_store_directory" SQL command.
|
|
*/
|
|
char *sqlite3_data_directory = 0;
|
|
|
|
/*
|
|
** Initialize SQLite.
|
|
**
|
|
** This routine must be called to initialize the memory allocation,
|
|
** VFS, and mutex subsystems prior to doing any serious work with
|
|
** SQLite. But as long as you do not compile with SQLITE_OMIT_AUTOINIT
|
|
** this routine will be called automatically by key routines such as
|
|
** sqlite3_open().
|
|
**
|
|
** This routine is a no-op except on its very first call for the process,
|
|
** or for the first call after a call to sqlite3_shutdown.
|
|
**
|
|
** The first thread to call this routine runs the initialization to
|
|
** completion. If subsequent threads call this routine before the first
|
|
** thread has finished the initialization process, then the subsequent
|
|
** threads must block until the first thread finishes with the initialization.
|
|
**
|
|
** The first thread might call this routine recursively. Recursive
|
|
** calls to this routine should not block, of course. Otherwise the
|
|
** initialization process would never complete.
|
|
**
|
|
** Let X be the first thread to enter this routine. Let Y be some other
|
|
** thread. Then while the initial invocation of this routine by X is
|
|
** incomplete, it is required that:
|
|
**
|
|
** * Calls to this routine from Y must block until the outer-most
|
|
** call by X completes.
|
|
**
|
|
** * Recursive calls to this routine from thread X return immediately
|
|
** without blocking.
|
|
*/
|
|
int sqlite3_initialize(void){
|
|
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
|
|
int rc; /* Result code */
|
|
#ifdef SQLITE_EXTRA_INIT
|
|
int bRunExtraInit = 0; /* Extra initialization needed */
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_WSD
|
|
rc = sqlite3_wsd_init(4096, 24);
|
|
if( rc!=SQLITE_OK ){
|
|
return rc;
|
|
}
|
|
#endif
|
|
|
|
/* If the following assert() fails on some obscure processor/compiler
|
|
** combination, the work-around is to set the correct pointer
|
|
** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
|
|
assert( SQLITE_PTRSIZE==sizeof(char*) );
|
|
|
|
/* If SQLite is already completely initialized, then this call
|
|
** to sqlite3_initialize() should be a no-op. But the initialization
|
|
** must be complete. So isInit must not be set until the very end
|
|
** of this routine.
|
|
*/
|
|
if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;
|
|
|
|
/* Make sure the mutex subsystem is initialized. If unable to
|
|
** initialize the mutex subsystem, return early with the error.
|
|
** If the system is so sick that we are unable to allocate a mutex,
|
|
** there is not much SQLite is going to be able to do.
|
|
**
|
|
** The mutex subsystem must take care of serializing its own
|
|
** initialization.
|
|
*/
|
|
rc = sqlite3MutexInit();
|
|
if( rc ) return rc;
|
|
|
|
/* Initialize the malloc() system and the recursive pInitMutex mutex.
|
|
** This operation is protected by the STATIC_MASTER mutex. Note that
|
|
** MutexAlloc() is called for a static mutex prior to initializing the
|
|
** malloc subsystem - this implies that the allocation of a static
|
|
** mutex must not require support from the malloc subsystem.
|
|
*/
|
|
MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
|
|
sqlite3_mutex_enter(pMaster);
|
|
sqlite3GlobalConfig.isMutexInit = 1;
|
|
if( !sqlite3GlobalConfig.isMallocInit ){
|
|
rc = sqlite3MallocInit();
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3GlobalConfig.isMallocInit = 1;
|
|
if( !sqlite3GlobalConfig.pInitMutex ){
|
|
sqlite3GlobalConfig.pInitMutex =
|
|
sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
|
|
if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
|
|
rc = SQLITE_NOMEM;
|
|
}
|
|
}
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3GlobalConfig.nRefInitMutex++;
|
|
}
|
|
sqlite3_mutex_leave(pMaster);
|
|
|
|
/* If rc is not SQLITE_OK at this point, then either the malloc
|
|
** subsystem could not be initialized or the system failed to allocate
|
|
** the pInitMutex mutex. Return an error in either case. */
|
|
if( rc!=SQLITE_OK ){
|
|
return rc;
|
|
}
|
|
|
|
/* Do the rest of the initialization under the recursive mutex so
|
|
** that we will be able to handle recursive calls into
|
|
** sqlite3_initialize(). The recursive calls normally come through
|
|
** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
|
|
** recursive calls might also be possible.
|
|
**
|
|
** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
|
|
** to the xInit method, so the xInit method need not be threadsafe.
|
|
**
|
|
** The following mutex is what serializes access to the appdef pcache xInit
|
|
** methods. The sqlite3_pcache_methods.xInit() all is embedded in the
|
|
** call to sqlite3PcacheInitialize().
|
|
*/
|
|
sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
|
|
if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
|
|
FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
|
|
sqlite3GlobalConfig.inProgress = 1;
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
{
|
|
extern void sqlite3_init_sqllog(void);
|
|
sqlite3_init_sqllog();
|
|
}
|
|
#endif
|
|
memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
|
|
sqlite3RegisterGlobalFunctions();
|
|
if( sqlite3GlobalConfig.isPCacheInit==0 ){
|
|
rc = sqlite3PcacheInitialize();
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3GlobalConfig.isPCacheInit = 1;
|
|
rc = sqlite3OsInit();
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
|
|
sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
|
|
sqlite3GlobalConfig.isInit = 1;
|
|
#ifdef SQLITE_EXTRA_INIT
|
|
bRunExtraInit = 1;
|
|
#endif
|
|
}
|
|
sqlite3GlobalConfig.inProgress = 0;
|
|
}
|
|
sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
|
|
|
|
/* Go back under the static mutex and clean up the recursive
|
|
** mutex to prevent a resource leak.
|
|
*/
|
|
sqlite3_mutex_enter(pMaster);
|
|
sqlite3GlobalConfig.nRefInitMutex--;
|
|
if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
|
|
assert( sqlite3GlobalConfig.nRefInitMutex==0 );
|
|
sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
|
|
sqlite3GlobalConfig.pInitMutex = 0;
|
|
}
|
|
sqlite3_mutex_leave(pMaster);
|
|
|
|
/* The following is just a sanity check to make sure SQLite has
|
|
** been compiled correctly. It is important to run this code, but
|
|
** we don't want to run it too often and soak up CPU cycles for no
|
|
** reason. So we run it once during initialization.
|
|
*/
|
|
#ifndef NDEBUG
|
|
#ifndef SQLITE_OMIT_FLOATING_POINT
|
|
/* This section of code's only "output" is via assert() statements. */
|
|
if ( rc==SQLITE_OK ){
|
|
u64 x = (((u64)1)<<63)-1;
|
|
double y;
|
|
assert(sizeof(x)==8);
|
|
assert(sizeof(x)==sizeof(y));
|
|
memcpy(&y, &x, 8);
|
|
assert( sqlite3IsNaN(y) );
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
/* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
|
|
** compile-time option.
|
|
*/
|
|
#ifdef SQLITE_EXTRA_INIT
|
|
if( bRunExtraInit ){
|
|
int SQLITE_EXTRA_INIT(const char*);
|
|
rc = SQLITE_EXTRA_INIT(0);
|
|
}
|
|
#endif
|
|
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Undo the effects of sqlite3_initialize(). Must not be called while
|
|
** there are outstanding database connections or memory allocations or
|
|
** while any part of SQLite is otherwise in use in any thread. This
|
|
** routine is not threadsafe. But it is safe to invoke this routine
|
|
** on when SQLite is already shut down. If SQLite is already shut down
|
|
** when this routine is invoked, then this routine is a harmless no-op.
|
|
*/
|
|
int sqlite3_shutdown(void){
|
|
#ifdef SQLITE_OMIT_WSD
|
|
int rc = sqlite3_wsd_init(4096, 24);
|
|
if( rc!=SQLITE_OK ){
|
|
return rc;
|
|
}
|
|
#endif
|
|
|
|
if( sqlite3GlobalConfig.isInit ){
|
|
#ifdef SQLITE_EXTRA_SHUTDOWN
|
|
void SQLITE_EXTRA_SHUTDOWN(void);
|
|
SQLITE_EXTRA_SHUTDOWN();
|
|
#endif
|
|
sqlite3_os_end();
|
|
sqlite3_reset_auto_extension();
|
|
sqlite3GlobalConfig.isInit = 0;
|
|
}
|
|
if( sqlite3GlobalConfig.isPCacheInit ){
|
|
sqlite3PcacheShutdown();
|
|
sqlite3GlobalConfig.isPCacheInit = 0;
|
|
}
|
|
if( sqlite3GlobalConfig.isMallocInit ){
|
|
sqlite3MallocEnd();
|
|
sqlite3GlobalConfig.isMallocInit = 0;
|
|
|
|
#ifndef SQLITE_OMIT_SHUTDOWN_DIRECTORIES
|
|
/* The heap subsystem has now been shutdown and these values are supposed
|
|
** to be NULL or point to memory that was obtained from sqlite3_malloc(),
|
|
** which would rely on that heap subsystem; therefore, make sure these
|
|
** values cannot refer to heap memory that was just invalidated when the
|
|
** heap subsystem was shutdown. This is only done if the current call to
|
|
** this function resulted in the heap subsystem actually being shutdown.
|
|
*/
|
|
sqlite3_data_directory = 0;
|
|
sqlite3_temp_directory = 0;
|
|
#endif
|
|
}
|
|
if( sqlite3GlobalConfig.isMutexInit ){
|
|
sqlite3MutexEnd();
|
|
sqlite3GlobalConfig.isMutexInit = 0;
|
|
}
|
|
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** This API allows applications to modify the global configuration of
|
|
** the SQLite library at run-time.
|
|
**
|
|
** This routine should only be called when there are no outstanding
|
|
** database connections or memory allocations. This routine is not
|
|
** threadsafe. Failure to heed these warnings can lead to unpredictable
|
|
** behavior.
|
|
*/
|
|
int sqlite3_config(int op, ...){
|
|
va_list ap;
|
|
int rc = SQLITE_OK;
|
|
|
|
/* sqlite3_config() shall return SQLITE_MISUSE if it is invoked while
|
|
** the SQLite library is in use. */
|
|
if( sqlite3GlobalConfig.isInit ) return SQLITE_MISUSE_BKPT;
|
|
|
|
va_start(ap, op);
|
|
switch( op ){
|
|
|
|
/* Mutex configuration options are only available in a threadsafe
|
|
** compile.
|
|
*/
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
|
|
case SQLITE_CONFIG_SINGLETHREAD: {
|
|
/* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
|
|
** Single-thread. */
|
|
sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
|
|
sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
|
|
break;
|
|
}
|
|
#endif
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
|
|
case SQLITE_CONFIG_MULTITHREAD: {
|
|
/* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
|
|
** Multi-thread. */
|
|
sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
|
|
sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
|
|
break;
|
|
}
|
|
#endif
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
|
|
case SQLITE_CONFIG_SERIALIZED: {
|
|
/* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
|
|
** Serialized. */
|
|
sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
|
|
sqlite3GlobalConfig.bFullMutex = 1; /* Enable mutex on connections */
|
|
break;
|
|
}
|
|
#endif
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
|
|
case SQLITE_CONFIG_MUTEX: {
|
|
/* Specify an alternative mutex implementation */
|
|
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
|
|
break;
|
|
}
|
|
#endif
|
|
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
|
|
case SQLITE_CONFIG_GETMUTEX: {
|
|
/* Retrieve the current mutex implementation */
|
|
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
case SQLITE_CONFIG_MALLOC: {
|
|
/* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
|
|
** single argument which is a pointer to an instance of the
|
|
** sqlite3_mem_methods structure. The argument specifies alternative
|
|
** low-level memory allocation routines to be used in place of the memory
|
|
** allocation routines built into SQLite. */
|
|
sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_GETMALLOC: {
|
|
/* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
|
|
** single argument which is a pointer to an instance of the
|
|
** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
|
|
** filled with the currently defined memory allocation routines. */
|
|
if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
|
|
*va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_MEMSTATUS: {
|
|
/* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
|
|
** single argument of type int, interpreted as a boolean, which enables
|
|
** or disables the collection of memory allocation statistics. */
|
|
sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_SCRATCH: {
|
|
/* EVIDENCE-OF: R-08404-60887 There are three arguments to
|
|
** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
|
|
** which the scratch allocations will be drawn, the size of each scratch
|
|
** allocation (sz), and the maximum number of scratch allocations (N). */
|
|
sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
|
|
sqlite3GlobalConfig.szScratch = va_arg(ap, int);
|
|
sqlite3GlobalConfig.nScratch = va_arg(ap, int);
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_PAGECACHE: {
|
|
/* EVIDENCE-OF: R-18761-36601 There are three arguments to
|
|
** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
|
|
** the size of each page cache line (sz), and the number of cache lines
|
|
** (N). */
|
|
sqlite3GlobalConfig.pPage = va_arg(ap, void*);
|
|
sqlite3GlobalConfig.szPage = va_arg(ap, int);
|
|
sqlite3GlobalConfig.nPage = va_arg(ap, int);
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_PCACHE_HDRSZ: {
|
|
/* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
|
|
** a single parameter which is a pointer to an integer and writes into
|
|
** that integer the number of extra bytes per page required for each page
|
|
** in SQLITE_CONFIG_PAGECACHE. */
|
|
*va_arg(ap, int*) =
|
|
sqlite3HeaderSizeBtree() +
|
|
sqlite3HeaderSizePcache() +
|
|
sqlite3HeaderSizePcache1();
|
|
break;
|
|
}
|
|
|
|
case SQLITE_CONFIG_PCACHE: {
|
|
/* no-op */
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_GETPCACHE: {
|
|
/* now an error */
|
|
rc = SQLITE_ERROR;
|
|
break;
|
|
}
|
|
|
|
case SQLITE_CONFIG_PCACHE2: {
|
|
/* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
|
|
** single argument which is a pointer to an sqlite3_pcache_methods2
|
|
** object. This object specifies the interface to a custom page cache
|
|
** implementation. */
|
|
sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
|
|
break;
|
|
}
|
|
case SQLITE_CONFIG_GETPCACHE2: {
|
|
/* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
|
|
** single argument which is a pointer to an sqlite3_pcache_methods2
|
|
** object. SQLite copies of the current page cache implementation into
|
|
** that object. */
|
|
if( sqlite3GlobalConfig.pcache2.xInit==0 ){
|
|
sqlite3PCacheSetDefault();
|
|
}
|
|
*va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
|
|
break;
|
|
}
|
|
|
|
/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
|
|
** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
|
|
** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
|
|
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
|
|
case SQLITE_CONFIG_HEAP: {
|
|
/* EVIDENCE-OF: R-19854-42126 There are three arguments to
|
|
** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
|
|
** number of bytes in the memory buffer, and the minimum allocation size.
|
|
*/
|
|
sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
|
|
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
|
|
sqlite3GlobalConfig.mnReq = va_arg(ap, int);
|
|
|
|
if( sqlite3GlobalConfig.mnReq<1 ){
|
|
sqlite3GlobalConfig.mnReq = 1;
|
|
}else if( sqlite3GlobalConfig.mnReq>(1<<12) ){
|
|
/* cap min request size at 2^12 */
|
|
sqlite3GlobalConfig.mnReq = (1<<12);
|
|
}
|
|
|
|
if( sqlite3GlobalConfig.pHeap==0 ){
|
|
/* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
|
|
** is NULL, then SQLite reverts to using its default memory allocator
|
|
** (the system malloc() implementation), undoing any prior invocation of
|
|
** SQLITE_CONFIG_MALLOC.
|
|
**
|
|
** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
|
|
** revert to its default implementation when sqlite3_initialize() is run
|
|
*/
|
|
memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
|
|
}else{
|
|
/* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
|
|
** alternative memory allocator is engaged to handle all of SQLites
|
|
** memory allocation needs. */
|
|
#ifdef SQLITE_ENABLE_MEMSYS3
|
|
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_MEMSYS5
|
|
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
|
|
#endif
|
|
}
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
case SQLITE_CONFIG_LOOKASIDE: {
|
|
sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
|
|
sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
|
|
break;
|
|
}
|
|
|
|
/* Record a pointer to the logger function and its first argument.
|
|
** The default is NULL. Logging is disabled if the function pointer is
|
|
** NULL.
|
|
*/
|
|
case SQLITE_CONFIG_LOG: {
|
|
/* MSVC is picky about pulling func ptrs from va lists.
|
|
** http://support.microsoft.com/kb/47961
|
|
** sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*));
|
|
*/
|
|
typedef void(*LOGFUNC_t)(void*,int,const char*);
|
|
sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
|
|
sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
|
|
break;
|
|
}
|
|
|
|
/* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
|
|
** can be changed at start-time using the
|
|
** sqlite3_config(SQLITE_CONFIG_URI,1) or
|
|
** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
|
|
*/
|
|
case SQLITE_CONFIG_URI: {
|
|
/* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
|
|
** argument of type int. If non-zero, then URI handling is globally
|
|
** enabled. If the parameter is zero, then URI handling is globally
|
|
** disabled. */
|
|
sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
|
|
break;
|
|
}
|
|
|
|
case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
|
|
/* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
|
|
** option takes a single integer argument which is interpreted as a
|
|
** boolean in order to enable or disable the use of covering indices for
|
|
** full table scans in the query optimizer. */
|
|
sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
|
|
break;
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
case SQLITE_CONFIG_SQLLOG: {
|
|
typedef void(*SQLLOGFUNC_t)(void*, sqlite3*, const char*, int);
|
|
sqlite3GlobalConfig.xSqllog = va_arg(ap, SQLLOGFUNC_t);
|
|
sqlite3GlobalConfig.pSqllogArg = va_arg(ap, void *);
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
case SQLITE_CONFIG_MMAP_SIZE: {
|
|
/* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
|
|
** integer (sqlite3_int64) values that are the default mmap size limit
|
|
** (the default setting for PRAGMA mmap_size) and the maximum allowed
|
|
** mmap size limit. */
|
|
sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
|
|
sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
|
|
/* EVIDENCE-OF: R-53367-43190 If either argument to this option is
|
|
** negative, then that argument is changed to its compile-time default.
|
|
**
|
|
** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
|
|
** silently truncated if necessary so that it does not exceed the
|
|
** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
|
|
** compile-time option.
|
|
*/
|
|
if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
|
|
mxMmap = SQLITE_MAX_MMAP_SIZE;
|
|
}
|
|
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
|
|
if( szMmap>mxMmap) szMmap = mxMmap;
|
|
sqlite3GlobalConfig.mxMmap = mxMmap;
|
|
sqlite3GlobalConfig.szMmap = szMmap;
|
|
break;
|
|
}
|
|
|
|
#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
|
|
case SQLITE_CONFIG_WIN32_HEAPSIZE: {
|
|
/* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
|
|
** unsigned integer value that specifies the maximum size of the created
|
|
** heap. */
|
|
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
case SQLITE_CONFIG_PMASZ: {
|
|
sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
|
|
break;
|
|
}
|
|
|
|
default: {
|
|
rc = SQLITE_ERROR;
|
|
break;
|
|
}
|
|
}
|
|
va_end(ap);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Set up the lookaside buffers for a database connection.
|
|
** Return SQLITE_OK on success.
|
|
** If lookaside is already active, return SQLITE_BUSY.
|
|
**
|
|
** The sz parameter is the number of bytes in each lookaside slot.
|
|
** The cnt parameter is the number of slots. If pStart is NULL the
|
|
** space for the lookaside memory is obtained from sqlite3_malloc().
|
|
** If pStart is not NULL then it is sz*cnt bytes of memory to use for
|
|
** the lookaside memory.
|
|
*/
|
|
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
|
|
#ifndef SQLITE_OMIT_LOOKASIDE
|
|
void *pStart;
|
|
if( db->lookaside.nOut ){
|
|
return SQLITE_BUSY;
|
|
}
|
|
/* Free any existing lookaside buffer for this handle before
|
|
** allocating a new one so we don't have to have space for
|
|
** both at the same time.
|
|
*/
|
|
if( db->lookaside.bMalloced ){
|
|
sqlite3_free(db->lookaside.pStart);
|
|
}
|
|
/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
|
|
** than a pointer to be useful.
|
|
*/
|
|
sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
|
|
if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
|
|
if( cnt<0 ) cnt = 0;
|
|
if( sz==0 || cnt==0 ){
|
|
sz = 0;
|
|
pStart = 0;
|
|
}else if( pBuf==0 ){
|
|
sqlite3BeginBenignMalloc();
|
|
pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
|
|
sqlite3EndBenignMalloc();
|
|
if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
|
|
}else{
|
|
pStart = pBuf;
|
|
}
|
|
db->lookaside.pStart = pStart;
|
|
db->lookaside.pFree = 0;
|
|
db->lookaside.sz = (u16)sz;
|
|
if( pStart ){
|
|
int i;
|
|
LookasideSlot *p;
|
|
assert( sz > (int)sizeof(LookasideSlot*) );
|
|
p = (LookasideSlot*)pStart;
|
|
for(i=cnt-1; i>=0; i--){
|
|
p->pNext = db->lookaside.pFree;
|
|
db->lookaside.pFree = p;
|
|
p = (LookasideSlot*)&((u8*)p)[sz];
|
|
}
|
|
db->lookaside.pEnd = p;
|
|
db->lookaside.bDisable = 0;
|
|
db->lookaside.bMalloced = pBuf==0 ?1:0;
|
|
}else{
|
|
db->lookaside.pStart = db;
|
|
db->lookaside.pEnd = db;
|
|
db->lookaside.bDisable = 1;
|
|
db->lookaside.bMalloced = 0;
|
|
}
|
|
#endif /* SQLITE_OMIT_LOOKASIDE */
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Return the mutex associated with a database connection.
|
|
*/
|
|
sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
return db->mutex;
|
|
}
|
|
|
|
/*
|
|
** Free up as much memory as we can from the given database
|
|
** connection.
|
|
*/
|
|
int sqlite3_db_release_memory(sqlite3 *db){
|
|
int i;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
sqlite3BtreeEnterAll(db);
|
|
for(i=0; i<db->nDb; i++){
|
|
Btree *pBt = db->aDb[i].pBt;
|
|
if( pBt ){
|
|
Pager *pPager = sqlite3BtreePager(pBt);
|
|
sqlite3PagerShrink(pPager);
|
|
}
|
|
}
|
|
sqlite3BtreeLeaveAll(db);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Flush any dirty pages in the pager-cache for any attached database
|
|
** to disk.
|
|
*/
|
|
int sqlite3_db_cacheflush(sqlite3 *db){
|
|
int i;
|
|
int rc = SQLITE_OK;
|
|
int bSeenBusy = 0;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
sqlite3BtreeEnterAll(db);
|
|
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
|
Btree *pBt = db->aDb[i].pBt;
|
|
if( pBt && sqlite3BtreeIsInTrans(pBt) ){
|
|
Pager *pPager = sqlite3BtreePager(pBt);
|
|
rc = sqlite3PagerFlush(pPager);
|
|
if( rc==SQLITE_BUSY ){
|
|
bSeenBusy = 1;
|
|
rc = SQLITE_OK;
|
|
}
|
|
}
|
|
}
|
|
sqlite3BtreeLeaveAll(db);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return ((rc==SQLITE_OK && bSeenBusy) ? SQLITE_BUSY : rc);
|
|
}
|
|
|
|
/*
|
|
** Configuration settings for an individual database connection
|
|
*/
|
|
int sqlite3_db_config(sqlite3 *db, int op, ...){
|
|
va_list ap;
|
|
int rc;
|
|
va_start(ap, op);
|
|
switch( op ){
|
|
case SQLITE_DBCONFIG_LOOKASIDE: {
|
|
void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
|
|
int sz = va_arg(ap, int); /* IMP: R-47871-25994 */
|
|
int cnt = va_arg(ap, int); /* IMP: R-04460-53386 */
|
|
rc = setupLookaside(db, pBuf, sz, cnt);
|
|
break;
|
|
}
|
|
default: {
|
|
static const struct {
|
|
int op; /* The opcode */
|
|
u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
|
|
} aFlagOp[] = {
|
|
{ SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
|
|
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
|
|
};
|
|
unsigned int i;
|
|
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
|
|
for(i=0; i<ArraySize(aFlagOp); i++){
|
|
if( aFlagOp[i].op==op ){
|
|
int onoff = va_arg(ap, int);
|
|
int *pRes = va_arg(ap, int*);
|
|
int oldFlags = db->flags;
|
|
if( onoff>0 ){
|
|
db->flags |= aFlagOp[i].mask;
|
|
}else if( onoff==0 ){
|
|
db->flags &= ~aFlagOp[i].mask;
|
|
}
|
|
if( oldFlags!=db->flags ){
|
|
sqlite3ExpirePreparedStatements(db);
|
|
}
|
|
if( pRes ){
|
|
*pRes = (db->flags & aFlagOp[i].mask)!=0;
|
|
}
|
|
rc = SQLITE_OK;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
va_end(ap);
|
|
return rc;
|
|
}
|
|
|
|
|
|
/*
|
|
** Return true if the buffer z[0..n-1] contains all spaces.
|
|
*/
|
|
static int allSpaces(const char *z, int n){
|
|
while( n>0 && z[n-1]==' ' ){ n--; }
|
|
return n==0;
|
|
}
|
|
|
|
/*
|
|
** This is the default collating function named "BINARY" which is always
|
|
** available.
|
|
**
|
|
** If the padFlag argument is not NULL then space padding at the end
|
|
** of strings is ignored. This implements the RTRIM collation.
|
|
*/
|
|
static int binCollFunc(
|
|
void *padFlag,
|
|
int nKey1, const void *pKey1,
|
|
int nKey2, const void *pKey2
|
|
){
|
|
int rc, n;
|
|
n = nKey1<nKey2 ? nKey1 : nKey2;
|
|
/* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
|
|
** strings byte by byte using the memcmp() function from the standard C
|
|
** library. */
|
|
rc = memcmp(pKey1, pKey2, n);
|
|
if( rc==0 ){
|
|
if( padFlag
|
|
&& allSpaces(((char*)pKey1)+n, nKey1-n)
|
|
&& allSpaces(((char*)pKey2)+n, nKey2-n)
|
|
){
|
|
/* EVIDENCE-OF: R-31624-24737 RTRIM is like BINARY except that extra
|
|
** spaces at the end of either string do not change the result. In other
|
|
** words, strings will compare equal to one another as long as they
|
|
** differ only in the number of spaces at the end.
|
|
*/
|
|
}else{
|
|
rc = nKey1 - nKey2;
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Another built-in collating sequence: NOCASE.
|
|
**
|
|
** This collating sequence is intended to be used for "case independent
|
|
** comparison". SQLite's knowledge of upper and lower case equivalents
|
|
** extends only to the 26 characters used in the English language.
|
|
**
|
|
** At the moment there is only a UTF-8 implementation.
|
|
*/
|
|
static int nocaseCollatingFunc(
|
|
void *NotUsed,
|
|
int nKey1, const void *pKey1,
|
|
int nKey2, const void *pKey2
|
|
){
|
|
int r = sqlite3StrNICmp(
|
|
(const char *)pKey1, (const char *)pKey2, (nKey1<nKey2)?nKey1:nKey2);
|
|
UNUSED_PARAMETER(NotUsed);
|
|
if( 0==r ){
|
|
r = nKey1-nKey2;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
/*
|
|
** Return the ROWID of the most recent insert
|
|
*/
|
|
sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
return db->lastRowid;
|
|
}
|
|
|
|
/*
|
|
** Return the number of changes in the most recent call to sqlite3_exec().
|
|
*/
|
|
int sqlite3_changes(sqlite3 *db){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
return db->nChange;
|
|
}
|
|
|
|
/*
|
|
** Return the number of changes since the database handle was opened.
|
|
*/
|
|
int sqlite3_total_changes(sqlite3 *db){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
return db->nTotalChange;
|
|
}
|
|
|
|
/*
|
|
** Close all open savepoints. This function only manipulates fields of the
|
|
** database handle object, it does not close any savepoints that may be open
|
|
** at the b-tree/pager level.
|
|
*/
|
|
void sqlite3CloseSavepoints(sqlite3 *db){
|
|
while( db->pSavepoint ){
|
|
Savepoint *pTmp = db->pSavepoint;
|
|
db->pSavepoint = pTmp->pNext;
|
|
sqlite3DbFree(db, pTmp);
|
|
}
|
|
db->nSavepoint = 0;
|
|
db->nStatement = 0;
|
|
db->isTransactionSavepoint = 0;
|
|
}
|
|
|
|
/*
|
|
** Invoke the destructor function associated with FuncDef p, if any. Except,
|
|
** if this is not the last copy of the function, do not invoke it. Multiple
|
|
** copies of a single function are created when create_function() is called
|
|
** with SQLITE_ANY as the encoding.
|
|
*/
|
|
static void functionDestroy(sqlite3 *db, FuncDef *p){
|
|
FuncDestructor *pDestructor = p->pDestructor;
|
|
if( pDestructor ){
|
|
pDestructor->nRef--;
|
|
if( pDestructor->nRef==0 ){
|
|
pDestructor->xDestroy(pDestructor->pUserData);
|
|
sqlite3DbFree(db, pDestructor);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
** Disconnect all sqlite3_vtab objects that belong to database connection
|
|
** db. This is called when db is being closed.
|
|
*/
|
|
static void disconnectAllVtab(sqlite3 *db){
|
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
int i;
|
|
HashElem *p;
|
|
sqlite3BtreeEnterAll(db);
|
|
for(i=0; i<db->nDb; i++){
|
|
Schema *pSchema = db->aDb[i].pSchema;
|
|
if( db->aDb[i].pSchema ){
|
|
for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
|
|
Table *pTab = (Table *)sqliteHashData(p);
|
|
if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
|
|
}
|
|
}
|
|
}
|
|
for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
|
|
Module *pMod = (Module *)sqliteHashData(p);
|
|
if( pMod->pEpoTab ){
|
|
sqlite3VtabDisconnect(db, pMod->pEpoTab);
|
|
}
|
|
}
|
|
sqlite3VtabUnlockList(db);
|
|
sqlite3BtreeLeaveAll(db);
|
|
#else
|
|
UNUSED_PARAMETER(db);
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
** Return TRUE if database connection db has unfinalized prepared
|
|
** statements or unfinished sqlite3_backup objects.
|
|
*/
|
|
static int connectionIsBusy(sqlite3 *db){
|
|
int j;
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
|
if( db->pVdbe ) return 1;
|
|
for(j=0; j<db->nDb; j++){
|
|
Btree *pBt = db->aDb[j].pBt;
|
|
if( pBt && sqlite3BtreeIsInBackup(pBt) ) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** Close an existing SQLite database
|
|
*/
|
|
static int sqlite3Close(sqlite3 *db, int forceZombie){
|
|
if( !db ){
|
|
/* EVIDENCE-OF: R-63257-11740 Calling sqlite3_close() or
|
|
** sqlite3_close_v2() with a NULL pointer argument is a harmless no-op. */
|
|
return SQLITE_OK;
|
|
}
|
|
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
/* Force xDisconnect calls on all virtual tables */
|
|
disconnectAllVtab(db);
|
|
|
|
/* If a transaction is open, the disconnectAllVtab() call above
|
|
** will not have called the xDisconnect() method on any virtual
|
|
** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
|
|
** call will do so. We need to do this before the check for active
|
|
** SQL statements below, as the v-table implementation may be storing
|
|
** some prepared statements internally.
|
|
*/
|
|
sqlite3VtabRollback(db);
|
|
|
|
/* Legacy behavior (sqlite3_close() behavior) is to return
|
|
** SQLITE_BUSY if the connection can not be closed immediately.
|
|
*/
|
|
if( !forceZombie && connectionIsBusy(db) ){
|
|
sqlite3ErrorWithMsg(db, SQLITE_BUSY, "unable to close due to unfinalized "
|
|
"statements or unfinished backups");
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return SQLITE_BUSY;
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
if( sqlite3GlobalConfig.xSqllog ){
|
|
/* Closing the handle. Fourth parameter is passed the value 2. */
|
|
sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2);
|
|
}
|
|
#endif
|
|
|
|
/* Convert the connection into a zombie and then close it.
|
|
*/
|
|
db->magic = SQLITE_MAGIC_ZOMBIE;
|
|
sqlite3LeaveMutexAndCloseZombie(db);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Two variations on the public interface for closing a database
|
|
** connection. The sqlite3_close() version returns SQLITE_BUSY and
|
|
** leaves the connection option if there are unfinalized prepared
|
|
** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
|
|
** version forces the connection to become a zombie if there are
|
|
** unclosed resources, and arranges for deallocation when the last
|
|
** prepare statement or sqlite3_backup closes.
|
|
*/
|
|
int sqlite3_close(sqlite3 *db){ return sqlite3Close(db,0); }
|
|
int sqlite3_close_v2(sqlite3 *db){ return sqlite3Close(db,1); }
|
|
|
|
|
|
/*
|
|
** Close the mutex on database connection db.
|
|
**
|
|
** Furthermore, if database connection db is a zombie (meaning that there
|
|
** has been a prior call to sqlite3_close(db) or sqlite3_close_v2(db)) and
|
|
** every sqlite3_stmt has now been finalized and every sqlite3_backup has
|
|
** finished, then free all resources.
|
|
*/
|
|
void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
|
|
HashElem *i; /* Hash table iterator */
|
|
int j;
|
|
|
|
/* If there are outstanding sqlite3_stmt or sqlite3_backup objects
|
|
** or if the connection has not yet been closed by sqlite3_close_v2(),
|
|
** then just leave the mutex and return.
|
|
*/
|
|
if( db->magic!=SQLITE_MAGIC_ZOMBIE || connectionIsBusy(db) ){
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return;
|
|
}
|
|
|
|
/* If we reach this point, it means that the database connection has
|
|
** closed all sqlite3_stmt and sqlite3_backup objects and has been
|
|
** passed to sqlite3_close (meaning that it is a zombie). Therefore,
|
|
** go ahead and free all resources.
|
|
*/
|
|
|
|
/* If a transaction is open, roll it back. This also ensures that if
|
|
** any database schemas have been modified by an uncommitted transaction
|
|
** they are reset. And that the required b-tree mutex is held to make
|
|
** the pager rollback and schema reset an atomic operation. */
|
|
sqlite3RollbackAll(db, SQLITE_OK);
|
|
|
|
/* Free any outstanding Savepoint structures. */
|
|
sqlite3CloseSavepoints(db);
|
|
|
|
/* Close all database connections */
|
|
for(j=0; j<db->nDb; j++){
|
|
struct Db *pDb = &db->aDb[j];
|
|
if( pDb->pBt ){
|
|
sqlite3BtreeClose(pDb->pBt);
|
|
pDb->pBt = 0;
|
|
if( j!=1 ){
|
|
pDb->pSchema = 0;
|
|
}
|
|
}
|
|
}
|
|
/* Clear the TEMP schema separately and last */
|
|
if( db->aDb[1].pSchema ){
|
|
sqlite3SchemaClear(db->aDb[1].pSchema);
|
|
}
|
|
sqlite3VtabUnlockList(db);
|
|
|
|
/* Free up the array of auxiliary databases */
|
|
sqlite3CollapseDatabaseArray(db);
|
|
assert( db->nDb<=2 );
|
|
assert( db->aDb==db->aDbStatic );
|
|
|
|
/* Tell the code in notify.c that the connection no longer holds any
|
|
** locks and does not require any further unlock-notify callbacks.
|
|
*/
|
|
sqlite3ConnectionClosed(db);
|
|
|
|
for(j=0; j<ArraySize(db->aFunc.a); j++){
|
|
FuncDef *pNext, *pHash, *p;
|
|
for(p=db->aFunc.a[j]; p; p=pHash){
|
|
pHash = p->pHash;
|
|
while( p ){
|
|
functionDestroy(db, p);
|
|
pNext = p->pNext;
|
|
sqlite3DbFree(db, p);
|
|
p = pNext;
|
|
}
|
|
}
|
|
}
|
|
for(i=sqliteHashFirst(&db->aCollSeq); i; i=sqliteHashNext(i)){
|
|
CollSeq *pColl = (CollSeq *)sqliteHashData(i);
|
|
/* Invoke any destructors registered for collation sequence user data. */
|
|
for(j=0; j<3; j++){
|
|
if( pColl[j].xDel ){
|
|
pColl[j].xDel(pColl[j].pUser);
|
|
}
|
|
}
|
|
sqlite3DbFree(db, pColl);
|
|
}
|
|
sqlite3HashClear(&db->aCollSeq);
|
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
|
|
Module *pMod = (Module *)sqliteHashData(i);
|
|
if( pMod->xDestroy ){
|
|
pMod->xDestroy(pMod->pAux);
|
|
}
|
|
sqlite3VtabEponymousTableClear(db, pMod);
|
|
sqlite3DbFree(db, pMod);
|
|
}
|
|
sqlite3HashClear(&db->aModule);
|
|
#endif
|
|
|
|
sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
|
|
sqlite3ValueFree(db->pErr);
|
|
sqlite3CloseExtensions(db);
|
|
#if SQLITE_USER_AUTHENTICATION
|
|
sqlite3_free(db->auth.zAuthUser);
|
|
sqlite3_free(db->auth.zAuthPW);
|
|
#endif
|
|
|
|
db->magic = SQLITE_MAGIC_ERROR;
|
|
|
|
/* The temp-database schema is allocated differently from the other schema
|
|
** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
|
|
** So it needs to be freed here. Todo: Why not roll the temp schema into
|
|
** the same sqliteMalloc() as the one that allocates the database
|
|
** structure?
|
|
*/
|
|
sqlite3DbFree(db, db->aDb[1].pSchema);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
db->magic = SQLITE_MAGIC_CLOSED;
|
|
sqlite3_mutex_free(db->mutex);
|
|
assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
|
|
if( db->lookaside.bMalloced ){
|
|
sqlite3_free(db->lookaside.pStart);
|
|
}
|
|
sqlite3_free(db);
|
|
}
|
|
|
|
/*
|
|
** Rollback all database files. If tripCode is not SQLITE_OK, then
|
|
** any write cursors are invalidated ("tripped" - as in "tripping a circuit
|
|
** breaker") and made to return tripCode if there are any further
|
|
** attempts to use that cursor. Read cursors remain open and valid
|
|
** but are "saved" in case the table pages are moved around.
|
|
*/
|
|
void sqlite3RollbackAll(sqlite3 *db, int tripCode){
|
|
int i;
|
|
int inTrans = 0;
|
|
int schemaChange;
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
|
sqlite3BeginBenignMalloc();
|
|
|
|
/* Obtain all b-tree mutexes before making any calls to BtreeRollback().
|
|
** This is important in case the transaction being rolled back has
|
|
** modified the database schema. If the b-tree mutexes are not taken
|
|
** here, then another shared-cache connection might sneak in between
|
|
** the database rollback and schema reset, which can cause false
|
|
** corruption reports in some cases. */
|
|
sqlite3BtreeEnterAll(db);
|
|
schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
|
|
|
|
for(i=0; i<db->nDb; i++){
|
|
Btree *p = db->aDb[i].pBt;
|
|
if( p ){
|
|
if( sqlite3BtreeIsInTrans(p) ){
|
|
inTrans = 1;
|
|
}
|
|
sqlite3BtreeRollback(p, tripCode, !schemaChange);
|
|
}
|
|
}
|
|
sqlite3VtabRollback(db);
|
|
sqlite3EndBenignMalloc();
|
|
|
|
if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
|
|
sqlite3ExpirePreparedStatements(db);
|
|
sqlite3ResetAllSchemasOfConnection(db);
|
|
}
|
|
sqlite3BtreeLeaveAll(db);
|
|
|
|
/* Any deferred constraint violations have now been resolved. */
|
|
db->nDeferredCons = 0;
|
|
db->nDeferredImmCons = 0;
|
|
db->flags &= ~SQLITE_DeferFKs;
|
|
|
|
/* If one has been configured, invoke the rollback-hook callback */
|
|
if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){
|
|
db->xRollbackCallback(db->pRollbackArg);
|
|
}
|
|
}
|
|
|
|
/*
|
|
** Return a static string containing the name corresponding to the error code
|
|
** specified in the argument.
|
|
*/
|
|
#if defined(SQLITE_NEED_ERR_NAME)
|
|
const char *sqlite3ErrName(int rc){
|
|
const char *zName = 0;
|
|
int i, origRc = rc;
|
|
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
|
|
switch( rc ){
|
|
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
|
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
|
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
|
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
|
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
|
case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break;
|
|
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
|
case SQLITE_BUSY_RECOVERY: zName = "SQLITE_BUSY_RECOVERY"; break;
|
|
case SQLITE_BUSY_SNAPSHOT: zName = "SQLITE_BUSY_SNAPSHOT"; break;
|
|
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
|
case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
|
|
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
|
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
|
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
|
|
case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
|
|
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
|
|
case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
|
|
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
|
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
|
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
|
|
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
|
|
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
|
|
case SQLITE_IOERR_FSYNC: zName = "SQLITE_IOERR_FSYNC"; break;
|
|
case SQLITE_IOERR_DIR_FSYNC: zName = "SQLITE_IOERR_DIR_FSYNC"; break;
|
|
case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break;
|
|
case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break;
|
|
case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break;
|
|
case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break;
|
|
case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break;
|
|
case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break;
|
|
case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break;
|
|
case SQLITE_IOERR_CHECKRESERVEDLOCK:
|
|
zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
|
|
case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break;
|
|
case SQLITE_IOERR_CLOSE: zName = "SQLITE_IOERR_CLOSE"; break;
|
|
case SQLITE_IOERR_DIR_CLOSE: zName = "SQLITE_IOERR_DIR_CLOSE"; break;
|
|
case SQLITE_IOERR_SHMOPEN: zName = "SQLITE_IOERR_SHMOPEN"; break;
|
|
case SQLITE_IOERR_SHMSIZE: zName = "SQLITE_IOERR_SHMSIZE"; break;
|
|
case SQLITE_IOERR_SHMLOCK: zName = "SQLITE_IOERR_SHMLOCK"; break;
|
|
case SQLITE_IOERR_SHMMAP: zName = "SQLITE_IOERR_SHMMAP"; break;
|
|
case SQLITE_IOERR_SEEK: zName = "SQLITE_IOERR_SEEK"; break;
|
|
case SQLITE_IOERR_DELETE_NOENT: zName = "SQLITE_IOERR_DELETE_NOENT";break;
|
|
case SQLITE_IOERR_MMAP: zName = "SQLITE_IOERR_MMAP"; break;
|
|
case SQLITE_IOERR_GETTEMPPATH: zName = "SQLITE_IOERR_GETTEMPPATH"; break;
|
|
case SQLITE_IOERR_CONVPATH: zName = "SQLITE_IOERR_CONVPATH"; break;
|
|
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
|
case SQLITE_CORRUPT_VTAB: zName = "SQLITE_CORRUPT_VTAB"; break;
|
|
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
|
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
|
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
|
case SQLITE_CANTOPEN_NOTEMPDIR: zName = "SQLITE_CANTOPEN_NOTEMPDIR";break;
|
|
case SQLITE_CANTOPEN_ISDIR: zName = "SQLITE_CANTOPEN_ISDIR"; break;
|
|
case SQLITE_CANTOPEN_FULLPATH: zName = "SQLITE_CANTOPEN_FULLPATH"; break;
|
|
case SQLITE_CANTOPEN_CONVPATH: zName = "SQLITE_CANTOPEN_CONVPATH"; break;
|
|
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
|
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
|
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
|
case SQLITE_TOOBIG: zName = "SQLITE_TOOBIG"; break;
|
|
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
|
case SQLITE_CONSTRAINT_UNIQUE: zName = "SQLITE_CONSTRAINT_UNIQUE"; break;
|
|
case SQLITE_CONSTRAINT_TRIGGER: zName = "SQLITE_CONSTRAINT_TRIGGER";break;
|
|
case SQLITE_CONSTRAINT_FOREIGNKEY:
|
|
zName = "SQLITE_CONSTRAINT_FOREIGNKEY"; break;
|
|
case SQLITE_CONSTRAINT_CHECK: zName = "SQLITE_CONSTRAINT_CHECK"; break;
|
|
case SQLITE_CONSTRAINT_PRIMARYKEY:
|
|
zName = "SQLITE_CONSTRAINT_PRIMARYKEY"; break;
|
|
case SQLITE_CONSTRAINT_NOTNULL: zName = "SQLITE_CONSTRAINT_NOTNULL";break;
|
|
case SQLITE_CONSTRAINT_COMMITHOOK:
|
|
zName = "SQLITE_CONSTRAINT_COMMITHOOK"; break;
|
|
case SQLITE_CONSTRAINT_VTAB: zName = "SQLITE_CONSTRAINT_VTAB"; break;
|
|
case SQLITE_CONSTRAINT_FUNCTION:
|
|
zName = "SQLITE_CONSTRAINT_FUNCTION"; break;
|
|
case SQLITE_CONSTRAINT_ROWID: zName = "SQLITE_CONSTRAINT_ROWID"; break;
|
|
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
|
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
|
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
|
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
|
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
|
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
|
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
|
|
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
|
case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
|
|
case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
|
|
case SQLITE_NOTICE_RECOVER_ROLLBACK:
|
|
zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
|
|
case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
|
|
case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
|
|
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
|
}
|
|
}
|
|
if( zName==0 ){
|
|
static char zBuf[50];
|
|
sqlite3_snprintf(sizeof(zBuf), zBuf, "SQLITE_UNKNOWN(%d)", origRc);
|
|
zName = zBuf;
|
|
}
|
|
return zName;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** Return a static string that describes the kind of error specified in the
|
|
** argument.
|
|
*/
|
|
const char *sqlite3ErrStr(int rc){
|
|
static const char* const aMsg[] = {
|
|
/* SQLITE_OK */ "not an error",
|
|
/* SQLITE_ERROR */ "SQL logic error or missing database",
|
|
/* SQLITE_INTERNAL */ 0,
|
|
/* SQLITE_PERM */ "access permission denied",
|
|
/* SQLITE_ABORT */ "callback requested query abort",
|
|
/* SQLITE_BUSY */ "database is locked",
|
|
/* SQLITE_LOCKED */ "database table is locked",
|
|
/* SQLITE_NOMEM */ "out of memory",
|
|
/* SQLITE_READONLY */ "attempt to write a readonly database",
|
|
/* SQLITE_INTERRUPT */ "interrupted",
|
|
/* SQLITE_IOERR */ "disk I/O error",
|
|
/* SQLITE_CORRUPT */ "database disk image is malformed",
|
|
/* SQLITE_NOTFOUND */ "unknown operation",
|
|
/* SQLITE_FULL */ "database or disk is full",
|
|
/* SQLITE_CANTOPEN */ "unable to open database file",
|
|
/* SQLITE_PROTOCOL */ "locking protocol",
|
|
/* SQLITE_EMPTY */ "table contains no data",
|
|
/* SQLITE_SCHEMA */ "database schema has changed",
|
|
/* SQLITE_TOOBIG */ "string or blob too big",
|
|
/* SQLITE_CONSTRAINT */ "constraint failed",
|
|
/* SQLITE_MISMATCH */ "datatype mismatch",
|
|
/* SQLITE_MISUSE */ "library routine called out of sequence",
|
|
/* SQLITE_NOLFS */ "large file support is disabled",
|
|
/* SQLITE_AUTH */ "authorization denied",
|
|
/* SQLITE_FORMAT */ "auxiliary database format error",
|
|
/* SQLITE_RANGE */ "bind or column index out of range",
|
|
/* SQLITE_NOTADB */ "file is encrypted or is not a database",
|
|
};
|
|
const char *zErr = "unknown error";
|
|
switch( rc ){
|
|
case SQLITE_ABORT_ROLLBACK: {
|
|
zErr = "abort due to ROLLBACK";
|
|
break;
|
|
}
|
|
default: {
|
|
rc &= 0xff;
|
|
if( ALWAYS(rc>=0) && rc<ArraySize(aMsg) && aMsg[rc]!=0 ){
|
|
zErr = aMsg[rc];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return zErr;
|
|
}
|
|
|
|
/*
|
|
** This routine implements a busy callback that sleeps and tries
|
|
** again until a timeout value is reached. The timeout value is
|
|
** an integer number of milliseconds passed in as the first
|
|
** argument.
|
|
*/
|
|
static int sqliteDefaultBusyCallback(
|
|
void *ptr, /* Database connection */
|
|
int count /* Number of times table has been busy */
|
|
){
|
|
#if SQLITE_OS_WIN || HAVE_USLEEP
|
|
static const u8 delays[] =
|
|
{ 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 };
|
|
static const u8 totals[] =
|
|
{ 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 };
|
|
# define NDELAY ArraySize(delays)
|
|
sqlite3 *db = (sqlite3 *)ptr;
|
|
int timeout = db->busyTimeout;
|
|
int delay, prior;
|
|
|
|
assert( count>=0 );
|
|
if( count < NDELAY ){
|
|
delay = delays[count];
|
|
prior = totals[count];
|
|
}else{
|
|
delay = delays[NDELAY-1];
|
|
prior = totals[NDELAY-1] + delay*(count-(NDELAY-1));
|
|
}
|
|
if( prior + delay > timeout ){
|
|
delay = timeout - prior;
|
|
if( delay<=0 ) return 0;
|
|
}
|
|
sqlite3OsSleep(db->pVfs, delay*1000);
|
|
return 1;
|
|
#else
|
|
sqlite3 *db = (sqlite3 *)ptr;
|
|
int timeout = ((sqlite3 *)ptr)->busyTimeout;
|
|
if( (count+1)*1000 > timeout ){
|
|
return 0;
|
|
}
|
|
sqlite3OsSleep(db->pVfs, 1000000);
|
|
return 1;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
** Invoke the given busy handler.
|
|
**
|
|
** This routine is called when an operation failed with a lock.
|
|
** If this routine returns non-zero, the lock is retried. If it
|
|
** returns 0, the operation aborts with an SQLITE_BUSY error.
|
|
*/
|
|
int sqlite3InvokeBusyHandler(BusyHandler *p){
|
|
int rc;
|
|
if( NEVER(p==0) || p->xFunc==0 || p->nBusy<0 ) return 0;
|
|
rc = p->xFunc(p->pArg, p->nBusy);
|
|
if( rc==0 ){
|
|
p->nBusy = -1;
|
|
}else{
|
|
p->nBusy++;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** This routine sets the busy callback for an Sqlite database to the
|
|
** given callback function with the given argument.
|
|
*/
|
|
int sqlite3_busy_handler(
|
|
sqlite3 *db,
|
|
int (*xBusy)(void*,int),
|
|
void *pArg
|
|
){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
db->busyHandler.xFunc = xBusy;
|
|
db->busyHandler.pArg = pArg;
|
|
db->busyHandler.nBusy = 0;
|
|
db->busyTimeout = 0;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
|
|
/*
|
|
** This routine sets the progress callback for an Sqlite database to the
|
|
** given callback function with the given argument. The progress callback will
|
|
** be invoked every nOps opcodes.
|
|
*/
|
|
void sqlite3_progress_handler(
|
|
sqlite3 *db,
|
|
int nOps,
|
|
int (*xProgress)(void*),
|
|
void *pArg
|
|
){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( nOps>0 ){
|
|
db->xProgress = xProgress;
|
|
db->nProgressOps = (unsigned)nOps;
|
|
db->pProgressArg = pArg;
|
|
}else{
|
|
db->xProgress = 0;
|
|
db->nProgressOps = 0;
|
|
db->pProgressArg = 0;
|
|
}
|
|
sqlite3_mutex_leave(db->mutex);
|
|
}
|
|
#endif
|
|
|
|
|
|
/*
|
|
** This routine installs a default busy handler that waits for the
|
|
** specified number of milliseconds before returning 0.
|
|
*/
|
|
int sqlite3_busy_timeout(sqlite3 *db, int ms){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
if( ms>0 ){
|
|
sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
|
|
db->busyTimeout = ms;
|
|
}else{
|
|
sqlite3_busy_handler(db, 0, 0);
|
|
}
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Cause any pending operation to stop at its earliest opportunity.
|
|
*/
|
|
void sqlite3_interrupt(sqlite3 *db){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return;
|
|
}
|
|
#endif
|
|
db->u1.isInterrupted = 1;
|
|
}
|
|
|
|
|
|
/*
|
|
** This function is exactly the same as sqlite3_create_function(), except
|
|
** that it is designed to be called by internal code. The difference is
|
|
** that if a malloc() fails in sqlite3_create_function(), an error code
|
|
** is returned and the mallocFailed flag cleared.
|
|
*/
|
|
int sqlite3CreateFunc(
|
|
sqlite3 *db,
|
|
const char *zFunctionName,
|
|
int nArg,
|
|
int enc,
|
|
void *pUserData,
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
|
void (*xFinal)(sqlite3_context*),
|
|
FuncDestructor *pDestructor
|
|
){
|
|
FuncDef *p;
|
|
int nName;
|
|
int extraFlags;
|
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
|
if( zFunctionName==0 ||
|
|
(xSFunc && (xFinal || xStep)) ||
|
|
(!xSFunc && (xFinal && !xStep)) ||
|
|
(!xSFunc && (!xFinal && xStep)) ||
|
|
(nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
|
|
(255<(nName = sqlite3Strlen30( zFunctionName))) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
|
|
assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
|
|
extraFlags = enc & SQLITE_DETERMINISTIC;
|
|
enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/* If SQLITE_UTF16 is specified as the encoding type, transform this
|
|
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
|
|
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
|
|
**
|
|
** If SQLITE_ANY is specified, add three versions of the function
|
|
** to the hash table.
|
|
*/
|
|
if( enc==SQLITE_UTF16 ){
|
|
enc = SQLITE_UTF16NATIVE;
|
|
}else if( enc==SQLITE_ANY ){
|
|
int rc;
|
|
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
|
|
pUserData, xSFunc, xStep, xFinal, pDestructor);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
|
|
pUserData, xSFunc, xStep, xFinal, pDestructor);
|
|
}
|
|
if( rc!=SQLITE_OK ){
|
|
return rc;
|
|
}
|
|
enc = SQLITE_UTF16BE;
|
|
}
|
|
#else
|
|
enc = SQLITE_UTF8;
|
|
#endif
|
|
|
|
/* Check if an existing function is being overridden or deleted. If so,
|
|
** and there are active VMs, then return SQLITE_BUSY. If a function
|
|
** is being overridden/deleted but there are no active VMs, allow the
|
|
** operation to continue but invalidate all precompiled statements.
|
|
*/
|
|
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
|
|
if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
|
|
if( db->nVdbeActive ){
|
|
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
|
"unable to delete/modify user-function due to active statements");
|
|
assert( !db->mallocFailed );
|
|
return SQLITE_BUSY;
|
|
}else{
|
|
sqlite3ExpirePreparedStatements(db);
|
|
}
|
|
}
|
|
|
|
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
|
|
assert(p || db->mallocFailed);
|
|
if( !p ){
|
|
return SQLITE_NOMEM;
|
|
}
|
|
|
|
/* If an older version of the function with a configured destructor is
|
|
** being replaced invoke the destructor function here. */
|
|
functionDestroy(db, p);
|
|
|
|
if( pDestructor ){
|
|
pDestructor->nRef++;
|
|
}
|
|
p->pDestructor = pDestructor;
|
|
p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
|
|
testcase( p->funcFlags & SQLITE_DETERMINISTIC );
|
|
p->xSFunc = xSFunc ? xSFunc : xStep;
|
|
p->xFinalize = xFinal;
|
|
p->pUserData = pUserData;
|
|
p->nArg = (u16)nArg;
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Create new user functions.
|
|
*/
|
|
int sqlite3_create_function(
|
|
sqlite3 *db,
|
|
const char *zFunc,
|
|
int nArg,
|
|
int enc,
|
|
void *p,
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
|
void (*xFinal)(sqlite3_context*)
|
|
){
|
|
return sqlite3_create_function_v2(db, zFunc, nArg, enc, p, xSFunc, xStep,
|
|
xFinal, 0);
|
|
}
|
|
|
|
int sqlite3_create_function_v2(
|
|
sqlite3 *db,
|
|
const char *zFunc,
|
|
int nArg,
|
|
int enc,
|
|
void *p,
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value **),
|
|
void (*xFinal)(sqlite3_context*),
|
|
void (*xDestroy)(void *)
|
|
){
|
|
int rc = SQLITE_ERROR;
|
|
FuncDestructor *pArg = 0;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( xDestroy ){
|
|
pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
|
|
if( !pArg ){
|
|
xDestroy(p);
|
|
goto out;
|
|
}
|
|
pArg->xDestroy = xDestroy;
|
|
pArg->pUserData = p;
|
|
}
|
|
rc = sqlite3CreateFunc(db, zFunc, nArg, enc, p, xSFunc, xStep, xFinal, pArg);
|
|
if( pArg && pArg->nRef==0 ){
|
|
assert( rc!=SQLITE_OK );
|
|
xDestroy(p);
|
|
sqlite3DbFree(db, pArg);
|
|
}
|
|
|
|
out:
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
int sqlite3_create_function16(
|
|
sqlite3 *db,
|
|
const void *zFunctionName,
|
|
int nArg,
|
|
int eTextRep,
|
|
void *p,
|
|
void (*xSFunc)(sqlite3_context*,int,sqlite3_value**),
|
|
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
|
void (*xFinal)(sqlite3_context*)
|
|
){
|
|
int rc;
|
|
char *zFunc8;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
assert( !db->mallocFailed );
|
|
zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
|
|
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xSFunc,xStep,xFinal,0);
|
|
sqlite3DbFree(db, zFunc8);
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
#endif
|
|
|
|
|
|
/*
|
|
** Declare that a function has been overloaded by a virtual table.
|
|
**
|
|
** If the function already exists as a regular global function, then
|
|
** this routine is a no-op. If the function does not exist, then create
|
|
** a new one that always throws a run-time error.
|
|
**
|
|
** When virtual tables intend to provide an overloaded function, they
|
|
** should call this routine to make sure the global function exists.
|
|
** A global function must exist in order for name resolution to work
|
|
** properly.
|
|
*/
|
|
int sqlite3_overload_function(
|
|
sqlite3 *db,
|
|
const char *zName,
|
|
int nArg
|
|
){
|
|
int nName = sqlite3Strlen30(zName);
|
|
int rc = SQLITE_OK;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
|
|
rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
|
|
0, sqlite3InvalidFunction, 0, 0, 0);
|
|
}
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_TRACE
|
|
/*
|
|
** Register a trace function. The pArg from the previously registered trace
|
|
** is returned.
|
|
**
|
|
** A NULL trace function means that no tracing is executes. A non-NULL
|
|
** trace is a pointer to a function that is invoked at the start of each
|
|
** SQL statement.
|
|
*/
|
|
void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
|
|
void *pOld;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pOld = db->pTraceArg;
|
|
db->xTrace = xTrace;
|
|
db->pTraceArg = pArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return pOld;
|
|
}
|
|
/*
|
|
** Register a profile function. The pArg from the previously registered
|
|
** profile function is returned.
|
|
**
|
|
** A NULL profile function means that no profiling is executes. A non-NULL
|
|
** profile is a pointer to a function that is invoked at the conclusion of
|
|
** each SQL statement that is run.
|
|
*/
|
|
void *sqlite3_profile(
|
|
sqlite3 *db,
|
|
void (*xProfile)(void*,const char*,sqlite_uint64),
|
|
void *pArg
|
|
){
|
|
void *pOld;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pOld = db->pProfileArg;
|
|
db->xProfile = xProfile;
|
|
db->pProfileArg = pArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return pOld;
|
|
}
|
|
#endif /* SQLITE_OMIT_TRACE */
|
|
|
|
/*
|
|
** Register a function to be invoked when a transaction commits.
|
|
** If the invoked function returns non-zero, then the commit becomes a
|
|
** rollback.
|
|
*/
|
|
void *sqlite3_commit_hook(
|
|
sqlite3 *db, /* Attach the hook to this database */
|
|
int (*xCallback)(void*), /* Function to invoke on each commit */
|
|
void *pArg /* Argument to the function */
|
|
){
|
|
void *pOld;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pOld = db->pCommitArg;
|
|
db->xCommitCallback = xCallback;
|
|
db->pCommitArg = pArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return pOld;
|
|
}
|
|
|
|
/*
|
|
** Register a callback to be invoked each time a row is updated,
|
|
** inserted or deleted using this database connection.
|
|
*/
|
|
void *sqlite3_update_hook(
|
|
sqlite3 *db, /* Attach the hook to this database */
|
|
void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
|
|
void *pArg /* Argument to the function */
|
|
){
|
|
void *pRet;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pRet = db->pUpdateArg;
|
|
db->xUpdateCallback = xCallback;
|
|
db->pUpdateArg = pArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return pRet;
|
|
}
|
|
|
|
/*
|
|
** Register a callback to be invoked each time a transaction is rolled
|
|
** back by this database connection.
|
|
*/
|
|
void *sqlite3_rollback_hook(
|
|
sqlite3 *db, /* Attach the hook to this database */
|
|
void (*xCallback)(void*), /* Callback function */
|
|
void *pArg /* Argument to the function */
|
|
){
|
|
void *pRet;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pRet = db->pRollbackArg;
|
|
db->xRollbackCallback = xCallback;
|
|
db->pRollbackArg = pArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return pRet;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_WAL
|
|
/*
|
|
** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
|
|
** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
|
|
** is greater than sqlite3.pWalArg cast to an integer (the value configured by
|
|
** wal_autocheckpoint()).
|
|
*/
|
|
int sqlite3WalDefaultHook(
|
|
void *pClientData, /* Argument */
|
|
sqlite3 *db, /* Connection */
|
|
const char *zDb, /* Database */
|
|
int nFrame /* Size of WAL */
|
|
){
|
|
if( nFrame>=SQLITE_PTR_TO_INT(pClientData) ){
|
|
sqlite3BeginBenignMalloc();
|
|
sqlite3_wal_checkpoint(db, zDb);
|
|
sqlite3EndBenignMalloc();
|
|
}
|
|
return SQLITE_OK;
|
|
}
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
|
|
/*
|
|
** Configure an sqlite3_wal_hook() callback to automatically checkpoint
|
|
** a database after committing a transaction if there are nFrame or
|
|
** more frames in the log file. Passing zero or a negative value as the
|
|
** nFrame parameter disables automatic checkpoints entirely.
|
|
**
|
|
** The callback registered by this function replaces any existing callback
|
|
** registered using sqlite3_wal_hook(). Likewise, registering a callback
|
|
** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
|
|
** configured by this function.
|
|
*/
|
|
int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
|
|
#ifdef SQLITE_OMIT_WAL
|
|
UNUSED_PARAMETER(db);
|
|
UNUSED_PARAMETER(nFrame);
|
|
#else
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
if( nFrame>0 ){
|
|
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
|
|
}else{
|
|
sqlite3_wal_hook(db, 0, 0);
|
|
}
|
|
#endif
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Register a callback to be invoked each time a transaction is written
|
|
** into the write-ahead-log by this database connection.
|
|
*/
|
|
void *sqlite3_wal_hook(
|
|
sqlite3 *db, /* Attach the hook to this db handle */
|
|
int(*xCallback)(void *, sqlite3*, const char*, int),
|
|
void *pArg /* First argument passed to xCallback() */
|
|
){
|
|
#ifndef SQLITE_OMIT_WAL
|
|
void *pRet;
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pRet = db->pWalArg;
|
|
db->xWalCallback = xCallback;
|
|
db->pWalArg = pArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return pRet;
|
|
#else
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
** Checkpoint database zDb.
|
|
*/
|
|
int sqlite3_wal_checkpoint_v2(
|
|
sqlite3 *db, /* Database handle */
|
|
const char *zDb, /* Name of attached database (or NULL) */
|
|
int eMode, /* SQLITE_CHECKPOINT_* value */
|
|
int *pnLog, /* OUT: Size of WAL log in frames */
|
|
int *pnCkpt /* OUT: Total number of frames checkpointed */
|
|
){
|
|
#ifdef SQLITE_OMIT_WAL
|
|
return SQLITE_OK;
|
|
#else
|
|
int rc; /* Return code */
|
|
int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
|
|
/* Initialize the output variables to -1 in case an error occurs. */
|
|
if( pnLog ) *pnLog = -1;
|
|
if( pnCkpt ) *pnCkpt = -1;
|
|
|
|
assert( SQLITE_CHECKPOINT_PASSIVE==0 );
|
|
assert( SQLITE_CHECKPOINT_FULL==1 );
|
|
assert( SQLITE_CHECKPOINT_RESTART==2 );
|
|
assert( SQLITE_CHECKPOINT_TRUNCATE==3 );
|
|
if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){
|
|
/* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
|
|
** mode: */
|
|
return SQLITE_MISUSE;
|
|
}
|
|
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( zDb && zDb[0] ){
|
|
iDb = sqlite3FindDbName(db, zDb);
|
|
}
|
|
if( iDb<0 ){
|
|
rc = SQLITE_ERROR;
|
|
sqlite3ErrorWithMsg(db, SQLITE_ERROR, "unknown database: %s", zDb);
|
|
}else{
|
|
db->busyHandler.nBusy = 0;
|
|
rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt);
|
|
sqlite3Error(db, rc);
|
|
}
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
#endif
|
|
}
|
|
|
|
|
|
/*
|
|
** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
|
|
** to contains a zero-length string, all attached databases are
|
|
** checkpointed.
|
|
*/
|
|
int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
|
|
/* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to
|
|
** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
|
|
return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_WAL
|
|
/*
|
|
** Run a checkpoint on database iDb. This is a no-op if database iDb is
|
|
** not currently open in WAL mode.
|
|
**
|
|
** If a transaction is open on the database being checkpointed, this
|
|
** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
|
|
** an error occurs while running the checkpoint, an SQLite error code is
|
|
** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
|
|
**
|
|
** The mutex on database handle db should be held by the caller. The mutex
|
|
** associated with the specific b-tree being checkpointed is taken by
|
|
** this function while the checkpoint is running.
|
|
**
|
|
** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
|
|
** checkpointed. If an error is encountered it is returned immediately -
|
|
** no attempt is made to checkpoint any remaining databases.
|
|
**
|
|
** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
|
|
*/
|
|
int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
|
|
int rc = SQLITE_OK; /* Return code */
|
|
int i; /* Used to iterate through attached dbs */
|
|
int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
|
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
|
assert( !pnLog || *pnLog==-1 );
|
|
assert( !pnCkpt || *pnCkpt==-1 );
|
|
|
|
for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
|
|
if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
|
|
rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt, eMode, pnLog, pnCkpt);
|
|
pnLog = 0;
|
|
pnCkpt = 0;
|
|
if( rc==SQLITE_BUSY ){
|
|
bBusy = 1;
|
|
rc = SQLITE_OK;
|
|
}
|
|
}
|
|
}
|
|
|
|
return (rc==SQLITE_OK && bBusy) ? SQLITE_BUSY : rc;
|
|
}
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
|
|
/*
|
|
** This function returns true if main-memory should be used instead of
|
|
** a temporary file for transient pager files and statement journals.
|
|
** The value returned depends on the value of db->temp_store (runtime
|
|
** parameter) and the compile time value of SQLITE_TEMP_STORE. The
|
|
** following table describes the relationship between these two values
|
|
** and this functions return value.
|
|
**
|
|
** SQLITE_TEMP_STORE db->temp_store Location of temporary database
|
|
** ----------------- -------------- ------------------------------
|
|
** 0 any file (return 0)
|
|
** 1 1 file (return 0)
|
|
** 1 2 memory (return 1)
|
|
** 1 0 file (return 0)
|
|
** 2 1 file (return 0)
|
|
** 2 2 memory (return 1)
|
|
** 2 0 memory (return 1)
|
|
** 3 any memory (return 1)
|
|
*/
|
|
int sqlite3TempInMemory(const sqlite3 *db){
|
|
#if SQLITE_TEMP_STORE==1
|
|
return ( db->temp_store==2 );
|
|
#endif
|
|
#if SQLITE_TEMP_STORE==2
|
|
return ( db->temp_store!=1 );
|
|
#endif
|
|
#if SQLITE_TEMP_STORE==3
|
|
UNUSED_PARAMETER(db);
|
|
return 1;
|
|
#endif
|
|
#if SQLITE_TEMP_STORE<1 || SQLITE_TEMP_STORE>3
|
|
UNUSED_PARAMETER(db);
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
** Return UTF-8 encoded English language explanation of the most recent
|
|
** error.
|
|
*/
|
|
const char *sqlite3_errmsg(sqlite3 *db){
|
|
const char *z;
|
|
if( !db ){
|
|
return sqlite3ErrStr(SQLITE_NOMEM);
|
|
}
|
|
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
|
return sqlite3ErrStr(SQLITE_MISUSE_BKPT);
|
|
}
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( db->mallocFailed ){
|
|
z = sqlite3ErrStr(SQLITE_NOMEM);
|
|
}else{
|
|
testcase( db->pErr==0 );
|
|
z = (char*)sqlite3_value_text(db->pErr);
|
|
assert( !db->mallocFailed );
|
|
if( z==0 ){
|
|
z = sqlite3ErrStr(db->errCode);
|
|
}
|
|
}
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return z;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/*
|
|
** Return UTF-16 encoded English language explanation of the most recent
|
|
** error.
|
|
*/
|
|
const void *sqlite3_errmsg16(sqlite3 *db){
|
|
static const u16 outOfMem[] = {
|
|
'o', 'u', 't', ' ', 'o', 'f', ' ', 'm', 'e', 'm', 'o', 'r', 'y', 0
|
|
};
|
|
static const u16 misuse[] = {
|
|
'l', 'i', 'b', 'r', 'a', 'r', 'y', ' ',
|
|
'r', 'o', 'u', 't', 'i', 'n', 'e', ' ',
|
|
'c', 'a', 'l', 'l', 'e', 'd', ' ',
|
|
'o', 'u', 't', ' ',
|
|
'o', 'f', ' ',
|
|
's', 'e', 'q', 'u', 'e', 'n', 'c', 'e', 0
|
|
};
|
|
|
|
const void *z;
|
|
if( !db ){
|
|
return (void *)outOfMem;
|
|
}
|
|
if( !sqlite3SafetyCheckSickOrOk(db) ){
|
|
return (void *)misuse;
|
|
}
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( db->mallocFailed ){
|
|
z = (void *)outOfMem;
|
|
}else{
|
|
z = sqlite3_value_text16(db->pErr);
|
|
if( z==0 ){
|
|
sqlite3ErrorWithMsg(db, db->errCode, sqlite3ErrStr(db->errCode));
|
|
z = sqlite3_value_text16(db->pErr);
|
|
}
|
|
/* A malloc() may have failed within the call to sqlite3_value_text16()
|
|
** above. If this is the case, then the db->mallocFailed flag needs to
|
|
** be cleared before returning. Do this directly, instead of via
|
|
** sqlite3ApiExit(), to avoid setting the database handle error message.
|
|
*/
|
|
sqlite3OomClear(db);
|
|
}
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return z;
|
|
}
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
|
|
/*
|
|
** Return the most recent error code generated by an SQLite routine. If NULL is
|
|
** passed to this function, we assume a malloc() failed during sqlite3_open().
|
|
*/
|
|
int sqlite3_errcode(sqlite3 *db){
|
|
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
if( !db || db->mallocFailed ){
|
|
return SQLITE_NOMEM;
|
|
}
|
|
return db->errCode & db->errMask;
|
|
}
|
|
int sqlite3_extended_errcode(sqlite3 *db){
|
|
if( db && !sqlite3SafetyCheckSickOrOk(db) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
if( !db || db->mallocFailed ){
|
|
return SQLITE_NOMEM;
|
|
}
|
|
return db->errCode;
|
|
}
|
|
|
|
/*
|
|
** Return a string that describes the kind of error specified in the
|
|
** argument. For now, this simply calls the internal sqlite3ErrStr()
|
|
** function.
|
|
*/
|
|
const char *sqlite3_errstr(int rc){
|
|
return sqlite3ErrStr(rc);
|
|
}
|
|
|
|
/*
|
|
** Create a new collating function for database "db". The name is zName
|
|
** and the encoding is enc.
|
|
*/
|
|
static int createCollation(
|
|
sqlite3* db,
|
|
const char *zName,
|
|
u8 enc,
|
|
void* pCtx,
|
|
int(*xCompare)(void*,int,const void*,int,const void*),
|
|
void(*xDel)(void*)
|
|
){
|
|
CollSeq *pColl;
|
|
int enc2;
|
|
|
|
assert( sqlite3_mutex_held(db->mutex) );
|
|
|
|
/* If SQLITE_UTF16 is specified as the encoding type, transform this
|
|
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
|
|
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
|
|
*/
|
|
enc2 = enc;
|
|
testcase( enc2==SQLITE_UTF16 );
|
|
testcase( enc2==SQLITE_UTF16_ALIGNED );
|
|
if( enc2==SQLITE_UTF16 || enc2==SQLITE_UTF16_ALIGNED ){
|
|
enc2 = SQLITE_UTF16NATIVE;
|
|
}
|
|
if( enc2<SQLITE_UTF8 || enc2>SQLITE_UTF16BE ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
|
|
/* Check if this call is removing or replacing an existing collation
|
|
** sequence. If so, and there are active VMs, return busy. If there
|
|
** are no active VMs, invalidate any pre-compiled statements.
|
|
*/
|
|
pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
|
|
if( pColl && pColl->xCmp ){
|
|
if( db->nVdbeActive ){
|
|
sqlite3ErrorWithMsg(db, SQLITE_BUSY,
|
|
"unable to delete/modify collation sequence due to active statements");
|
|
return SQLITE_BUSY;
|
|
}
|
|
sqlite3ExpirePreparedStatements(db);
|
|
|
|
/* If collation sequence pColl was created directly by a call to
|
|
** sqlite3_create_collation, and not generated by synthCollSeq(),
|
|
** then any copies made by synthCollSeq() need to be invalidated.
|
|
** Also, collation destructor - CollSeq.xDel() - function may need
|
|
** to be called.
|
|
*/
|
|
if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
|
|
CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
|
|
int j;
|
|
for(j=0; j<3; j++){
|
|
CollSeq *p = &aColl[j];
|
|
if( p->enc==pColl->enc ){
|
|
if( p->xDel ){
|
|
p->xDel(p->pUser);
|
|
}
|
|
p->xCmp = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
|
|
if( pColl==0 ) return SQLITE_NOMEM;
|
|
pColl->xCmp = xCompare;
|
|
pColl->pUser = pCtx;
|
|
pColl->xDel = xDel;
|
|
pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED));
|
|
sqlite3Error(db, SQLITE_OK);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
|
|
/*
|
|
** This array defines hard upper bounds on limit values. The
|
|
** initializer must be kept in sync with the SQLITE_LIMIT_*
|
|
** #defines in sqlite3.h.
|
|
*/
|
|
static const int aHardLimit[] = {
|
|
SQLITE_MAX_LENGTH,
|
|
SQLITE_MAX_SQL_LENGTH,
|
|
SQLITE_MAX_COLUMN,
|
|
SQLITE_MAX_EXPR_DEPTH,
|
|
SQLITE_MAX_COMPOUND_SELECT,
|
|
SQLITE_MAX_VDBE_OP,
|
|
SQLITE_MAX_FUNCTION_ARG,
|
|
SQLITE_MAX_ATTACHED,
|
|
SQLITE_MAX_LIKE_PATTERN_LENGTH,
|
|
SQLITE_MAX_VARIABLE_NUMBER, /* IMP: R-38091-32352 */
|
|
SQLITE_MAX_TRIGGER_DEPTH,
|
|
SQLITE_MAX_WORKER_THREADS,
|
|
};
|
|
|
|
/*
|
|
** Make sure the hard limits are set to reasonable values
|
|
*/
|
|
#if SQLITE_MAX_LENGTH<100
|
|
# error SQLITE_MAX_LENGTH must be at least 100
|
|
#endif
|
|
#if SQLITE_MAX_SQL_LENGTH<100
|
|
# error SQLITE_MAX_SQL_LENGTH must be at least 100
|
|
#endif
|
|
#if SQLITE_MAX_SQL_LENGTH>SQLITE_MAX_LENGTH
|
|
# error SQLITE_MAX_SQL_LENGTH must not be greater than SQLITE_MAX_LENGTH
|
|
#endif
|
|
#if SQLITE_MAX_COMPOUND_SELECT<2
|
|
# error SQLITE_MAX_COMPOUND_SELECT must be at least 2
|
|
#endif
|
|
#if SQLITE_MAX_VDBE_OP<40
|
|
# error SQLITE_MAX_VDBE_OP must be at least 40
|
|
#endif
|
|
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
|
|
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
|
|
#endif
|
|
#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>125
|
|
# error SQLITE_MAX_ATTACHED must be between 0 and 125
|
|
#endif
|
|
#if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
|
|
# error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
|
|
#endif
|
|
#if SQLITE_MAX_COLUMN>32767
|
|
# error SQLITE_MAX_COLUMN must not exceed 32767
|
|
#endif
|
|
#if SQLITE_MAX_TRIGGER_DEPTH<1
|
|
# error SQLITE_MAX_TRIGGER_DEPTH must be at least 1
|
|
#endif
|
|
#if SQLITE_MAX_WORKER_THREADS<0 || SQLITE_MAX_WORKER_THREADS>50
|
|
# error SQLITE_MAX_WORKER_THREADS must be between 0 and 50
|
|
#endif
|
|
|
|
|
|
/*
|
|
** Change the value of a limit. Report the old value.
|
|
** If an invalid limit index is supplied, report -1.
|
|
** Make no changes but still report the old value if the
|
|
** new limit is negative.
|
|
**
|
|
** A new lower limit does not shrink existing constructs.
|
|
** It merely prevents new constructs that exceed the limit
|
|
** from forming.
|
|
*/
|
|
int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
|
|
int oldLimit;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return -1;
|
|
}
|
|
#endif
|
|
|
|
/* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
|
|
** there is a hard upper bound set at compile-time by a C preprocessor
|
|
** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
|
|
** "_MAX_".)
|
|
*/
|
|
assert( aHardLimit[SQLITE_LIMIT_LENGTH]==SQLITE_MAX_LENGTH );
|
|
assert( aHardLimit[SQLITE_LIMIT_SQL_LENGTH]==SQLITE_MAX_SQL_LENGTH );
|
|
assert( aHardLimit[SQLITE_LIMIT_COLUMN]==SQLITE_MAX_COLUMN );
|
|
assert( aHardLimit[SQLITE_LIMIT_EXPR_DEPTH]==SQLITE_MAX_EXPR_DEPTH );
|
|
assert( aHardLimit[SQLITE_LIMIT_COMPOUND_SELECT]==SQLITE_MAX_COMPOUND_SELECT);
|
|
assert( aHardLimit[SQLITE_LIMIT_VDBE_OP]==SQLITE_MAX_VDBE_OP );
|
|
assert( aHardLimit[SQLITE_LIMIT_FUNCTION_ARG]==SQLITE_MAX_FUNCTION_ARG );
|
|
assert( aHardLimit[SQLITE_LIMIT_ATTACHED]==SQLITE_MAX_ATTACHED );
|
|
assert( aHardLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]==
|
|
SQLITE_MAX_LIKE_PATTERN_LENGTH );
|
|
assert( aHardLimit[SQLITE_LIMIT_VARIABLE_NUMBER]==SQLITE_MAX_VARIABLE_NUMBER);
|
|
assert( aHardLimit[SQLITE_LIMIT_TRIGGER_DEPTH]==SQLITE_MAX_TRIGGER_DEPTH );
|
|
assert( aHardLimit[SQLITE_LIMIT_WORKER_THREADS]==SQLITE_MAX_WORKER_THREADS );
|
|
assert( SQLITE_LIMIT_WORKER_THREADS==(SQLITE_N_LIMIT-1) );
|
|
|
|
|
|
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
|
|
return -1;
|
|
}
|
|
oldLimit = db->aLimit[limitId];
|
|
if( newLimit>=0 ){ /* IMP: R-52476-28732 */
|
|
if( newLimit>aHardLimit[limitId] ){
|
|
newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
|
|
}
|
|
db->aLimit[limitId] = newLimit;
|
|
}
|
|
return oldLimit; /* IMP: R-53341-35419 */
|
|
}
|
|
|
|
/*
|
|
** This function is used to parse both URIs and non-URI filenames passed by the
|
|
** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
|
|
** URIs specified as part of ATTACH statements.
|
|
**
|
|
** The first argument to this function is the name of the VFS to use (or
|
|
** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
|
|
** query parameter. The second argument contains the URI (or non-URI filename)
|
|
** itself. When this function is called the *pFlags variable should contain
|
|
** the default flags to open the database handle with. The value stored in
|
|
** *pFlags may be updated before returning if the URI filename contains
|
|
** "cache=xxx" or "mode=xxx" query parameters.
|
|
**
|
|
** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
|
|
** the VFS that should be used to open the database file. *pzFile is set to
|
|
** point to a buffer containing the name of the file to open. It is the
|
|
** responsibility of the caller to eventually call sqlite3_free() to release
|
|
** this buffer.
|
|
**
|
|
** If an error occurs, then an SQLite error code is returned and *pzErrMsg
|
|
** may be set to point to a buffer containing an English language error
|
|
** message. It is the responsibility of the caller to eventually release
|
|
** this buffer by calling sqlite3_free().
|
|
*/
|
|
int sqlite3ParseUri(
|
|
const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */
|
|
const char *zUri, /* Nul-terminated URI to parse */
|
|
unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
|
|
sqlite3_vfs **ppVfs, /* OUT: VFS to use */
|
|
char **pzFile, /* OUT: Filename component of URI */
|
|
char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */
|
|
){
|
|
int rc = SQLITE_OK;
|
|
unsigned int flags = *pFlags;
|
|
const char *zVfs = zDefaultVfs;
|
|
char *zFile;
|
|
char c;
|
|
int nUri = sqlite3Strlen30(zUri);
|
|
|
|
assert( *pzErrMsg==0 );
|
|
|
|
if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
|
|
|| sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
|
|
&& nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
|
|
){
|
|
char *zOpt;
|
|
int eState; /* Parser state when parsing URI */
|
|
int iIn; /* Input character index */
|
|
int iOut = 0; /* Output character index */
|
|
u64 nByte = nUri+2; /* Bytes of space to allocate */
|
|
|
|
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
|
|
** method that there may be extra parameters following the file-name. */
|
|
flags |= SQLITE_OPEN_URI;
|
|
|
|
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
|
|
zFile = sqlite3_malloc64(nByte);
|
|
if( !zFile ) return SQLITE_NOMEM;
|
|
|
|
iIn = 5;
|
|
#ifdef SQLITE_ALLOW_URI_AUTHORITY
|
|
if( strncmp(zUri+5, "///", 3)==0 ){
|
|
iIn = 7;
|
|
/* The following condition causes URIs with five leading / characters
|
|
** like file://///host/path to be converted into UNCs like //host/path.
|
|
** The correct URI for that UNC has only two or four leading / characters
|
|
** file://host/path or file:////host/path. But 5 leading slashes is a
|
|
** common error, we are told, so we handle it as a special case. */
|
|
if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
|
|
}else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
|
|
iIn = 16;
|
|
}
|
|
#else
|
|
/* Discard the scheme and authority segments of the URI. */
|
|
if( zUri[5]=='/' && zUri[6]=='/' ){
|
|
iIn = 7;
|
|
while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
|
|
if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
|
|
*pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
|
|
iIn-7, &zUri[7]);
|
|
rc = SQLITE_ERROR;
|
|
goto parse_uri_out;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* Copy the filename and any query parameters into the zFile buffer.
|
|
** Decode %HH escape codes along the way.
|
|
**
|
|
** Within this loop, variable eState may be set to 0, 1 or 2, depending
|
|
** on the parsing context. As follows:
|
|
**
|
|
** 0: Parsing file-name.
|
|
** 1: Parsing name section of a name=value query parameter.
|
|
** 2: Parsing value section of a name=value query parameter.
|
|
*/
|
|
eState = 0;
|
|
while( (c = zUri[iIn])!=0 && c!='#' ){
|
|
iIn++;
|
|
if( c=='%'
|
|
&& sqlite3Isxdigit(zUri[iIn])
|
|
&& sqlite3Isxdigit(zUri[iIn+1])
|
|
){
|
|
int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
|
|
octet += sqlite3HexToInt(zUri[iIn++]);
|
|
|
|
assert( octet>=0 && octet<256 );
|
|
if( octet==0 ){
|
|
/* This branch is taken when "%00" appears within the URI. In this
|
|
** case we ignore all text in the remainder of the path, name or
|
|
** value currently being parsed. So ignore the current character
|
|
** and skip to the next "?", "=" or "&", as appropriate. */
|
|
while( (c = zUri[iIn])!=0 && c!='#'
|
|
&& (eState!=0 || c!='?')
|
|
&& (eState!=1 || (c!='=' && c!='&'))
|
|
&& (eState!=2 || c!='&')
|
|
){
|
|
iIn++;
|
|
}
|
|
continue;
|
|
}
|
|
c = octet;
|
|
}else if( eState==1 && (c=='&' || c=='=') ){
|
|
if( zFile[iOut-1]==0 ){
|
|
/* An empty option name. Ignore this option altogether. */
|
|
while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++;
|
|
continue;
|
|
}
|
|
if( c=='&' ){
|
|
zFile[iOut++] = '\0';
|
|
}else{
|
|
eState = 2;
|
|
}
|
|
c = 0;
|
|
}else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
|
|
c = 0;
|
|
eState = 1;
|
|
}
|
|
zFile[iOut++] = c;
|
|
}
|
|
if( eState==1 ) zFile[iOut++] = '\0';
|
|
zFile[iOut++] = '\0';
|
|
zFile[iOut++] = '\0';
|
|
|
|
/* Check if there were any options specified that should be interpreted
|
|
** here. Options that are interpreted here include "vfs" and those that
|
|
** correspond to flags that may be passed to the sqlite3_open_v2()
|
|
** method. */
|
|
zOpt = &zFile[sqlite3Strlen30(zFile)+1];
|
|
while( zOpt[0] ){
|
|
int nOpt = sqlite3Strlen30(zOpt);
|
|
char *zVal = &zOpt[nOpt+1];
|
|
int nVal = sqlite3Strlen30(zVal);
|
|
|
|
if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
|
|
zVfs = zVal;
|
|
}else{
|
|
struct OpenMode {
|
|
const char *z;
|
|
int mode;
|
|
} *aMode = 0;
|
|
char *zModeType = 0;
|
|
int mask = 0;
|
|
int limit = 0;
|
|
|
|
if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
|
|
static struct OpenMode aCacheMode[] = {
|
|
{ "shared", SQLITE_OPEN_SHAREDCACHE },
|
|
{ "private", SQLITE_OPEN_PRIVATECACHE },
|
|
{ 0, 0 }
|
|
};
|
|
|
|
mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE;
|
|
aMode = aCacheMode;
|
|
limit = mask;
|
|
zModeType = "cache";
|
|
}
|
|
if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
|
|
static struct OpenMode aOpenMode[] = {
|
|
{ "ro", SQLITE_OPEN_READONLY },
|
|
{ "rw", SQLITE_OPEN_READWRITE },
|
|
{ "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
|
|
{ "memory", SQLITE_OPEN_MEMORY },
|
|
{ 0, 0 }
|
|
};
|
|
|
|
mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE
|
|
| SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY;
|
|
aMode = aOpenMode;
|
|
limit = mask & flags;
|
|
zModeType = "access";
|
|
}
|
|
|
|
if( aMode ){
|
|
int i;
|
|
int mode = 0;
|
|
for(i=0; aMode[i].z; i++){
|
|
const char *z = aMode[i].z;
|
|
if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
|
|
mode = aMode[i].mode;
|
|
break;
|
|
}
|
|
}
|
|
if( mode==0 ){
|
|
*pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
|
|
rc = SQLITE_ERROR;
|
|
goto parse_uri_out;
|
|
}
|
|
if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
|
|
*pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
|
|
zModeType, zVal);
|
|
rc = SQLITE_PERM;
|
|
goto parse_uri_out;
|
|
}
|
|
flags = (flags & ~mask) | mode;
|
|
}
|
|
}
|
|
|
|
zOpt = &zVal[nVal+1];
|
|
}
|
|
|
|
}else{
|
|
zFile = sqlite3_malloc64(nUri+2);
|
|
if( !zFile ) return SQLITE_NOMEM;
|
|
memcpy(zFile, zUri, nUri);
|
|
zFile[nUri] = '\0';
|
|
zFile[nUri+1] = '\0';
|
|
flags &= ~SQLITE_OPEN_URI;
|
|
}
|
|
|
|
*ppVfs = sqlite3_vfs_find(zVfs);
|
|
if( *ppVfs==0 ){
|
|
*pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
|
|
rc = SQLITE_ERROR;
|
|
}
|
|
parse_uri_out:
|
|
if( rc!=SQLITE_OK ){
|
|
sqlite3_free(zFile);
|
|
zFile = 0;
|
|
}
|
|
*pFlags = flags;
|
|
*pzFile = zFile;
|
|
return rc;
|
|
}
|
|
|
|
|
|
/*
|
|
** This routine does the work of opening a database on behalf of
|
|
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
|
|
** is UTF-8 encoded.
|
|
*/
|
|
static int openDatabase(
|
|
const char *zFilename, /* Database filename UTF-8 encoded */
|
|
sqlite3 **ppDb, /* OUT: Returned database handle */
|
|
unsigned int flags, /* Operational flags */
|
|
const char *zVfs /* Name of the VFS to use */
|
|
){
|
|
sqlite3 *db; /* Store allocated handle here */
|
|
int rc; /* Return code */
|
|
int isThreadsafe; /* True for threadsafe connections */
|
|
char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
|
|
char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
*ppDb = 0;
|
|
#ifndef SQLITE_OMIT_AUTOINIT
|
|
rc = sqlite3_initialize();
|
|
if( rc ) return rc;
|
|
#endif
|
|
|
|
/* Only allow sensible combinations of bits in the flags argument.
|
|
** Throw an error if any non-sense combination is used. If we
|
|
** do not block illegal combinations here, it could trigger
|
|
** assert() statements in deeper layers. Sensible combinations
|
|
** are:
|
|
**
|
|
** 1: SQLITE_OPEN_READONLY
|
|
** 2: SQLITE_OPEN_READWRITE
|
|
** 6: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
|
|
*/
|
|
assert( SQLITE_OPEN_READONLY == 0x01 );
|
|
assert( SQLITE_OPEN_READWRITE == 0x02 );
|
|
assert( SQLITE_OPEN_CREATE == 0x04 );
|
|
testcase( (1<<(flags&7))==0x02 ); /* READONLY */
|
|
testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
|
|
testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
|
|
if( ((1<<(flags&7)) & 0x46)==0 ){
|
|
return SQLITE_MISUSE_BKPT; /* IMP: R-65497-44594 */
|
|
}
|
|
|
|
if( sqlite3GlobalConfig.bCoreMutex==0 ){
|
|
isThreadsafe = 0;
|
|
}else if( flags & SQLITE_OPEN_NOMUTEX ){
|
|
isThreadsafe = 0;
|
|
}else if( flags & SQLITE_OPEN_FULLMUTEX ){
|
|
isThreadsafe = 1;
|
|
}else{
|
|
isThreadsafe = sqlite3GlobalConfig.bFullMutex;
|
|
}
|
|
if( flags & SQLITE_OPEN_PRIVATECACHE ){
|
|
flags &= ~SQLITE_OPEN_SHAREDCACHE;
|
|
}else if( sqlite3GlobalConfig.sharedCacheEnabled ){
|
|
flags |= SQLITE_OPEN_SHAREDCACHE;
|
|
}
|
|
|
|
/* Remove harmful bits from the flags parameter
|
|
**
|
|
** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were
|
|
** dealt with in the previous code block. Besides these, the only
|
|
** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY,
|
|
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
|
|
** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
|
|
** off all other flags.
|
|
*/
|
|
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
|
|
SQLITE_OPEN_EXCLUSIVE |
|
|
SQLITE_OPEN_MAIN_DB |
|
|
SQLITE_OPEN_TEMP_DB |
|
|
SQLITE_OPEN_TRANSIENT_DB |
|
|
SQLITE_OPEN_MAIN_JOURNAL |
|
|
SQLITE_OPEN_TEMP_JOURNAL |
|
|
SQLITE_OPEN_SUBJOURNAL |
|
|
SQLITE_OPEN_MASTER_JOURNAL |
|
|
SQLITE_OPEN_NOMUTEX |
|
|
SQLITE_OPEN_FULLMUTEX |
|
|
SQLITE_OPEN_WAL
|
|
);
|
|
|
|
/* Allocate the sqlite data structure */
|
|
db = sqlite3MallocZero( sizeof(sqlite3) );
|
|
if( db==0 ) goto opendb_out;
|
|
if( isThreadsafe ){
|
|
db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
|
|
if( db->mutex==0 ){
|
|
sqlite3_free(db);
|
|
db = 0;
|
|
goto opendb_out;
|
|
}
|
|
}
|
|
sqlite3_mutex_enter(db->mutex);
|
|
db->errMask = 0xff;
|
|
db->nDb = 2;
|
|
db->magic = SQLITE_MAGIC_BUSY;
|
|
db->aDb = db->aDbStatic;
|
|
|
|
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
|
|
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
|
|
db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = SQLITE_DEFAULT_WORKER_THREADS;
|
|
db->autoCommit = 1;
|
|
db->nextAutovac = -1;
|
|
db->szMmap = sqlite3GlobalConfig.szMmap;
|
|
db->nextPagesize = 0;
|
|
db->nMaxSorterMmap = 0x7FFFFFFF;
|
|
db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
|
|
#if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
|
|
| SQLITE_AutoIndex
|
|
#endif
|
|
#if SQLITE_DEFAULT_CKPTFULLFSYNC
|
|
| SQLITE_CkptFullFSync
|
|
#endif
|
|
#if SQLITE_DEFAULT_FILE_FORMAT<4
|
|
| SQLITE_LegacyFileFmt
|
|
#endif
|
|
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
|
|
| SQLITE_LoadExtension
|
|
#endif
|
|
#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
|
|
| SQLITE_RecTriggers
|
|
#endif
|
|
#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
|
|
| SQLITE_ForeignKeys
|
|
#endif
|
|
#if defined(SQLITE_REVERSE_UNORDERED_SELECTS)
|
|
| SQLITE_ReverseOrder
|
|
#endif
|
|
#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
|
|
| SQLITE_CellSizeCk
|
|
#endif
|
|
;
|
|
sqlite3HashInit(&db->aCollSeq);
|
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
sqlite3HashInit(&db->aModule);
|
|
#endif
|
|
|
|
/* Add the default collation sequence BINARY. BINARY works for both UTF-8
|
|
** and UTF-16, so add a version for each to avoid any unnecessary
|
|
** conversions. The only error that can occur here is a malloc() failure.
|
|
**
|
|
** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
|
|
** functions:
|
|
*/
|
|
createCollation(db, sqlite3StrBINARY, SQLITE_UTF8, 0, binCollFunc, 0);
|
|
createCollation(db, sqlite3StrBINARY, SQLITE_UTF16BE, 0, binCollFunc, 0);
|
|
createCollation(db, sqlite3StrBINARY, SQLITE_UTF16LE, 0, binCollFunc, 0);
|
|
createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
|
|
createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
|
|
if( db->mallocFailed ){
|
|
goto opendb_out;
|
|
}
|
|
/* EVIDENCE-OF: R-08308-17224 The default collating function for all
|
|
** strings is BINARY.
|
|
*/
|
|
db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, sqlite3StrBINARY, 0);
|
|
assert( db->pDfltColl!=0 );
|
|
|
|
/* Parse the filename/URI argument. */
|
|
db->openFlags = flags;
|
|
rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
|
|
if( rc!=SQLITE_OK ){
|
|
if( rc==SQLITE_NOMEM ) sqlite3OomFault(db);
|
|
sqlite3ErrorWithMsg(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
|
|
sqlite3_free(zErrMsg);
|
|
goto opendb_out;
|
|
}
|
|
|
|
/* Open the backend database driver */
|
|
rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
|
|
flags | SQLITE_OPEN_MAIN_DB);
|
|
if( rc!=SQLITE_OK ){
|
|
if( rc==SQLITE_IOERR_NOMEM ){
|
|
rc = SQLITE_NOMEM;
|
|
}
|
|
sqlite3Error(db, rc);
|
|
goto opendb_out;
|
|
}
|
|
sqlite3BtreeEnter(db->aDb[0].pBt);
|
|
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
|
|
if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
|
|
sqlite3BtreeLeave(db->aDb[0].pBt);
|
|
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
|
|
|
|
/* The default safety_level for the main database is 'full'; for the temp
|
|
** database it is 'NONE'. This matches the pager layer defaults.
|
|
*/
|
|
db->aDb[0].zName = "main";
|
|
db->aDb[0].safety_level = 3;
|
|
db->aDb[1].zName = "temp";
|
|
db->aDb[1].safety_level = 1;
|
|
|
|
db->magic = SQLITE_MAGIC_OPEN;
|
|
if( db->mallocFailed ){
|
|
goto opendb_out;
|
|
}
|
|
|
|
/* Register all built-in functions, but do not attempt to read the
|
|
** database schema yet. This is delayed until the first time the database
|
|
** is accessed.
|
|
*/
|
|
sqlite3Error(db, SQLITE_OK);
|
|
sqlite3RegisterBuiltinFunctions(db);
|
|
|
|
/* Load automatic extensions - extensions that have been registered
|
|
** using the sqlite3_automatic_extension() API.
|
|
*/
|
|
rc = sqlite3_errcode(db);
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3AutoLoadExtensions(db);
|
|
rc = sqlite3_errcode(db);
|
|
if( rc!=SQLITE_OK ){
|
|
goto opendb_out;
|
|
}
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_FTS1
|
|
if( !db->mallocFailed ){
|
|
extern int sqlite3Fts1Init(sqlite3*);
|
|
rc = sqlite3Fts1Init(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_FTS2
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
|
extern int sqlite3Fts2Init(sqlite3*);
|
|
rc = sqlite3Fts2Init(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_FTS3 /* automatically defined by SQLITE_ENABLE_FTS4 */
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
|
rc = sqlite3Fts3Init(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_FTS5
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5Init(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_ICU
|
|
if( !db->mallocFailed && rc==SQLITE_OK ){
|
|
rc = sqlite3IcuInit(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_RTREE
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
|
rc = sqlite3RtreeInit(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_DBSTAT_VTAB
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
|
rc = sqlite3DbstatRegister(db);
|
|
}
|
|
#endif
|
|
|
|
#ifdef SQLITE_ENABLE_JSON1
|
|
if( !db->mallocFailed && rc==SQLITE_OK){
|
|
rc = sqlite3Json1Init(db);
|
|
}
|
|
#endif
|
|
|
|
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
|
|
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
|
|
** mode. Doing nothing at all also makes NORMAL the default.
|
|
*/
|
|
#ifdef SQLITE_DEFAULT_LOCKING_MODE
|
|
db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
|
|
sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
|
|
SQLITE_DEFAULT_LOCKING_MODE);
|
|
#endif
|
|
|
|
if( rc ) sqlite3Error(db, rc);
|
|
|
|
/* Enable the lookaside-malloc subsystem */
|
|
setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
|
|
sqlite3GlobalConfig.nLookaside);
|
|
|
|
sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
|
|
|
|
opendb_out:
|
|
if( db ){
|
|
assert( db->mutex!=0 || isThreadsafe==0
|
|
|| sqlite3GlobalConfig.bFullMutex==0 );
|
|
sqlite3_mutex_leave(db->mutex);
|
|
}
|
|
rc = sqlite3_errcode(db);
|
|
assert( db!=0 || rc==SQLITE_NOMEM );
|
|
if( rc==SQLITE_NOMEM ){
|
|
sqlite3_close(db);
|
|
db = 0;
|
|
}else if( rc!=SQLITE_OK ){
|
|
db->magic = SQLITE_MAGIC_SICK;
|
|
}
|
|
*ppDb = db;
|
|
#ifdef SQLITE_ENABLE_SQLLOG
|
|
if( sqlite3GlobalConfig.xSqllog ){
|
|
/* Opening a db handle. Fourth parameter is passed 0. */
|
|
void *pArg = sqlite3GlobalConfig.pSqllogArg;
|
|
sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
|
|
}
|
|
#endif
|
|
#if defined(SQLITE_HAS_CODEC)
|
|
if( rc==SQLITE_OK ){
|
|
const char *zHexKey = sqlite3_uri_parameter(zOpen, "hexkey");
|
|
if( zHexKey && zHexKey[0] ){
|
|
u8 iByte;
|
|
int i;
|
|
char zKey[40];
|
|
for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zHexKey[i]); i++){
|
|
iByte = (iByte<<4) + sqlite3HexToInt(zHexKey[i]);
|
|
if( (i&1)!=0 ) zKey[i/2] = iByte;
|
|
}
|
|
sqlite3_key_v2(db, 0, zKey, i/2);
|
|
}
|
|
}
|
|
#endif
|
|
sqlite3_free(zOpen);
|
|
return rc & 0xff;
|
|
}
|
|
|
|
/*
|
|
** Open a new database handle.
|
|
*/
|
|
int sqlite3_open(
|
|
const char *zFilename,
|
|
sqlite3 **ppDb
|
|
){
|
|
return openDatabase(zFilename, ppDb,
|
|
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
|
|
}
|
|
int sqlite3_open_v2(
|
|
const char *filename, /* Database filename (UTF-8) */
|
|
sqlite3 **ppDb, /* OUT: SQLite db handle */
|
|
int flags, /* Flags */
|
|
const char *zVfs /* Name of VFS module to use */
|
|
){
|
|
return openDatabase(filename, ppDb, (unsigned int)flags, zVfs);
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/*
|
|
** Open a new database handle.
|
|
*/
|
|
int sqlite3_open16(
|
|
const void *zFilename,
|
|
sqlite3 **ppDb
|
|
){
|
|
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
|
|
sqlite3_value *pVal;
|
|
int rc;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
*ppDb = 0;
|
|
#ifndef SQLITE_OMIT_AUTOINIT
|
|
rc = sqlite3_initialize();
|
|
if( rc ) return rc;
|
|
#endif
|
|
if( zFilename==0 ) zFilename = "\000\000";
|
|
pVal = sqlite3ValueNew(0);
|
|
sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
|
|
zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
|
|
if( zFilename8 ){
|
|
rc = openDatabase(zFilename8, ppDb,
|
|
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
|
|
assert( *ppDb || rc==SQLITE_NOMEM );
|
|
if( rc==SQLITE_OK && !DbHasProperty(*ppDb, 0, DB_SchemaLoaded) ){
|
|
SCHEMA_ENC(*ppDb) = ENC(*ppDb) = SQLITE_UTF16NATIVE;
|
|
}
|
|
}else{
|
|
rc = SQLITE_NOMEM;
|
|
}
|
|
sqlite3ValueFree(pVal);
|
|
|
|
return rc & 0xff;
|
|
}
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
|
|
/*
|
|
** Register a new collation sequence with the database handle db.
|
|
*/
|
|
int sqlite3_create_collation(
|
|
sqlite3* db,
|
|
const char *zName,
|
|
int enc,
|
|
void* pCtx,
|
|
int(*xCompare)(void*,int,const void*,int,const void*)
|
|
){
|
|
return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
|
|
}
|
|
|
|
/*
|
|
** Register a new collation sequence with the database handle db.
|
|
*/
|
|
int sqlite3_create_collation_v2(
|
|
sqlite3* db,
|
|
const char *zName,
|
|
int enc,
|
|
void* pCtx,
|
|
int(*xCompare)(void*,int,const void*,int,const void*),
|
|
void(*xDel)(void*)
|
|
){
|
|
int rc;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
assert( !db->mallocFailed );
|
|
rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/*
|
|
** Register a new collation sequence with the database handle db.
|
|
*/
|
|
int sqlite3_create_collation16(
|
|
sqlite3* db,
|
|
const void *zName,
|
|
int enc,
|
|
void* pCtx,
|
|
int(*xCompare)(void*,int,const void*,int,const void*)
|
|
){
|
|
int rc = SQLITE_OK;
|
|
char *zName8;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
assert( !db->mallocFailed );
|
|
zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
|
|
if( zName8 ){
|
|
rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
|
|
sqlite3DbFree(db, zName8);
|
|
}
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
|
|
/*
|
|
** Register a collation sequence factory callback with the database handle
|
|
** db. Replace any previously installed collation sequence factory.
|
|
*/
|
|
int sqlite3_collation_needed(
|
|
sqlite3 *db,
|
|
void *pCollNeededArg,
|
|
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
|
|
){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
db->xCollNeeded = xCollNeeded;
|
|
db->xCollNeeded16 = 0;
|
|
db->pCollNeededArg = pCollNeededArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
/*
|
|
** Register a collation sequence factory callback with the database handle
|
|
** db. Replace any previously installed collation sequence factory.
|
|
*/
|
|
int sqlite3_collation_needed16(
|
|
sqlite3 *db,
|
|
void *pCollNeededArg,
|
|
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
|
|
){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
db->xCollNeeded = 0;
|
|
db->xCollNeeded16 = xCollNeeded16;
|
|
db->pCollNeededArg = pCollNeededArg;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return SQLITE_OK;
|
|
}
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
/*
|
|
** This function is now an anachronism. It used to be used to recover from a
|
|
** malloc() failure, but SQLite now does this automatically.
|
|
*/
|
|
int sqlite3_global_recover(void){
|
|
return SQLITE_OK;
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** Test to see whether or not the database connection is in autocommit
|
|
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
|
|
** by default. Autocommit is disabled by a BEGIN statement and reenabled
|
|
** by the next COMMIT or ROLLBACK.
|
|
*/
|
|
int sqlite3_get_autocommit(sqlite3 *db){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
return db->autoCommit;
|
|
}
|
|
|
|
/*
|
|
** The following routines are substitutes for constants SQLITE_CORRUPT,
|
|
** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_IOERR and possibly other error
|
|
** constants. They serve two purposes:
|
|
**
|
|
** 1. Serve as a convenient place to set a breakpoint in a debugger
|
|
** to detect when version error conditions occurs.
|
|
**
|
|
** 2. Invoke sqlite3_log() to provide the source code location where
|
|
** a low-level error is first detected.
|
|
*/
|
|
int sqlite3CorruptError(int lineno){
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
|
sqlite3_log(SQLITE_CORRUPT,
|
|
"database corruption at line %d of [%.10s]",
|
|
lineno, 20+sqlite3_sourceid());
|
|
return SQLITE_CORRUPT;
|
|
}
|
|
int sqlite3MisuseError(int lineno){
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
|
sqlite3_log(SQLITE_MISUSE,
|
|
"misuse at line %d of [%.10s]",
|
|
lineno, 20+sqlite3_sourceid());
|
|
return SQLITE_MISUSE;
|
|
}
|
|
int sqlite3CantopenError(int lineno){
|
|
testcase( sqlite3GlobalConfig.xLog!=0 );
|
|
sqlite3_log(SQLITE_CANTOPEN,
|
|
"cannot open file at line %d of [%.10s]",
|
|
lineno, 20+sqlite3_sourceid());
|
|
return SQLITE_CANTOPEN;
|
|
}
|
|
|
|
|
|
#ifndef SQLITE_OMIT_DEPRECATED
|
|
/*
|
|
** This is a convenience routine that makes sure that all thread-specific
|
|
** data for this thread has been deallocated.
|
|
**
|
|
** SQLite no longer uses thread-specific data so this routine is now a
|
|
** no-op. It is retained for historical compatibility.
|
|
*/
|
|
void sqlite3_thread_cleanup(void){
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
** Return meta information about a specific column of a database table.
|
|
** See comment in sqlite3.h (sqlite.h.in) for details.
|
|
*/
|
|
int sqlite3_table_column_metadata(
|
|
sqlite3 *db, /* Connection handle */
|
|
const char *zDbName, /* Database name or NULL */
|
|
const char *zTableName, /* Table name */
|
|
const char *zColumnName, /* Column name */
|
|
char const **pzDataType, /* OUTPUT: Declared data type */
|
|
char const **pzCollSeq, /* OUTPUT: Collation sequence name */
|
|
int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */
|
|
int *pPrimaryKey, /* OUTPUT: True if column part of PK */
|
|
int *pAutoinc /* OUTPUT: True if column is auto-increment */
|
|
){
|
|
int rc;
|
|
char *zErrMsg = 0;
|
|
Table *pTab = 0;
|
|
Column *pCol = 0;
|
|
int iCol = 0;
|
|
char const *zDataType = 0;
|
|
char const *zCollSeq = 0;
|
|
int notnull = 0;
|
|
int primarykey = 0;
|
|
int autoinc = 0;
|
|
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) || zTableName==0 ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
#endif
|
|
|
|
/* Ensure the database schema has been loaded */
|
|
sqlite3_mutex_enter(db->mutex);
|
|
sqlite3BtreeEnterAll(db);
|
|
rc = sqlite3Init(db, &zErrMsg);
|
|
if( SQLITE_OK!=rc ){
|
|
goto error_out;
|
|
}
|
|
|
|
/* Locate the table in question */
|
|
pTab = sqlite3FindTable(db, zTableName, zDbName);
|
|
if( !pTab || pTab->pSelect ){
|
|
pTab = 0;
|
|
goto error_out;
|
|
}
|
|
|
|
/* Find the column for which info is requested */
|
|
if( zColumnName==0 ){
|
|
/* Query for existance of table only */
|
|
}else{
|
|
for(iCol=0; iCol<pTab->nCol; iCol++){
|
|
pCol = &pTab->aCol[iCol];
|
|
if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
|
|
break;
|
|
}
|
|
}
|
|
if( iCol==pTab->nCol ){
|
|
if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
|
|
iCol = pTab->iPKey;
|
|
pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
|
|
}else{
|
|
pTab = 0;
|
|
goto error_out;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* The following block stores the meta information that will be returned
|
|
** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
|
|
** and autoinc. At this point there are two possibilities:
|
|
**
|
|
** 1. The specified column name was rowid", "oid" or "_rowid_"
|
|
** and there is no explicitly declared IPK column.
|
|
**
|
|
** 2. The table is not a view and the column name identified an
|
|
** explicitly declared column. Copy meta information from *pCol.
|
|
*/
|
|
if( pCol ){
|
|
zDataType = pCol->zType;
|
|
zCollSeq = pCol->zColl;
|
|
notnull = pCol->notNull!=0;
|
|
primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
|
|
autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
|
|
}else{
|
|
zDataType = "INTEGER";
|
|
primarykey = 1;
|
|
}
|
|
if( !zCollSeq ){
|
|
zCollSeq = sqlite3StrBINARY;
|
|
}
|
|
|
|
error_out:
|
|
sqlite3BtreeLeaveAll(db);
|
|
|
|
/* Whether the function call succeeded or failed, set the output parameters
|
|
** to whatever their local counterparts contain. If an error did occur,
|
|
** this has the effect of zeroing all output parameters.
|
|
*/
|
|
if( pzDataType ) *pzDataType = zDataType;
|
|
if( pzCollSeq ) *pzCollSeq = zCollSeq;
|
|
if( pNotNull ) *pNotNull = notnull;
|
|
if( pPrimaryKey ) *pPrimaryKey = primarykey;
|
|
if( pAutoinc ) *pAutoinc = autoinc;
|
|
|
|
if( SQLITE_OK==rc && !pTab ){
|
|
sqlite3DbFree(db, zErrMsg);
|
|
zErrMsg = sqlite3MPrintf(db, "no such table column: %s.%s", zTableName,
|
|
zColumnName);
|
|
rc = SQLITE_ERROR;
|
|
}
|
|
sqlite3ErrorWithMsg(db, rc, (zErrMsg?"%s":0), zErrMsg);
|
|
sqlite3DbFree(db, zErrMsg);
|
|
rc = sqlite3ApiExit(db, rc);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Sleep for a little while. Return the amount of time slept.
|
|
*/
|
|
int sqlite3_sleep(int ms){
|
|
sqlite3_vfs *pVfs;
|
|
int rc;
|
|
pVfs = sqlite3_vfs_find(0);
|
|
if( pVfs==0 ) return 0;
|
|
|
|
/* This function works in milliseconds, but the underlying OsSleep()
|
|
** API uses microseconds. Hence the 1000's.
|
|
*/
|
|
rc = (sqlite3OsSleep(pVfs, 1000*ms)/1000);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Enable or disable the extended result codes.
|
|
*/
|
|
int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
db->errMask = onoff ? 0xffffffff : 0xff;
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Invoke the xFileControl method on a particular database.
|
|
*/
|
|
int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
|
|
int rc = SQLITE_ERROR;
|
|
Btree *pBtree;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
pBtree = sqlite3DbNameToBtree(db, zDbName);
|
|
if( pBtree ){
|
|
Pager *pPager;
|
|
sqlite3_file *fd;
|
|
sqlite3BtreeEnter(pBtree);
|
|
pPager = sqlite3BtreePager(pBtree);
|
|
assert( pPager!=0 );
|
|
fd = sqlite3PagerFile(pPager);
|
|
assert( fd!=0 );
|
|
if( op==SQLITE_FCNTL_FILE_POINTER ){
|
|
*(sqlite3_file**)pArg = fd;
|
|
rc = SQLITE_OK;
|
|
}else if( op==SQLITE_FCNTL_VFS_POINTER ){
|
|
*(sqlite3_vfs**)pArg = sqlite3PagerVfs(pPager);
|
|
rc = SQLITE_OK;
|
|
}else if( op==SQLITE_FCNTL_JOURNAL_POINTER ){
|
|
*(sqlite3_file**)pArg = sqlite3PagerJrnlFile(pPager);
|
|
rc = SQLITE_OK;
|
|
}else if( fd->pMethods ){
|
|
rc = sqlite3OsFileControl(fd, op, pArg);
|
|
}else{
|
|
rc = SQLITE_NOTFOUND;
|
|
}
|
|
sqlite3BtreeLeave(pBtree);
|
|
}
|
|
sqlite3_mutex_leave(db->mutex);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Interface to the testing logic.
|
|
*/
|
|
int sqlite3_test_control(int op, ...){
|
|
int rc = 0;
|
|
#ifdef SQLITE_OMIT_BUILTIN_TEST
|
|
UNUSED_PARAMETER(op);
|
|
#else
|
|
va_list ap;
|
|
va_start(ap, op);
|
|
switch( op ){
|
|
|
|
/*
|
|
** Save the current state of the PRNG.
|
|
*/
|
|
case SQLITE_TESTCTRL_PRNG_SAVE: {
|
|
sqlite3PrngSaveState();
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** Restore the state of the PRNG to the last state saved using
|
|
** PRNG_SAVE. If PRNG_SAVE has never before been called, then
|
|
** this verb acts like PRNG_RESET.
|
|
*/
|
|
case SQLITE_TESTCTRL_PRNG_RESTORE: {
|
|
sqlite3PrngRestoreState();
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** Reset the PRNG back to its uninitialized state. The next call
|
|
** to sqlite3_randomness() will reseed the PRNG using a single call
|
|
** to the xRandomness method of the default VFS.
|
|
*/
|
|
case SQLITE_TESTCTRL_PRNG_RESET: {
|
|
sqlite3_randomness(0,0);
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** sqlite3_test_control(BITVEC_TEST, size, program)
|
|
**
|
|
** Run a test against a Bitvec object of size. The program argument
|
|
** is an array of integers that defines the test. Return -1 on a
|
|
** memory allocation error, 0 on success, or non-zero for an error.
|
|
** See the sqlite3BitvecBuiltinTest() for additional information.
|
|
*/
|
|
case SQLITE_TESTCTRL_BITVEC_TEST: {
|
|
int sz = va_arg(ap, int);
|
|
int *aProg = va_arg(ap, int*);
|
|
rc = sqlite3BitvecBuiltinTest(sz, aProg);
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** sqlite3_test_control(FAULT_INSTALL, xCallback)
|
|
**
|
|
** Arrange to invoke xCallback() whenever sqlite3FaultSim() is called,
|
|
** if xCallback is not NULL.
|
|
**
|
|
** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
|
|
** is called immediately after installing the new callback and the return
|
|
** value from sqlite3FaultSim(0) becomes the return from
|
|
** sqlite3_test_control().
|
|
*/
|
|
case SQLITE_TESTCTRL_FAULT_INSTALL: {
|
|
/* MSVC is picky about pulling func ptrs from va lists.
|
|
** http://support.microsoft.com/kb/47961
|
|
** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
|
|
*/
|
|
typedef int(*TESTCALLBACKFUNC_t)(int);
|
|
sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
|
|
rc = sqlite3FaultSim(0);
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
|
|
**
|
|
** Register hooks to call to indicate which malloc() failures
|
|
** are benign.
|
|
*/
|
|
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS: {
|
|
typedef void (*void_function)(void);
|
|
void_function xBenignBegin;
|
|
void_function xBenignEnd;
|
|
xBenignBegin = va_arg(ap, void_function);
|
|
xBenignEnd = va_arg(ap, void_function);
|
|
sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd);
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, unsigned int X)
|
|
**
|
|
** Set the PENDING byte to the value in the argument, if X>0.
|
|
** Make no changes if X==0. Return the value of the pending byte
|
|
** as it existing before this routine was called.
|
|
**
|
|
** IMPORTANT: Changing the PENDING byte from 0x40000000 results in
|
|
** an incompatible database file format. Changing the PENDING byte
|
|
** while any database connection is open results in undefined and
|
|
** deleterious behavior.
|
|
*/
|
|
case SQLITE_TESTCTRL_PENDING_BYTE: {
|
|
rc = PENDING_BYTE;
|
|
#ifndef SQLITE_OMIT_WSD
|
|
{
|
|
unsigned int newVal = va_arg(ap, unsigned int);
|
|
if( newVal ) sqlite3PendingByte = newVal;
|
|
}
|
|
#endif
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X)
|
|
**
|
|
** This action provides a run-time test to see whether or not
|
|
** assert() was enabled at compile-time. If X is true and assert()
|
|
** is enabled, then the return value is true. If X is true and
|
|
** assert() is disabled, then the return value is zero. If X is
|
|
** false and assert() is enabled, then the assertion fires and the
|
|
** process aborts. If X is false and assert() is disabled, then the
|
|
** return value is zero.
|
|
*/
|
|
case SQLITE_TESTCTRL_ASSERT: {
|
|
volatile int x = 0;
|
|
assert( /*side-effects-ok*/ (x = va_arg(ap,int))!=0 );
|
|
rc = x;
|
|
break;
|
|
}
|
|
|
|
|
|
/*
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
|
|
**
|
|
** This action provides a run-time test to see how the ALWAYS and
|
|
** NEVER macros were defined at compile-time.
|
|
**
|
|
** The return value is ALWAYS(X).
|
|
**
|
|
** The recommended test is X==2. If the return value is 2, that means
|
|
** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
|
|
** default setting. If the return value is 1, then ALWAYS() is either
|
|
** hard-coded to true or else it asserts if its argument is false.
|
|
** The first behavior (hard-coded to true) is the case if
|
|
** SQLITE_TESTCTRL_ASSERT shows that assert() is disabled and the second
|
|
** behavior (assert if the argument to ALWAYS() is false) is the case if
|
|
** SQLITE_TESTCTRL_ASSERT shows that assert() is enabled.
|
|
**
|
|
** The run-time test procedure might look something like this:
|
|
**
|
|
** if( sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, 2)==2 ){
|
|
** // ALWAYS() and NEVER() are no-op pass-through macros
|
|
** }else if( sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, 1) ){
|
|
** // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
|
|
** }else{
|
|
** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
|
|
** }
|
|
*/
|
|
case SQLITE_TESTCTRL_ALWAYS: {
|
|
int x = va_arg(ap,int);
|
|
rc = ALWAYS(x);
|
|
break;
|
|
}
|
|
|
|
/*
|
|
** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
|
|
**
|
|
** The integer returned reveals the byte-order of the computer on which
|
|
** SQLite is running:
|
|
**
|
|
** 1 big-endian, determined at run-time
|
|
** 10 little-endian, determined at run-time
|
|
** 432101 big-endian, determined at compile-time
|
|
** 123410 little-endian, determined at compile-time
|
|
*/
|
|
case SQLITE_TESTCTRL_BYTEORDER: {
|
|
rc = SQLITE_BYTEORDER*100 + SQLITE_LITTLEENDIAN*10 + SQLITE_BIGENDIAN;
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
|
|
**
|
|
** Set the nReserve size to N for the main database on the database
|
|
** connection db.
|
|
*/
|
|
case SQLITE_TESTCTRL_RESERVE: {
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
|
int x = va_arg(ap,int);
|
|
sqlite3_mutex_enter(db->mutex);
|
|
sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
|
|
sqlite3_mutex_leave(db->mutex);
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
|
|
**
|
|
** Enable or disable various optimizations for testing purposes. The
|
|
** argument N is a bitmask of optimizations to be disabled. For normal
|
|
** operation N should be 0. The idea is that a test program (like the
|
|
** SQL Logic Test or SLT test module) can run the same SQL multiple times
|
|
** with various optimizations disabled to verify that the same answer
|
|
** is obtained in every case.
|
|
*/
|
|
case SQLITE_TESTCTRL_OPTIMIZATIONS: {
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
|
db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
|
|
break;
|
|
}
|
|
|
|
#ifdef SQLITE_N_KEYWORD
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord)
|
|
**
|
|
** If zWord is a keyword recognized by the parser, then return the
|
|
** number of keywords. Or if zWord is not a keyword, return 0.
|
|
**
|
|
** This test feature is only available in the amalgamation since
|
|
** the SQLITE_N_KEYWORD macro is not defined in this file if SQLite
|
|
** is built using separate source files.
|
|
*/
|
|
case SQLITE_TESTCTRL_ISKEYWORD: {
|
|
const char *zWord = va_arg(ap, const char*);
|
|
int n = sqlite3Strlen30(zWord);
|
|
rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0;
|
|
break;
|
|
}
|
|
#endif
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
|
|
**
|
|
** Pass pFree into sqlite3ScratchFree().
|
|
** If sz>0 then allocate a scratch buffer into pNew.
|
|
*/
|
|
case SQLITE_TESTCTRL_SCRATCHMALLOC: {
|
|
void *pFree, **ppNew;
|
|
int sz;
|
|
sz = va_arg(ap, int);
|
|
ppNew = va_arg(ap, void**);
|
|
pFree = va_arg(ap, void*);
|
|
if( sz ) *ppNew = sqlite3ScratchMalloc(sz);
|
|
sqlite3ScratchFree(pFree);
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
|
|
**
|
|
** If parameter onoff is non-zero, configure the wrappers so that all
|
|
** subsequent calls to localtime() and variants fail. If onoff is zero,
|
|
** undo this setting.
|
|
*/
|
|
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
|
|
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
|
|
**
|
|
** Set or clear a flag that indicates that the database file is always well-
|
|
** formed and never corrupt. This flag is clear by default, indicating that
|
|
** database files might have arbitrary corruption. Setting the flag during
|
|
** testing causes certain assert() statements in the code to be activated
|
|
** that demonstrat invariants on well-formed database files.
|
|
*/
|
|
case SQLITE_TESTCTRL_NEVER_CORRUPT: {
|
|
sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
|
|
break;
|
|
}
|
|
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
|
|
**
|
|
** Set the VDBE coverage callback function to xCallback with context
|
|
** pointer ptr.
|
|
*/
|
|
case SQLITE_TESTCTRL_VDBE_COVERAGE: {
|
|
#ifdef SQLITE_VDBE_COVERAGE
|
|
typedef void (*branch_callback)(void*,int,u8,u8);
|
|
sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
|
|
sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
|
|
#endif
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */
|
|
case SQLITE_TESTCTRL_SORTER_MMAP: {
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
|
db->nMaxSorterMmap = va_arg(ap, int);
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
|
|
**
|
|
** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
|
|
** not.
|
|
*/
|
|
case SQLITE_TESTCTRL_ISINIT: {
|
|
if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
|
|
break;
|
|
}
|
|
|
|
/* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
|
|
**
|
|
** This test control is used to create imposter tables. "db" is a pointer
|
|
** to the database connection. dbName is the database name (ex: "main" or
|
|
** "temp") which will receive the imposter. "onOff" turns imposter mode on
|
|
** or off. "tnum" is the root page of the b-tree to which the imposter
|
|
** table should connect.
|
|
**
|
|
** Enable imposter mode only when the schema has already been parsed. Then
|
|
** run a single CREATE TABLE statement to construct the imposter table in
|
|
** the parsed schema. Then turn imposter mode back off again.
|
|
**
|
|
** If onOff==0 and tnum>0 then reset the schema for all databases, causing
|
|
** the schema to be reparsed the next time it is needed. This has the
|
|
** effect of erasing all imposter tables.
|
|
*/
|
|
case SQLITE_TESTCTRL_IMPOSTER: {
|
|
sqlite3 *db = va_arg(ap, sqlite3*);
|
|
sqlite3_mutex_enter(db->mutex);
|
|
db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*));
|
|
db->init.busy = db->init.imposterTable = va_arg(ap,int);
|
|
db->init.newTnum = va_arg(ap,int);
|
|
if( db->init.busy==0 && db->init.newTnum>0 ){
|
|
sqlite3ResetAllSchemasOfConnection(db);
|
|
}
|
|
sqlite3_mutex_leave(db->mutex);
|
|
break;
|
|
}
|
|
}
|
|
va_end(ap);
|
|
#endif /* SQLITE_OMIT_BUILTIN_TEST */
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** This is a utility routine, useful to VFS implementations, that checks
|
|
** to see if a database file was a URI that contained a specific query
|
|
** parameter, and if so obtains the value of the query parameter.
|
|
**
|
|
** The zFilename argument is the filename pointer passed into the xOpen()
|
|
** method of a VFS implementation. The zParam argument is the name of the
|
|
** query parameter we seek. This routine returns the value of the zParam
|
|
** parameter if it exists. If the parameter does not exist, this routine
|
|
** returns a NULL pointer.
|
|
*/
|
|
const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
|
|
if( zFilename==0 || zParam==0 ) return 0;
|
|
zFilename += sqlite3Strlen30(zFilename) + 1;
|
|
while( zFilename[0] ){
|
|
int x = strcmp(zFilename, zParam);
|
|
zFilename += sqlite3Strlen30(zFilename) + 1;
|
|
if( x==0 ) return zFilename;
|
|
zFilename += sqlite3Strlen30(zFilename) + 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** Return a boolean value for a query parameter.
|
|
*/
|
|
int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){
|
|
const char *z = sqlite3_uri_parameter(zFilename, zParam);
|
|
bDflt = bDflt!=0;
|
|
return z ? sqlite3GetBoolean(z, bDflt) : bDflt;
|
|
}
|
|
|
|
/*
|
|
** Return a 64-bit integer value for a query parameter.
|
|
*/
|
|
sqlite3_int64 sqlite3_uri_int64(
|
|
const char *zFilename, /* Filename as passed to xOpen */
|
|
const char *zParam, /* URI parameter sought */
|
|
sqlite3_int64 bDflt /* return if parameter is missing */
|
|
){
|
|
const char *z = sqlite3_uri_parameter(zFilename, zParam);
|
|
sqlite3_int64 v;
|
|
if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){
|
|
bDflt = v;
|
|
}
|
|
return bDflt;
|
|
}
|
|
|
|
/*
|
|
** Return the Btree pointer identified by zDbName. Return NULL if not found.
|
|
*/
|
|
Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
|
|
int i;
|
|
for(i=0; i<db->nDb; i++){
|
|
if( db->aDb[i].pBt
|
|
&& (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)
|
|
){
|
|
return db->aDb[i].pBt;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** Return the filename of the database associated with a database
|
|
** connection.
|
|
*/
|
|
const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
|
|
Btree *pBt;
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return 0;
|
|
}
|
|
#endif
|
|
pBt = sqlite3DbNameToBtree(db, zDbName);
|
|
return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
|
|
}
|
|
|
|
/*
|
|
** Return 1 if database is read-only or 0 if read/write. Return -1 if
|
|
** no such database exists.
|
|
*/
|
|
int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
|
|
Btree *pBt;
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
(void)SQLITE_MISUSE_BKPT;
|
|
return -1;
|
|
}
|
|
#endif
|
|
pBt = sqlite3DbNameToBtree(db, zDbName);
|
|
return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
|
|
}
|
|
|
|
#ifdef SQLITE_ENABLE_SNAPSHOT
|
|
/*
|
|
** Obtain a snapshot handle for the snapshot of database zDb currently
|
|
** being read by handle db.
|
|
*/
|
|
int sqlite3_snapshot_get(
|
|
sqlite3 *db,
|
|
const char *zDb,
|
|
sqlite3_snapshot **ppSnapshot
|
|
){
|
|
int rc = SQLITE_ERROR;
|
|
#ifndef SQLITE_OMIT_WAL
|
|
int iDb;
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
|
|
iDb = sqlite3FindDbName(db, zDb);
|
|
if( iDb==0 || iDb>1 ){
|
|
Btree *pBt = db->aDb[iDb].pBt;
|
|
if( 0==sqlite3BtreeIsInTrans(pBt) ){
|
|
rc = sqlite3BtreeBeginTrans(pBt, 0);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
|
|
}
|
|
}
|
|
}
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Open a read-transaction on the snapshot idendified by pSnapshot.
|
|
*/
|
|
int sqlite3_snapshot_open(
|
|
sqlite3 *db,
|
|
const char *zDb,
|
|
sqlite3_snapshot *pSnapshot
|
|
){
|
|
int rc = SQLITE_ERROR;
|
|
#ifndef SQLITE_OMIT_WAL
|
|
|
|
#ifdef SQLITE_ENABLE_API_ARMOR
|
|
if( !sqlite3SafetyCheckOk(db) ){
|
|
return SQLITE_MISUSE_BKPT;
|
|
}
|
|
#endif
|
|
sqlite3_mutex_enter(db->mutex);
|
|
if( db->autoCommit==0 ){
|
|
int iDb;
|
|
iDb = sqlite3FindDbName(db, zDb);
|
|
if( iDb==0 || iDb>1 ){
|
|
Btree *pBt = db->aDb[iDb].pBt;
|
|
if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
|
|
rc = sqlite3PagerSnapshotOpen(sqlite3BtreePager(pBt), pSnapshot);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3BtreeBeginTrans(pBt, 0);
|
|
sqlite3PagerSnapshotOpen(sqlite3BtreePager(pBt), 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sqlite3_mutex_leave(db->mutex);
|
|
#endif /* SQLITE_OMIT_WAL */
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Free a snapshot handle obtained from sqlite3_snapshot_get().
|
|
*/
|
|
void sqlite3_snapshot_free(sqlite3_snapshot *pSnapshot){
|
|
sqlite3_free(pSnapshot);
|
|
}
|
|
#endif /* SQLITE_ENABLE_SNAPSHOT */
|