
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
2722 lines
82 KiB
C
2722 lines
82 KiB
C
/*
|
|
** 2014 Jun 09
|
|
**
|
|
** 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.
|
|
**
|
|
******************************************************************************
|
|
**
|
|
** This is an SQLite module implementing full-text search.
|
|
*/
|
|
|
|
|
|
#include "fts5Int.h"
|
|
|
|
/*
|
|
** This variable is set to false when running tests for which the on disk
|
|
** structures should not be corrupt. Otherwise, true. If it is false, extra
|
|
** assert() conditions in the fts5 code are activated - conditions that are
|
|
** only true if it is guaranteed that the fts5 database is not corrupt.
|
|
*/
|
|
int sqlite3_fts5_may_be_corrupt = 1;
|
|
|
|
|
|
typedef struct Fts5Auxdata Fts5Auxdata;
|
|
typedef struct Fts5Auxiliary Fts5Auxiliary;
|
|
typedef struct Fts5Cursor Fts5Cursor;
|
|
typedef struct Fts5Sorter Fts5Sorter;
|
|
typedef struct Fts5Table Fts5Table;
|
|
typedef struct Fts5TokenizerModule Fts5TokenizerModule;
|
|
|
|
/*
|
|
** NOTES ON TRANSACTIONS:
|
|
**
|
|
** SQLite invokes the following virtual table methods as transactions are
|
|
** opened and closed by the user:
|
|
**
|
|
** xBegin(): Start of a new transaction.
|
|
** xSync(): Initial part of two-phase commit.
|
|
** xCommit(): Final part of two-phase commit.
|
|
** xRollback(): Rollback the transaction.
|
|
**
|
|
** Anything that is required as part of a commit that may fail is performed
|
|
** in the xSync() callback. Current versions of SQLite ignore any errors
|
|
** returned by xCommit().
|
|
**
|
|
** And as sub-transactions are opened/closed:
|
|
**
|
|
** xSavepoint(int S): Open savepoint S.
|
|
** xRelease(int S): Commit and close savepoint S.
|
|
** xRollbackTo(int S): Rollback to start of savepoint S.
|
|
**
|
|
** During a write-transaction the fts5_index.c module may cache some data
|
|
** in-memory. It is flushed to disk whenever xSync(), xRelease() or
|
|
** xSavepoint() is called. And discarded whenever xRollback() or xRollbackTo()
|
|
** is called.
|
|
**
|
|
** Additionally, if SQLITE_DEBUG is defined, an instance of the following
|
|
** structure is used to record the current transaction state. This information
|
|
** is not required, but it is used in the assert() statements executed by
|
|
** function fts5CheckTransactionState() (see below).
|
|
*/
|
|
struct Fts5TransactionState {
|
|
int eState; /* 0==closed, 1==open, 2==synced */
|
|
int iSavepoint; /* Number of open savepoints (0 -> none) */
|
|
};
|
|
|
|
/*
|
|
** A single object of this type is allocated when the FTS5 module is
|
|
** registered with a database handle. It is used to store pointers to
|
|
** all registered FTS5 extensions - tokenizers and auxiliary functions.
|
|
*/
|
|
struct Fts5Global {
|
|
fts5_api api; /* User visible part of object (see fts5.h) */
|
|
sqlite3 *db; /* Associated database connection */
|
|
i64 iNextId; /* Used to allocate unique cursor ids */
|
|
Fts5Auxiliary *pAux; /* First in list of all aux. functions */
|
|
Fts5TokenizerModule *pTok; /* First in list of all tokenizer modules */
|
|
Fts5TokenizerModule *pDfltTok; /* Default tokenizer module */
|
|
Fts5Cursor *pCsr; /* First in list of all open cursors */
|
|
};
|
|
|
|
/*
|
|
** Each auxiliary function registered with the FTS5 module is represented
|
|
** by an object of the following type. All such objects are stored as part
|
|
** of the Fts5Global.pAux list.
|
|
*/
|
|
struct Fts5Auxiliary {
|
|
Fts5Global *pGlobal; /* Global context for this function */
|
|
char *zFunc; /* Function name (nul-terminated) */
|
|
void *pUserData; /* User-data pointer */
|
|
fts5_extension_function xFunc; /* Callback function */
|
|
void (*xDestroy)(void*); /* Destructor function */
|
|
Fts5Auxiliary *pNext; /* Next registered auxiliary function */
|
|
};
|
|
|
|
/*
|
|
** Each tokenizer module registered with the FTS5 module is represented
|
|
** by an object of the following type. All such objects are stored as part
|
|
** of the Fts5Global.pTok list.
|
|
*/
|
|
struct Fts5TokenizerModule {
|
|
char *zName; /* Name of tokenizer */
|
|
void *pUserData; /* User pointer passed to xCreate() */
|
|
fts5_tokenizer x; /* Tokenizer functions */
|
|
void (*xDestroy)(void*); /* Destructor function */
|
|
Fts5TokenizerModule *pNext; /* Next registered tokenizer module */
|
|
};
|
|
|
|
/*
|
|
** Virtual-table object.
|
|
*/
|
|
struct Fts5Table {
|
|
sqlite3_vtab base; /* Base class used by SQLite core */
|
|
Fts5Config *pConfig; /* Virtual table configuration */
|
|
Fts5Index *pIndex; /* Full-text index */
|
|
Fts5Storage *pStorage; /* Document store */
|
|
Fts5Global *pGlobal; /* Global (connection wide) data */
|
|
Fts5Cursor *pSortCsr; /* Sort data from this cursor */
|
|
#ifdef SQLITE_DEBUG
|
|
struct Fts5TransactionState ts;
|
|
#endif
|
|
};
|
|
|
|
struct Fts5MatchPhrase {
|
|
Fts5Buffer *pPoslist; /* Pointer to current poslist */
|
|
int nTerm; /* Size of phrase in terms */
|
|
};
|
|
|
|
/*
|
|
** pStmt:
|
|
** SELECT rowid, <fts> FROM <fts> ORDER BY +rank;
|
|
**
|
|
** aIdx[]:
|
|
** There is one entry in the aIdx[] array for each phrase in the query,
|
|
** the value of which is the offset within aPoslist[] following the last
|
|
** byte of the position list for the corresponding phrase.
|
|
*/
|
|
struct Fts5Sorter {
|
|
sqlite3_stmt *pStmt;
|
|
i64 iRowid; /* Current rowid */
|
|
const u8 *aPoslist; /* Position lists for current row */
|
|
int nIdx; /* Number of entries in aIdx[] */
|
|
int aIdx[1]; /* Offsets into aPoslist for current row */
|
|
};
|
|
|
|
|
|
/*
|
|
** Virtual-table cursor object.
|
|
**
|
|
** iSpecial:
|
|
** If this is a 'special' query (refer to function fts5SpecialMatch()),
|
|
** then this variable contains the result of the query.
|
|
**
|
|
** iFirstRowid, iLastRowid:
|
|
** These variables are only used for FTS5_PLAN_MATCH cursors. Assuming the
|
|
** cursor iterates in ascending order of rowids, iFirstRowid is the lower
|
|
** limit of rowids to return, and iLastRowid the upper. In other words, the
|
|
** WHERE clause in the user's query might have been:
|
|
**
|
|
** <tbl> MATCH <expr> AND rowid BETWEEN $iFirstRowid AND $iLastRowid
|
|
**
|
|
** If the cursor iterates in descending order of rowid, iFirstRowid
|
|
** is the upper limit (i.e. the "first" rowid visited) and iLastRowid
|
|
** the lower.
|
|
*/
|
|
struct Fts5Cursor {
|
|
sqlite3_vtab_cursor base; /* Base class used by SQLite core */
|
|
Fts5Cursor *pNext; /* Next cursor in Fts5Cursor.pCsr list */
|
|
int *aColumnSize; /* Values for xColumnSize() */
|
|
i64 iCsrId; /* Cursor id */
|
|
|
|
/* Zero from this point onwards on cursor reset */
|
|
int ePlan; /* FTS5_PLAN_XXX value */
|
|
int bDesc; /* True for "ORDER BY rowid DESC" queries */
|
|
i64 iFirstRowid; /* Return no rowids earlier than this */
|
|
i64 iLastRowid; /* Return no rowids later than this */
|
|
sqlite3_stmt *pStmt; /* Statement used to read %_content */
|
|
Fts5Expr *pExpr; /* Expression for MATCH queries */
|
|
Fts5Sorter *pSorter; /* Sorter for "ORDER BY rank" queries */
|
|
int csrflags; /* Mask of cursor flags (see below) */
|
|
i64 iSpecial; /* Result of special query */
|
|
|
|
/* "rank" function. Populated on demand from vtab.xColumn(). */
|
|
char *zRank; /* Custom rank function */
|
|
char *zRankArgs; /* Custom rank function args */
|
|
Fts5Auxiliary *pRank; /* Rank callback (or NULL) */
|
|
int nRankArg; /* Number of trailing arguments for rank() */
|
|
sqlite3_value **apRankArg; /* Array of trailing arguments */
|
|
sqlite3_stmt *pRankArgStmt; /* Origin of objects in apRankArg[] */
|
|
|
|
/* Auxiliary data storage */
|
|
Fts5Auxiliary *pAux; /* Currently executing extension function */
|
|
Fts5Auxdata *pAuxdata; /* First in linked list of saved aux-data */
|
|
|
|
/* Cache used by auxiliary functions xInst() and xInstCount() */
|
|
Fts5PoslistReader *aInstIter; /* One for each phrase */
|
|
int nInstAlloc; /* Size of aInst[] array (entries / 3) */
|
|
int nInstCount; /* Number of phrase instances */
|
|
int *aInst; /* 3 integers per phrase instance */
|
|
};
|
|
|
|
/*
|
|
** Bits that make up the "idxNum" parameter passed indirectly by
|
|
** xBestIndex() to xFilter().
|
|
*/
|
|
#define FTS5_BI_MATCH 0x0001 /* <tbl> MATCH ? */
|
|
#define FTS5_BI_RANK 0x0002 /* rank MATCH ? */
|
|
#define FTS5_BI_ROWID_EQ 0x0004 /* rowid == ? */
|
|
#define FTS5_BI_ROWID_LE 0x0008 /* rowid <= ? */
|
|
#define FTS5_BI_ROWID_GE 0x0010 /* rowid >= ? */
|
|
|
|
#define FTS5_BI_ORDER_RANK 0x0020
|
|
#define FTS5_BI_ORDER_ROWID 0x0040
|
|
#define FTS5_BI_ORDER_DESC 0x0080
|
|
|
|
/*
|
|
** Values for Fts5Cursor.csrflags
|
|
*/
|
|
#define FTS5CSR_EOF 0x01
|
|
#define FTS5CSR_REQUIRE_CONTENT 0x02
|
|
#define FTS5CSR_REQUIRE_DOCSIZE 0x04
|
|
#define FTS5CSR_REQUIRE_INST 0x08
|
|
#define FTS5CSR_FREE_ZRANK 0x10
|
|
#define FTS5CSR_REQUIRE_RESEEK 0x20
|
|
#define FTS5CSR_REQUIRE_POSLIST 0x40
|
|
|
|
#define BitFlagAllTest(x,y) (((x) & (y))==(y))
|
|
#define BitFlagTest(x,y) (((x) & (y))!=0)
|
|
|
|
|
|
/*
|
|
** Macros to Set(), Clear() and Test() cursor flags.
|
|
*/
|
|
#define CsrFlagSet(pCsr, flag) ((pCsr)->csrflags |= (flag))
|
|
#define CsrFlagClear(pCsr, flag) ((pCsr)->csrflags &= ~(flag))
|
|
#define CsrFlagTest(pCsr, flag) ((pCsr)->csrflags & (flag))
|
|
|
|
struct Fts5Auxdata {
|
|
Fts5Auxiliary *pAux; /* Extension to which this belongs */
|
|
void *pPtr; /* Pointer value */
|
|
void(*xDelete)(void*); /* Destructor */
|
|
Fts5Auxdata *pNext; /* Next object in linked list */
|
|
};
|
|
|
|
#ifdef SQLITE_DEBUG
|
|
#define FTS5_BEGIN 1
|
|
#define FTS5_SYNC 2
|
|
#define FTS5_COMMIT 3
|
|
#define FTS5_ROLLBACK 4
|
|
#define FTS5_SAVEPOINT 5
|
|
#define FTS5_RELEASE 6
|
|
#define FTS5_ROLLBACKTO 7
|
|
static void fts5CheckTransactionState(Fts5Table *p, int op, int iSavepoint){
|
|
switch( op ){
|
|
case FTS5_BEGIN:
|
|
assert( p->ts.eState==0 );
|
|
p->ts.eState = 1;
|
|
p->ts.iSavepoint = -1;
|
|
break;
|
|
|
|
case FTS5_SYNC:
|
|
assert( p->ts.eState==1 );
|
|
p->ts.eState = 2;
|
|
break;
|
|
|
|
case FTS5_COMMIT:
|
|
assert( p->ts.eState==2 );
|
|
p->ts.eState = 0;
|
|
break;
|
|
|
|
case FTS5_ROLLBACK:
|
|
assert( p->ts.eState==1 || p->ts.eState==2 || p->ts.eState==0 );
|
|
p->ts.eState = 0;
|
|
break;
|
|
|
|
case FTS5_SAVEPOINT:
|
|
assert( p->ts.eState==1 );
|
|
assert( iSavepoint>=0 );
|
|
assert( iSavepoint>p->ts.iSavepoint );
|
|
p->ts.iSavepoint = iSavepoint;
|
|
break;
|
|
|
|
case FTS5_RELEASE:
|
|
assert( p->ts.eState==1 );
|
|
assert( iSavepoint>=0 );
|
|
assert( iSavepoint<=p->ts.iSavepoint );
|
|
p->ts.iSavepoint = iSavepoint-1;
|
|
break;
|
|
|
|
case FTS5_ROLLBACKTO:
|
|
assert( p->ts.eState==1 );
|
|
assert( iSavepoint>=0 );
|
|
assert( iSavepoint<=p->ts.iSavepoint );
|
|
p->ts.iSavepoint = iSavepoint;
|
|
break;
|
|
}
|
|
}
|
|
#else
|
|
# define fts5CheckTransactionState(x,y,z)
|
|
#endif
|
|
|
|
/*
|
|
** Return true if pTab is a contentless table.
|
|
*/
|
|
static int fts5IsContentless(Fts5Table *pTab){
|
|
return pTab->pConfig->eContent==FTS5_CONTENT_NONE;
|
|
}
|
|
|
|
/*
|
|
** Delete a virtual table handle allocated by fts5InitVtab().
|
|
*/
|
|
static void fts5FreeVtab(Fts5Table *pTab){
|
|
if( pTab ){
|
|
sqlite3Fts5IndexClose(pTab->pIndex);
|
|
sqlite3Fts5StorageClose(pTab->pStorage);
|
|
sqlite3Fts5ConfigFree(pTab->pConfig);
|
|
sqlite3_free(pTab);
|
|
}
|
|
}
|
|
|
|
/*
|
|
** The xDisconnect() virtual table method.
|
|
*/
|
|
static int fts5DisconnectMethod(sqlite3_vtab *pVtab){
|
|
fts5FreeVtab((Fts5Table*)pVtab);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** The xDestroy() virtual table method.
|
|
*/
|
|
static int fts5DestroyMethod(sqlite3_vtab *pVtab){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
int rc = sqlite3Fts5DropAll(pTab->pConfig);
|
|
if( rc==SQLITE_OK ){
|
|
fts5FreeVtab((Fts5Table*)pVtab);
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** This function is the implementation of both the xConnect and xCreate
|
|
** methods of the FTS3 virtual table.
|
|
**
|
|
** The argv[] array contains the following:
|
|
**
|
|
** argv[0] -> module name ("fts5")
|
|
** argv[1] -> database name
|
|
** argv[2] -> table name
|
|
** argv[...] -> "column name" and other module argument fields.
|
|
*/
|
|
static int fts5InitVtab(
|
|
int bCreate, /* True for xCreate, false for xConnect */
|
|
sqlite3 *db, /* The SQLite database connection */
|
|
void *pAux, /* Hash table containing tokenizers */
|
|
int argc, /* Number of elements in argv array */
|
|
const char * const *argv, /* xCreate/xConnect argument array */
|
|
sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */
|
|
char **pzErr /* Write any error message here */
|
|
){
|
|
Fts5Global *pGlobal = (Fts5Global*)pAux;
|
|
const char **azConfig = (const char**)argv;
|
|
int rc = SQLITE_OK; /* Return code */
|
|
Fts5Config *pConfig = 0; /* Results of parsing argc/argv */
|
|
Fts5Table *pTab = 0; /* New virtual table object */
|
|
|
|
/* Allocate the new vtab object and parse the configuration */
|
|
pTab = (Fts5Table*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Table));
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5ConfigParse(pGlobal, db, argc, azConfig, &pConfig, pzErr);
|
|
assert( (rc==SQLITE_OK && *pzErr==0) || pConfig==0 );
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
pTab->pConfig = pConfig;
|
|
pTab->pGlobal = pGlobal;
|
|
}
|
|
|
|
/* Open the index sub-system */
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5IndexOpen(pConfig, bCreate, &pTab->pIndex, pzErr);
|
|
}
|
|
|
|
/* Open the storage sub-system */
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5StorageOpen(
|
|
pConfig, pTab->pIndex, bCreate, &pTab->pStorage, pzErr
|
|
);
|
|
}
|
|
|
|
/* Call sqlite3_declare_vtab() */
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5ConfigDeclareVtab(pConfig);
|
|
}
|
|
|
|
/* Load the initial configuration */
|
|
if( rc==SQLITE_OK ){
|
|
assert( pConfig->pzErrmsg==0 );
|
|
pConfig->pzErrmsg = pzErr;
|
|
rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
|
|
sqlite3Fts5IndexRollback(pTab->pIndex);
|
|
pConfig->pzErrmsg = 0;
|
|
}
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
fts5FreeVtab(pTab);
|
|
pTab = 0;
|
|
}else if( bCreate ){
|
|
fts5CheckTransactionState(pTab, FTS5_BEGIN, 0);
|
|
}
|
|
*ppVTab = (sqlite3_vtab*)pTab;
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** The xConnect() and xCreate() methods for the virtual table. All the
|
|
** work is done in function fts5InitVtab().
|
|
*/
|
|
static int fts5ConnectMethod(
|
|
sqlite3 *db, /* Database connection */
|
|
void *pAux, /* Pointer to tokenizer hash table */
|
|
int argc, /* Number of elements in argv array */
|
|
const char * const *argv, /* xCreate/xConnect argument array */
|
|
sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
|
|
char **pzErr /* OUT: sqlite3_malloc'd error message */
|
|
){
|
|
return fts5InitVtab(0, db, pAux, argc, argv, ppVtab, pzErr);
|
|
}
|
|
static int fts5CreateMethod(
|
|
sqlite3 *db, /* Database connection */
|
|
void *pAux, /* Pointer to tokenizer hash table */
|
|
int argc, /* Number of elements in argv array */
|
|
const char * const *argv, /* xCreate/xConnect argument array */
|
|
sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
|
|
char **pzErr /* OUT: sqlite3_malloc'd error message */
|
|
){
|
|
return fts5InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
|
|
}
|
|
|
|
/*
|
|
** The different query plans.
|
|
*/
|
|
#define FTS5_PLAN_MATCH 1 /* (<tbl> MATCH ?) */
|
|
#define FTS5_PLAN_SOURCE 2 /* A source cursor for SORTED_MATCH */
|
|
#define FTS5_PLAN_SPECIAL 3 /* An internal query */
|
|
#define FTS5_PLAN_SORTED_MATCH 4 /* (<tbl> MATCH ? ORDER BY rank) */
|
|
#define FTS5_PLAN_SCAN 5 /* No usable constraint */
|
|
#define FTS5_PLAN_ROWID 6 /* (rowid = ?) */
|
|
|
|
/*
|
|
** Set the SQLITE_INDEX_SCAN_UNIQUE flag in pIdxInfo->flags. Unless this
|
|
** extension is currently being used by a version of SQLite too old to
|
|
** support index-info flags. In that case this function is a no-op.
|
|
*/
|
|
static void fts5SetUniqueFlag(sqlite3_index_info *pIdxInfo){
|
|
#if SQLITE_VERSION_NUMBER>=3008012
|
|
#ifndef SQLITE_CORE
|
|
if( sqlite3_libversion_number()>=3008012 )
|
|
#endif
|
|
{
|
|
pIdxInfo->idxFlags |= SQLITE_INDEX_SCAN_UNIQUE;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
** Implementation of the xBestIndex method for FTS5 tables. Within the
|
|
** WHERE constraint, it searches for the following:
|
|
**
|
|
** 1. A MATCH constraint against the special column.
|
|
** 2. A MATCH constraint against the "rank" column.
|
|
** 3. An == constraint against the rowid column.
|
|
** 4. A < or <= constraint against the rowid column.
|
|
** 5. A > or >= constraint against the rowid column.
|
|
**
|
|
** Within the ORDER BY, either:
|
|
**
|
|
** 5. ORDER BY rank [ASC|DESC]
|
|
** 6. ORDER BY rowid [ASC|DESC]
|
|
**
|
|
** Costs are assigned as follows:
|
|
**
|
|
** a) If an unusable MATCH operator is present in the WHERE clause, the
|
|
** cost is unconditionally set to 1e50 (a really big number).
|
|
**
|
|
** a) If a MATCH operator is present, the cost depends on the other
|
|
** constraints also present. As follows:
|
|
**
|
|
** * No other constraints: cost=1000.0
|
|
** * One rowid range constraint: cost=750.0
|
|
** * Both rowid range constraints: cost=500.0
|
|
** * An == rowid constraint: cost=100.0
|
|
**
|
|
** b) Otherwise, if there is no MATCH:
|
|
**
|
|
** * No other constraints: cost=1000000.0
|
|
** * One rowid range constraint: cost=750000.0
|
|
** * Both rowid range constraints: cost=250000.0
|
|
** * An == rowid constraint: cost=10.0
|
|
**
|
|
** Costs are not modified by the ORDER BY clause.
|
|
*/
|
|
static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
|
Fts5Table *pTab = (Fts5Table*)pVTab;
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
int idxFlags = 0; /* Parameter passed through to xFilter() */
|
|
int bHasMatch;
|
|
int iNext;
|
|
int i;
|
|
|
|
struct Constraint {
|
|
int op; /* Mask against sqlite3_index_constraint.op */
|
|
int fts5op; /* FTS5 mask for idxFlags */
|
|
int iCol; /* 0==rowid, 1==tbl, 2==rank */
|
|
int omit; /* True to omit this if found */
|
|
int iConsIndex; /* Index in pInfo->aConstraint[] */
|
|
} aConstraint[] = {
|
|
{SQLITE_INDEX_CONSTRAINT_MATCH|SQLITE_INDEX_CONSTRAINT_EQ,
|
|
FTS5_BI_MATCH, 1, 1, -1},
|
|
{SQLITE_INDEX_CONSTRAINT_MATCH|SQLITE_INDEX_CONSTRAINT_EQ,
|
|
FTS5_BI_RANK, 2, 1, -1},
|
|
{SQLITE_INDEX_CONSTRAINT_EQ, FTS5_BI_ROWID_EQ, 0, 0, -1},
|
|
{SQLITE_INDEX_CONSTRAINT_LT|SQLITE_INDEX_CONSTRAINT_LE,
|
|
FTS5_BI_ROWID_LE, 0, 0, -1},
|
|
{SQLITE_INDEX_CONSTRAINT_GT|SQLITE_INDEX_CONSTRAINT_GE,
|
|
FTS5_BI_ROWID_GE, 0, 0, -1},
|
|
};
|
|
|
|
int aColMap[3];
|
|
aColMap[0] = -1;
|
|
aColMap[1] = pConfig->nCol;
|
|
aColMap[2] = pConfig->nCol+1;
|
|
|
|
/* Set idxFlags flags for all WHERE clause terms that will be used. */
|
|
for(i=0; i<pInfo->nConstraint; i++){
|
|
struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
|
|
int j;
|
|
for(j=0; j<ArraySize(aConstraint); j++){
|
|
struct Constraint *pC = &aConstraint[j];
|
|
if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){
|
|
if( p->usable ){
|
|
pC->iConsIndex = i;
|
|
idxFlags |= pC->fts5op;
|
|
}else if( j==0 ){
|
|
/* As there exists an unusable MATCH constraint this is an
|
|
** unusable plan. Set a prohibitively high cost. */
|
|
pInfo->estimatedCost = 1e50;
|
|
return SQLITE_OK;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Set idxFlags flags for the ORDER BY clause */
|
|
if( pInfo->nOrderBy==1 ){
|
|
int iSort = pInfo->aOrderBy[0].iColumn;
|
|
if( iSort==(pConfig->nCol+1) && BitFlagTest(idxFlags, FTS5_BI_MATCH) ){
|
|
idxFlags |= FTS5_BI_ORDER_RANK;
|
|
}else if( iSort==-1 ){
|
|
idxFlags |= FTS5_BI_ORDER_ROWID;
|
|
}
|
|
if( BitFlagTest(idxFlags, FTS5_BI_ORDER_RANK|FTS5_BI_ORDER_ROWID) ){
|
|
pInfo->orderByConsumed = 1;
|
|
if( pInfo->aOrderBy[0].desc ){
|
|
idxFlags |= FTS5_BI_ORDER_DESC;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Calculate the estimated cost based on the flags set in idxFlags. */
|
|
bHasMatch = BitFlagTest(idxFlags, FTS5_BI_MATCH);
|
|
if( BitFlagTest(idxFlags, FTS5_BI_ROWID_EQ) ){
|
|
pInfo->estimatedCost = bHasMatch ? 100.0 : 10.0;
|
|
if( bHasMatch==0 ) fts5SetUniqueFlag(pInfo);
|
|
}else if( BitFlagAllTest(idxFlags, FTS5_BI_ROWID_LE|FTS5_BI_ROWID_GE) ){
|
|
pInfo->estimatedCost = bHasMatch ? 500.0 : 250000.0;
|
|
}else if( BitFlagTest(idxFlags, FTS5_BI_ROWID_LE|FTS5_BI_ROWID_GE) ){
|
|
pInfo->estimatedCost = bHasMatch ? 750.0 : 750000.0;
|
|
}else{
|
|
pInfo->estimatedCost = bHasMatch ? 1000.0 : 1000000.0;
|
|
}
|
|
|
|
/* Assign argvIndex values to each constraint in use. */
|
|
iNext = 1;
|
|
for(i=0; i<ArraySize(aConstraint); i++){
|
|
struct Constraint *pC = &aConstraint[i];
|
|
if( pC->iConsIndex>=0 ){
|
|
pInfo->aConstraintUsage[pC->iConsIndex].argvIndex = iNext++;
|
|
pInfo->aConstraintUsage[pC->iConsIndex].omit = (unsigned char)pC->omit;
|
|
}
|
|
}
|
|
|
|
pInfo->idxNum = idxFlags;
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Implementation of xOpen method.
|
|
*/
|
|
static int fts5OpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
|
|
Fts5Table *pTab = (Fts5Table*)pVTab;
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
Fts5Cursor *pCsr; /* New cursor object */
|
|
int nByte; /* Bytes of space to allocate */
|
|
int rc = SQLITE_OK; /* Return code */
|
|
|
|
nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
|
|
pCsr = (Fts5Cursor*)sqlite3_malloc(nByte);
|
|
if( pCsr ){
|
|
Fts5Global *pGlobal = pTab->pGlobal;
|
|
memset(pCsr, 0, nByte);
|
|
pCsr->aColumnSize = (int*)&pCsr[1];
|
|
pCsr->pNext = pGlobal->pCsr;
|
|
pGlobal->pCsr = pCsr;
|
|
pCsr->iCsrId = ++pGlobal->iNextId;
|
|
}else{
|
|
rc = SQLITE_NOMEM;
|
|
}
|
|
*ppCsr = (sqlite3_vtab_cursor*)pCsr;
|
|
return rc;
|
|
}
|
|
|
|
static int fts5StmtType(Fts5Cursor *pCsr){
|
|
if( pCsr->ePlan==FTS5_PLAN_SCAN ){
|
|
return (pCsr->bDesc) ? FTS5_STMT_SCAN_DESC : FTS5_STMT_SCAN_ASC;
|
|
}
|
|
return FTS5_STMT_LOOKUP;
|
|
}
|
|
|
|
/*
|
|
** This function is called after the cursor passed as the only argument
|
|
** is moved to point at a different row. It clears all cached data
|
|
** specific to the previous row stored by the cursor object.
|
|
*/
|
|
static void fts5CsrNewrow(Fts5Cursor *pCsr){
|
|
CsrFlagSet(pCsr,
|
|
FTS5CSR_REQUIRE_CONTENT
|
|
| FTS5CSR_REQUIRE_DOCSIZE
|
|
| FTS5CSR_REQUIRE_INST
|
|
| FTS5CSR_REQUIRE_POSLIST
|
|
);
|
|
}
|
|
|
|
static void fts5FreeCursorComponents(Fts5Cursor *pCsr){
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
Fts5Auxdata *pData;
|
|
Fts5Auxdata *pNext;
|
|
|
|
sqlite3_free(pCsr->aInstIter);
|
|
sqlite3_free(pCsr->aInst);
|
|
if( pCsr->pStmt ){
|
|
int eStmt = fts5StmtType(pCsr);
|
|
sqlite3Fts5StorageStmtRelease(pTab->pStorage, eStmt, pCsr->pStmt);
|
|
}
|
|
if( pCsr->pSorter ){
|
|
Fts5Sorter *pSorter = pCsr->pSorter;
|
|
sqlite3_finalize(pSorter->pStmt);
|
|
sqlite3_free(pSorter);
|
|
}
|
|
|
|
if( pCsr->ePlan!=FTS5_PLAN_SOURCE ){
|
|
sqlite3Fts5ExprFree(pCsr->pExpr);
|
|
}
|
|
|
|
for(pData=pCsr->pAuxdata; pData; pData=pNext){
|
|
pNext = pData->pNext;
|
|
if( pData->xDelete ) pData->xDelete(pData->pPtr);
|
|
sqlite3_free(pData);
|
|
}
|
|
|
|
sqlite3_finalize(pCsr->pRankArgStmt);
|
|
sqlite3_free(pCsr->apRankArg);
|
|
|
|
if( CsrFlagTest(pCsr, FTS5CSR_FREE_ZRANK) ){
|
|
sqlite3_free(pCsr->zRank);
|
|
sqlite3_free(pCsr->zRankArgs);
|
|
}
|
|
|
|
memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan - (u8*)pCsr));
|
|
}
|
|
|
|
|
|
/*
|
|
** Close the cursor. For additional information see the documentation
|
|
** on the xClose method of the virtual table interface.
|
|
*/
|
|
static int fts5CloseMethod(sqlite3_vtab_cursor *pCursor){
|
|
if( pCursor ){
|
|
Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
|
Fts5Cursor **pp;
|
|
|
|
fts5FreeCursorComponents(pCsr);
|
|
/* Remove the cursor from the Fts5Global.pCsr list */
|
|
for(pp=&pTab->pGlobal->pCsr; (*pp)!=pCsr; pp=&(*pp)->pNext);
|
|
*pp = pCsr->pNext;
|
|
|
|
sqlite3_free(pCsr);
|
|
}
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
static int fts5SorterNext(Fts5Cursor *pCsr){
|
|
Fts5Sorter *pSorter = pCsr->pSorter;
|
|
int rc;
|
|
|
|
rc = sqlite3_step(pSorter->pStmt);
|
|
if( rc==SQLITE_DONE ){
|
|
rc = SQLITE_OK;
|
|
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
|
}else if( rc==SQLITE_ROW ){
|
|
const u8 *a;
|
|
const u8 *aBlob;
|
|
int nBlob;
|
|
int i;
|
|
int iOff = 0;
|
|
rc = SQLITE_OK;
|
|
|
|
pSorter->iRowid = sqlite3_column_int64(pSorter->pStmt, 0);
|
|
nBlob = sqlite3_column_bytes(pSorter->pStmt, 1);
|
|
aBlob = a = sqlite3_column_blob(pSorter->pStmt, 1);
|
|
|
|
/* nBlob==0 in detail=none mode. */
|
|
if( nBlob>0 ){
|
|
for(i=0; i<(pSorter->nIdx-1); i++){
|
|
int iVal;
|
|
a += fts5GetVarint32(a, iVal);
|
|
iOff += iVal;
|
|
pSorter->aIdx[i] = iOff;
|
|
}
|
|
pSorter->aIdx[i] = &aBlob[nBlob] - a;
|
|
pSorter->aPoslist = a;
|
|
}
|
|
|
|
fts5CsrNewrow(pCsr);
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
|
|
/*
|
|
** Set the FTS5CSR_REQUIRE_RESEEK flag on all FTS5_PLAN_MATCH cursors
|
|
** open on table pTab.
|
|
*/
|
|
static void fts5TripCursors(Fts5Table *pTab){
|
|
Fts5Cursor *pCsr;
|
|
for(pCsr=pTab->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){
|
|
if( pCsr->ePlan==FTS5_PLAN_MATCH
|
|
&& pCsr->base.pVtab==(sqlite3_vtab*)pTab
|
|
){
|
|
CsrFlagSet(pCsr, FTS5CSR_REQUIRE_RESEEK);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
** If the REQUIRE_RESEEK flag is set on the cursor passed as the first
|
|
** argument, close and reopen all Fts5IndexIter iterators that the cursor
|
|
** is using. Then attempt to move the cursor to a rowid equal to or laster
|
|
** (in the cursors sort order - ASC or DESC) than the current rowid.
|
|
**
|
|
** If the new rowid is not equal to the old, set output parameter *pbSkip
|
|
** to 1 before returning. Otherwise, leave it unchanged.
|
|
**
|
|
** Return SQLITE_OK if successful or if no reseek was required, or an
|
|
** error code if an error occurred.
|
|
*/
|
|
static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){
|
|
int rc = SQLITE_OK;
|
|
assert( *pbSkip==0 );
|
|
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_RESEEK) ){
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
int bDesc = pCsr->bDesc;
|
|
i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
|
|
|
|
rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->pIndex, iRowid, bDesc);
|
|
if( rc==SQLITE_OK && iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
|
|
*pbSkip = 1;
|
|
}
|
|
|
|
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_RESEEK);
|
|
fts5CsrNewrow(pCsr);
|
|
if( sqlite3Fts5ExprEof(pCsr->pExpr) ){
|
|
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
|
*pbSkip = 1;
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
|
|
/*
|
|
** Advance the cursor to the next row in the table that matches the
|
|
** search criteria.
|
|
**
|
|
** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
|
|
** even if we reach end-of-file. The fts5EofMethod() will be called
|
|
** subsequently to determine whether or not an EOF was hit.
|
|
*/
|
|
static int fts5NextMethod(sqlite3_vtab_cursor *pCursor){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
|
int rc;
|
|
|
|
assert( (pCsr->ePlan<3)==
|
|
(pCsr->ePlan==FTS5_PLAN_MATCH || pCsr->ePlan==FTS5_PLAN_SOURCE)
|
|
);
|
|
assert( !CsrFlagTest(pCsr, FTS5CSR_EOF) );
|
|
|
|
if( pCsr->ePlan<3 ){
|
|
int bSkip = 0;
|
|
if( (rc = fts5CursorReseek(pCsr, &bSkip)) || bSkip ) return rc;
|
|
rc = sqlite3Fts5ExprNext(pCsr->pExpr, pCsr->iLastRowid);
|
|
CsrFlagSet(pCsr, sqlite3Fts5ExprEof(pCsr->pExpr));
|
|
fts5CsrNewrow(pCsr);
|
|
}else{
|
|
switch( pCsr->ePlan ){
|
|
case FTS5_PLAN_SPECIAL: {
|
|
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
|
rc = SQLITE_OK;
|
|
break;
|
|
}
|
|
|
|
case FTS5_PLAN_SORTED_MATCH: {
|
|
rc = fts5SorterNext(pCsr);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
rc = sqlite3_step(pCsr->pStmt);
|
|
if( rc!=SQLITE_ROW ){
|
|
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
|
rc = sqlite3_reset(pCsr->pStmt);
|
|
}else{
|
|
rc = SQLITE_OK;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
|
|
static int fts5PrepareStatement(
|
|
sqlite3_stmt **ppStmt,
|
|
Fts5Config *pConfig,
|
|
const char *zFmt,
|
|
...
|
|
){
|
|
sqlite3_stmt *pRet = 0;
|
|
int rc;
|
|
char *zSql;
|
|
va_list ap;
|
|
|
|
va_start(ap, zFmt);
|
|
zSql = sqlite3_vmprintf(zFmt, ap);
|
|
if( zSql==0 ){
|
|
rc = SQLITE_NOMEM;
|
|
}else{
|
|
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0);
|
|
if( rc!=SQLITE_OK ){
|
|
*pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db));
|
|
}
|
|
sqlite3_free(zSql);
|
|
}
|
|
|
|
va_end(ap);
|
|
*ppStmt = pRet;
|
|
return rc;
|
|
}
|
|
|
|
static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
Fts5Sorter *pSorter;
|
|
int nPhrase;
|
|
int nByte;
|
|
int rc;
|
|
const char *zRank = pCsr->zRank;
|
|
const char *zRankArgs = pCsr->zRankArgs;
|
|
|
|
nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
|
|
nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
|
|
pSorter = (Fts5Sorter*)sqlite3_malloc(nByte);
|
|
if( pSorter==0 ) return SQLITE_NOMEM;
|
|
memset(pSorter, 0, nByte);
|
|
pSorter->nIdx = nPhrase;
|
|
|
|
/* TODO: It would be better to have some system for reusing statement
|
|
** handles here, rather than preparing a new one for each query. But that
|
|
** is not possible as SQLite reference counts the virtual table objects.
|
|
** And since the statement required here reads from this very virtual
|
|
** table, saving it creates a circular reference.
|
|
**
|
|
** If SQLite a built-in statement cache, this wouldn't be a problem. */
|
|
rc = fts5PrepareStatement(&pSorter->pStmt, pConfig,
|
|
"SELECT rowid, rank FROM %Q.%Q ORDER BY %s(%s%s%s) %s",
|
|
pConfig->zDb, pConfig->zName, zRank, pConfig->zName,
|
|
(zRankArgs ? ", " : ""),
|
|
(zRankArgs ? zRankArgs : ""),
|
|
bDesc ? "DESC" : "ASC"
|
|
);
|
|
|
|
pCsr->pSorter = pSorter;
|
|
if( rc==SQLITE_OK ){
|
|
assert( pTab->pSortCsr==0 );
|
|
pTab->pSortCsr = pCsr;
|
|
rc = fts5SorterNext(pCsr);
|
|
pTab->pSortCsr = 0;
|
|
}
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
sqlite3_finalize(pSorter->pStmt);
|
|
sqlite3_free(pSorter);
|
|
pCsr->pSorter = 0;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int fts5CursorFirst(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
|
|
int rc;
|
|
Fts5Expr *pExpr = pCsr->pExpr;
|
|
rc = sqlite3Fts5ExprFirst(pExpr, pTab->pIndex, pCsr->iFirstRowid, bDesc);
|
|
if( sqlite3Fts5ExprEof(pExpr) ){
|
|
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
|
}
|
|
fts5CsrNewrow(pCsr);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Process a "special" query. A special query is identified as one with a
|
|
** MATCH expression that begins with a '*' character. The remainder of
|
|
** the text passed to the MATCH operator are used as the special query
|
|
** parameters.
|
|
*/
|
|
static int fts5SpecialMatch(
|
|
Fts5Table *pTab,
|
|
Fts5Cursor *pCsr,
|
|
const char *zQuery
|
|
){
|
|
int rc = SQLITE_OK; /* Return code */
|
|
const char *z = zQuery; /* Special query text */
|
|
int n; /* Number of bytes in text at z */
|
|
|
|
while( z[0]==' ' ) z++;
|
|
for(n=0; z[n] && z[n]!=' '; n++);
|
|
|
|
assert( pTab->base.zErrMsg==0 );
|
|
pCsr->ePlan = FTS5_PLAN_SPECIAL;
|
|
|
|
if( 0==sqlite3_strnicmp("reads", z, n) ){
|
|
pCsr->iSpecial = sqlite3Fts5IndexReads(pTab->pIndex);
|
|
}
|
|
else if( 0==sqlite3_strnicmp("id", z, n) ){
|
|
pCsr->iSpecial = pCsr->iCsrId;
|
|
}
|
|
else{
|
|
/* An unrecognized directive. Return an error message. */
|
|
pTab->base.zErrMsg = sqlite3_mprintf("unknown special query: %.*s", n, z);
|
|
rc = SQLITE_ERROR;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Search for an auxiliary function named zName that can be used with table
|
|
** pTab. If one is found, return a pointer to the corresponding Fts5Auxiliary
|
|
** structure. Otherwise, if no such function exists, return NULL.
|
|
*/
|
|
static Fts5Auxiliary *fts5FindAuxiliary(Fts5Table *pTab, const char *zName){
|
|
Fts5Auxiliary *pAux;
|
|
|
|
for(pAux=pTab->pGlobal->pAux; pAux; pAux=pAux->pNext){
|
|
if( sqlite3_stricmp(zName, pAux->zFunc)==0 ) return pAux;
|
|
}
|
|
|
|
/* No function of the specified name was found. Return 0. */
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int fts5FindRankFunction(Fts5Cursor *pCsr){
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
int rc = SQLITE_OK;
|
|
Fts5Auxiliary *pAux = 0;
|
|
const char *zRank = pCsr->zRank;
|
|
const char *zRankArgs = pCsr->zRankArgs;
|
|
|
|
if( zRankArgs ){
|
|
char *zSql = sqlite3Fts5Mprintf(&rc, "SELECT %s", zRankArgs);
|
|
if( zSql ){
|
|
sqlite3_stmt *pStmt = 0;
|
|
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pStmt, 0);
|
|
sqlite3_free(zSql);
|
|
assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
|
|
if( rc==SQLITE_OK ){
|
|
if( SQLITE_ROW==sqlite3_step(pStmt) ){
|
|
int nByte;
|
|
pCsr->nRankArg = sqlite3_column_count(pStmt);
|
|
nByte = sizeof(sqlite3_value*)*pCsr->nRankArg;
|
|
pCsr->apRankArg = (sqlite3_value**)sqlite3Fts5MallocZero(&rc, nByte);
|
|
if( rc==SQLITE_OK ){
|
|
int i;
|
|
for(i=0; i<pCsr->nRankArg; i++){
|
|
pCsr->apRankArg[i] = sqlite3_column_value(pStmt, i);
|
|
}
|
|
}
|
|
pCsr->pRankArgStmt = pStmt;
|
|
}else{
|
|
rc = sqlite3_finalize(pStmt);
|
|
assert( rc!=SQLITE_OK );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( rc==SQLITE_OK ){
|
|
pAux = fts5FindAuxiliary(pTab, zRank);
|
|
if( pAux==0 ){
|
|
assert( pTab->base.zErrMsg==0 );
|
|
pTab->base.zErrMsg = sqlite3_mprintf("no such function: %s", zRank);
|
|
rc = SQLITE_ERROR;
|
|
}
|
|
}
|
|
|
|
pCsr->pRank = pAux;
|
|
return rc;
|
|
}
|
|
|
|
|
|
static int fts5CursorParseRank(
|
|
Fts5Config *pConfig,
|
|
Fts5Cursor *pCsr,
|
|
sqlite3_value *pRank
|
|
){
|
|
int rc = SQLITE_OK;
|
|
if( pRank ){
|
|
const char *z = (const char*)sqlite3_value_text(pRank);
|
|
char *zRank = 0;
|
|
char *zRankArgs = 0;
|
|
|
|
if( z==0 ){
|
|
if( sqlite3_value_type(pRank)==SQLITE_NULL ) rc = SQLITE_ERROR;
|
|
}else{
|
|
rc = sqlite3Fts5ConfigParseRank(z, &zRank, &zRankArgs);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
pCsr->zRank = zRank;
|
|
pCsr->zRankArgs = zRankArgs;
|
|
CsrFlagSet(pCsr, FTS5CSR_FREE_ZRANK);
|
|
}else if( rc==SQLITE_ERROR ){
|
|
pCsr->base.pVtab->zErrMsg = sqlite3_mprintf(
|
|
"parse error in rank function: %s", z
|
|
);
|
|
}
|
|
}else{
|
|
if( pConfig->zRank ){
|
|
pCsr->zRank = (char*)pConfig->zRank;
|
|
pCsr->zRankArgs = (char*)pConfig->zRankArgs;
|
|
}else{
|
|
pCsr->zRank = (char*)FTS5_DEFAULT_RANK;
|
|
pCsr->zRankArgs = 0;
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static i64 fts5GetRowidLimit(sqlite3_value *pVal, i64 iDefault){
|
|
if( pVal ){
|
|
int eType = sqlite3_value_numeric_type(pVal);
|
|
if( eType==SQLITE_INTEGER ){
|
|
return sqlite3_value_int64(pVal);
|
|
}
|
|
}
|
|
return iDefault;
|
|
}
|
|
|
|
/*
|
|
** This is the xFilter interface for the virtual table. See
|
|
** the virtual table xFilter method documentation for additional
|
|
** information.
|
|
**
|
|
** There are three possible query strategies:
|
|
**
|
|
** 1. Full-text search using a MATCH operator.
|
|
** 2. A by-rowid lookup.
|
|
** 3. A full-table scan.
|
|
*/
|
|
static int fts5FilterMethod(
|
|
sqlite3_vtab_cursor *pCursor, /* The cursor used for this query */
|
|
int idxNum, /* Strategy index */
|
|
const char *zUnused, /* Unused */
|
|
int nVal, /* Number of elements in apVal */
|
|
sqlite3_value **apVal /* Arguments for the indexing scheme */
|
|
){
|
|
Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
|
int rc = SQLITE_OK; /* Error code */
|
|
int iVal = 0; /* Counter for apVal[] */
|
|
int bDesc; /* True if ORDER BY [rank|rowid] DESC */
|
|
int bOrderByRank; /* True if ORDER BY rank */
|
|
sqlite3_value *pMatch = 0; /* <tbl> MATCH ? expression (or NULL) */
|
|
sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
|
|
sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
|
|
sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
|
|
sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
|
|
char **pzErrmsg = pConfig->pzErrmsg;
|
|
|
|
UNUSED_PARAM(zUnused);
|
|
UNUSED_PARAM(nVal);
|
|
|
|
if( pCsr->ePlan ){
|
|
fts5FreeCursorComponents(pCsr);
|
|
memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
|
|
}
|
|
|
|
assert( pCsr->pStmt==0 );
|
|
assert( pCsr->pExpr==0 );
|
|
assert( pCsr->csrflags==0 );
|
|
assert( pCsr->pRank==0 );
|
|
assert( pCsr->zRank==0 );
|
|
assert( pCsr->zRankArgs==0 );
|
|
|
|
assert( pzErrmsg==0 || pzErrmsg==&pTab->base.zErrMsg );
|
|
pConfig->pzErrmsg = &pTab->base.zErrMsg;
|
|
|
|
/* Decode the arguments passed through to this function.
|
|
**
|
|
** Note: The following set of if(...) statements must be in the same
|
|
** order as the corresponding entries in the struct at the top of
|
|
** fts5BestIndexMethod(). */
|
|
if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
|
|
if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
|
|
if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
|
|
if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
|
|
if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
|
|
assert( iVal==nVal );
|
|
bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
|
|
pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
|
|
|
|
/* Set the cursor upper and lower rowid limits. Only some strategies
|
|
** actually use them. This is ok, as the xBestIndex() method leaves the
|
|
** sqlite3_index_constraint.omit flag clear for range constraints
|
|
** on the rowid field. */
|
|
if( pRowidEq ){
|
|
pRowidLe = pRowidGe = pRowidEq;
|
|
}
|
|
if( bDesc ){
|
|
pCsr->iFirstRowid = fts5GetRowidLimit(pRowidLe, LARGEST_INT64);
|
|
pCsr->iLastRowid = fts5GetRowidLimit(pRowidGe, SMALLEST_INT64);
|
|
}else{
|
|
pCsr->iLastRowid = fts5GetRowidLimit(pRowidLe, LARGEST_INT64);
|
|
pCsr->iFirstRowid = fts5GetRowidLimit(pRowidGe, SMALLEST_INT64);
|
|
}
|
|
|
|
if( pTab->pSortCsr ){
|
|
/* If pSortCsr is non-NULL, then this call is being made as part of
|
|
** processing for a "... MATCH <expr> ORDER BY rank" query (ePlan is
|
|
** set to FTS5_PLAN_SORTED_MATCH). pSortCsr is the cursor that will
|
|
** return results to the user for this query. The current cursor
|
|
** (pCursor) is used to execute the query issued by function
|
|
** fts5CursorFirstSorted() above. */
|
|
assert( pRowidEq==0 && pRowidLe==0 && pRowidGe==0 && pRank==0 );
|
|
assert( nVal==0 && pMatch==0 && bOrderByRank==0 && bDesc==0 );
|
|
assert( pCsr->iLastRowid==LARGEST_INT64 );
|
|
assert( pCsr->iFirstRowid==SMALLEST_INT64 );
|
|
pCsr->ePlan = FTS5_PLAN_SOURCE;
|
|
pCsr->pExpr = pTab->pSortCsr->pExpr;
|
|
rc = fts5CursorFirst(pTab, pCsr, bDesc);
|
|
sqlite3Fts5ExprClearEof(pCsr->pExpr);
|
|
}else if( pMatch ){
|
|
const char *zExpr = (const char*)sqlite3_value_text(apVal[0]);
|
|
if( zExpr==0 ) zExpr = "";
|
|
|
|
rc = fts5CursorParseRank(pConfig, pCsr, pRank);
|
|
if( rc==SQLITE_OK ){
|
|
if( zExpr[0]=='*' ){
|
|
/* The user has issued a query of the form "MATCH '*...'". This
|
|
** indicates that the MATCH expression is not a full text query,
|
|
** but a request for an internal parameter. */
|
|
rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
|
|
}else{
|
|
char **pzErr = &pTab->base.zErrMsg;
|
|
rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pCsr->pExpr, pzErr);
|
|
if( rc==SQLITE_OK ){
|
|
if( bOrderByRank ){
|
|
pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
|
|
rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
|
|
}else{
|
|
pCsr->ePlan = FTS5_PLAN_MATCH;
|
|
rc = fts5CursorFirst(pTab, pCsr, bDesc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}else if( pConfig->zContent==0 ){
|
|
*pConfig->pzErrmsg = sqlite3_mprintf(
|
|
"%s: table does not support scanning", pConfig->zName
|
|
);
|
|
rc = SQLITE_ERROR;
|
|
}else{
|
|
/* This is either a full-table scan (ePlan==FTS5_PLAN_SCAN) or a lookup
|
|
** by rowid (ePlan==FTS5_PLAN_ROWID). */
|
|
pCsr->ePlan = (pRowidEq ? FTS5_PLAN_ROWID : FTS5_PLAN_SCAN);
|
|
rc = sqlite3Fts5StorageStmt(
|
|
pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->base.zErrMsg
|
|
);
|
|
if( rc==SQLITE_OK ){
|
|
if( pCsr->ePlan==FTS5_PLAN_ROWID ){
|
|
sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]);
|
|
}else{
|
|
sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iFirstRowid);
|
|
sqlite3_bind_int64(pCsr->pStmt, 2, pCsr->iLastRowid);
|
|
}
|
|
rc = fts5NextMethod(pCursor);
|
|
}
|
|
}
|
|
|
|
pConfig->pzErrmsg = pzErrmsg;
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** This is the xEof method of the virtual table. SQLite calls this
|
|
** routine to find out if it has reached the end of a result set.
|
|
*/
|
|
static int fts5EofMethod(sqlite3_vtab_cursor *pCursor){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
|
return (CsrFlagTest(pCsr, FTS5CSR_EOF) ? 1 : 0);
|
|
}
|
|
|
|
/*
|
|
** Return the rowid that the cursor currently points to.
|
|
*/
|
|
static i64 fts5CursorRowid(Fts5Cursor *pCsr){
|
|
assert( pCsr->ePlan==FTS5_PLAN_MATCH
|
|
|| pCsr->ePlan==FTS5_PLAN_SORTED_MATCH
|
|
|| pCsr->ePlan==FTS5_PLAN_SOURCE
|
|
);
|
|
if( pCsr->pSorter ){
|
|
return pCsr->pSorter->iRowid;
|
|
}else{
|
|
return sqlite3Fts5ExprRowid(pCsr->pExpr);
|
|
}
|
|
}
|
|
|
|
/*
|
|
** This is the xRowid method. The SQLite core calls this routine to
|
|
** retrieve the rowid for the current row of the result set. fts5
|
|
** exposes %_content.rowid as the rowid for the virtual table. The
|
|
** rowid should be written to *pRowid.
|
|
*/
|
|
static int fts5RowidMethod(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
|
int ePlan = pCsr->ePlan;
|
|
|
|
assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
|
|
switch( ePlan ){
|
|
case FTS5_PLAN_SPECIAL:
|
|
*pRowid = 0;
|
|
break;
|
|
|
|
case FTS5_PLAN_SOURCE:
|
|
case FTS5_PLAN_MATCH:
|
|
case FTS5_PLAN_SORTED_MATCH:
|
|
*pRowid = fts5CursorRowid(pCsr);
|
|
break;
|
|
|
|
default:
|
|
*pRowid = sqlite3_column_int64(pCsr->pStmt, 0);
|
|
break;
|
|
}
|
|
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** If the cursor requires seeking (bSeekRequired flag is set), seek it.
|
|
** Return SQLITE_OK if no error occurs, or an SQLite error code otherwise.
|
|
**
|
|
** If argument bErrormsg is true and an error occurs, an error message may
|
|
** be left in sqlite3_vtab.zErrMsg.
|
|
*/
|
|
static int fts5SeekCursor(Fts5Cursor *pCsr, int bErrormsg){
|
|
int rc = SQLITE_OK;
|
|
|
|
/* If the cursor does not yet have a statement handle, obtain one now. */
|
|
if( pCsr->pStmt==0 ){
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
int eStmt = fts5StmtType(pCsr);
|
|
rc = sqlite3Fts5StorageStmt(
|
|
pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->base.zErrMsg:0)
|
|
);
|
|
assert( rc!=SQLITE_OK || pTab->base.zErrMsg==0 );
|
|
assert( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) );
|
|
}
|
|
|
|
if( rc==SQLITE_OK && CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) ){
|
|
assert( pCsr->pExpr );
|
|
sqlite3_reset(pCsr->pStmt);
|
|
sqlite3_bind_int64(pCsr->pStmt, 1, fts5CursorRowid(pCsr));
|
|
rc = sqlite3_step(pCsr->pStmt);
|
|
if( rc==SQLITE_ROW ){
|
|
rc = SQLITE_OK;
|
|
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_CONTENT);
|
|
}else{
|
|
rc = sqlite3_reset(pCsr->pStmt);
|
|
if( rc==SQLITE_OK ){
|
|
rc = FTS5_CORRUPT;
|
|
}
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static void fts5SetVtabError(Fts5Table *p, const char *zFormat, ...){
|
|
va_list ap; /* ... printf arguments */
|
|
va_start(ap, zFormat);
|
|
assert( p->base.zErrMsg==0 );
|
|
p->base.zErrMsg = sqlite3_vmprintf(zFormat, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
/*
|
|
** This function is called to handle an FTS INSERT command. In other words,
|
|
** an INSERT statement of the form:
|
|
**
|
|
** INSERT INTO fts(fts) VALUES($pCmd)
|
|
** INSERT INTO fts(fts, rank) VALUES($pCmd, $pVal)
|
|
**
|
|
** Argument pVal is the value assigned to column "fts" by the INSERT
|
|
** statement. This function returns SQLITE_OK if successful, or an SQLite
|
|
** error code if an error occurs.
|
|
**
|
|
** The commands implemented by this function are documented in the "Special
|
|
** INSERT Directives" section of the documentation. It should be updated if
|
|
** more commands are added to this function.
|
|
*/
|
|
static int fts5SpecialInsert(
|
|
Fts5Table *pTab, /* Fts5 table object */
|
|
const char *zCmd, /* Text inserted into table-name column */
|
|
sqlite3_value *pVal /* Value inserted into rank column */
|
|
){
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
int rc = SQLITE_OK;
|
|
int bError = 0;
|
|
|
|
if( 0==sqlite3_stricmp("delete-all", zCmd) ){
|
|
if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
|
fts5SetVtabError(pTab,
|
|
"'delete-all' may only be used with a "
|
|
"contentless or external content fts5 table"
|
|
);
|
|
rc = SQLITE_ERROR;
|
|
}else{
|
|
rc = sqlite3Fts5StorageDeleteAll(pTab->pStorage);
|
|
}
|
|
}else if( 0==sqlite3_stricmp("rebuild", zCmd) ){
|
|
if( pConfig->eContent==FTS5_CONTENT_NONE ){
|
|
fts5SetVtabError(pTab,
|
|
"'rebuild' may not be used with a contentless fts5 table"
|
|
);
|
|
rc = SQLITE_ERROR;
|
|
}else{
|
|
rc = sqlite3Fts5StorageRebuild(pTab->pStorage);
|
|
}
|
|
}else if( 0==sqlite3_stricmp("optimize", zCmd) ){
|
|
rc = sqlite3Fts5StorageOptimize(pTab->pStorage);
|
|
}else if( 0==sqlite3_stricmp("merge", zCmd) ){
|
|
int nMerge = sqlite3_value_int(pVal);
|
|
rc = sqlite3Fts5StorageMerge(pTab->pStorage, nMerge);
|
|
}else if( 0==sqlite3_stricmp("integrity-check", zCmd) ){
|
|
rc = sqlite3Fts5StorageIntegrity(pTab->pStorage);
|
|
#ifdef SQLITE_DEBUG
|
|
}else if( 0==sqlite3_stricmp("prefix-index", zCmd) ){
|
|
pConfig->bPrefixIndex = sqlite3_value_int(pVal);
|
|
#endif
|
|
}else{
|
|
rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5ConfigSetValue(pTab->pConfig, zCmd, pVal, &bError);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
if( bError ){
|
|
rc = SQLITE_ERROR;
|
|
}else{
|
|
rc = sqlite3Fts5StorageConfigValue(pTab->pStorage, zCmd, pVal, 0);
|
|
}
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static int fts5SpecialDelete(
|
|
Fts5Table *pTab,
|
|
sqlite3_value **apVal
|
|
){
|
|
int rc = SQLITE_OK;
|
|
int eType1 = sqlite3_value_type(apVal[1]);
|
|
if( eType1==SQLITE_INTEGER ){
|
|
sqlite3_int64 iDel = sqlite3_value_int64(apVal[1]);
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, &apVal[2]);
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static void fts5StorageInsert(
|
|
int *pRc,
|
|
Fts5Table *pTab,
|
|
sqlite3_value **apVal,
|
|
i64 *piRowid
|
|
){
|
|
int rc = *pRc;
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, piRowid);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *piRowid);
|
|
}
|
|
*pRc = rc;
|
|
}
|
|
|
|
/*
|
|
** This function is the implementation of the xUpdate callback used by
|
|
** FTS3 virtual tables. It is invoked by SQLite each time a row is to be
|
|
** inserted, updated or deleted.
|
|
**
|
|
** A delete specifies a single argument - the rowid of the row to remove.
|
|
**
|
|
** Update and insert operations pass:
|
|
**
|
|
** 1. The "old" rowid, or NULL.
|
|
** 2. The "new" rowid.
|
|
** 3. Values for each of the nCol matchable columns.
|
|
** 4. Values for the two hidden columns (<tablename> and "rank").
|
|
*/
|
|
static int fts5UpdateMethod(
|
|
sqlite3_vtab *pVtab, /* Virtual table handle */
|
|
int nArg, /* Size of argument array */
|
|
sqlite3_value **apVal, /* Array of arguments */
|
|
sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */
|
|
){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
int eType0; /* value_type() of apVal[0] */
|
|
int rc = SQLITE_OK; /* Return code */
|
|
|
|
/* A transaction must be open when this is called. */
|
|
assert( pTab->ts.eState==1 );
|
|
|
|
assert( pVtab->zErrMsg==0 );
|
|
assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
|
|
assert( nArg==1
|
|
|| sqlite3_value_type(apVal[1])==SQLITE_INTEGER
|
|
|| sqlite3_value_type(apVal[1])==SQLITE_NULL
|
|
);
|
|
assert( pTab->pConfig->pzErrmsg==0 );
|
|
pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
|
|
|
|
/* Put any active cursors into REQUIRE_SEEK state. */
|
|
fts5TripCursors(pTab);
|
|
|
|
eType0 = sqlite3_value_type(apVal[0]);
|
|
if( eType0==SQLITE_NULL
|
|
&& sqlite3_value_type(apVal[2+pConfig->nCol])!=SQLITE_NULL
|
|
){
|
|
/* A "special" INSERT op. These are handled separately. */
|
|
const char *z = (const char*)sqlite3_value_text(apVal[2+pConfig->nCol]);
|
|
if( pConfig->eContent!=FTS5_CONTENT_NORMAL
|
|
&& 0==sqlite3_stricmp("delete", z)
|
|
){
|
|
rc = fts5SpecialDelete(pTab, apVal);
|
|
}else{
|
|
rc = fts5SpecialInsert(pTab, z, apVal[2 + pConfig->nCol + 1]);
|
|
}
|
|
}else{
|
|
/* A regular INSERT, UPDATE or DELETE statement. The trick here is that
|
|
** any conflict on the rowid value must be detected before any
|
|
** modifications are made to the database file. There are 4 cases:
|
|
**
|
|
** 1) DELETE
|
|
** 2) UPDATE (rowid not modified)
|
|
** 3) UPDATE (rowid modified)
|
|
** 4) INSERT
|
|
**
|
|
** Cases 3 and 4 may violate the rowid constraint.
|
|
*/
|
|
int eConflict = SQLITE_ABORT;
|
|
if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
|
eConflict = sqlite3_vtab_on_conflict(pConfig->db);
|
|
}
|
|
|
|
assert( eType0==SQLITE_INTEGER || eType0==SQLITE_NULL );
|
|
assert( nArg!=1 || eType0==SQLITE_INTEGER );
|
|
|
|
/* Filter out attempts to run UPDATE or DELETE on contentless tables.
|
|
** This is not suported. */
|
|
if( eType0==SQLITE_INTEGER && fts5IsContentless(pTab) ){
|
|
pTab->base.zErrMsg = sqlite3_mprintf(
|
|
"cannot %s contentless fts5 table: %s",
|
|
(nArg>1 ? "UPDATE" : "DELETE from"), pConfig->zName
|
|
);
|
|
rc = SQLITE_ERROR;
|
|
}
|
|
|
|
/* Case 1: DELETE */
|
|
else if( nArg==1 ){
|
|
i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
|
|
}
|
|
|
|
/* Case 2: INSERT */
|
|
else if( eType0!=SQLITE_INTEGER ){
|
|
/* If this is a REPLACE, first remove the current entry (if any) */
|
|
if( eConflict==SQLITE_REPLACE
|
|
&& sqlite3_value_type(apVal[1])==SQLITE_INTEGER
|
|
){
|
|
i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
|
}
|
|
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
|
}
|
|
|
|
/* Case 2: UPDATE */
|
|
else{
|
|
i64 iOld = sqlite3_value_int64(apVal[0]); /* Old rowid */
|
|
i64 iNew = sqlite3_value_int64(apVal[1]); /* New rowid */
|
|
if( iOld!=iNew ){
|
|
if( eConflict==SQLITE_REPLACE ){
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
|
}
|
|
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
|
}else{
|
|
rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *pRowid);
|
|
}
|
|
}
|
|
}else{
|
|
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
|
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
|
}
|
|
}
|
|
}
|
|
|
|
pTab->pConfig->pzErrmsg = 0;
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Implementation of xSync() method.
|
|
*/
|
|
static int fts5SyncMethod(sqlite3_vtab *pVtab){
|
|
int rc;
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
|
|
pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
|
|
fts5TripCursors(pTab);
|
|
rc = sqlite3Fts5StorageSync(pTab->pStorage, 1);
|
|
pTab->pConfig->pzErrmsg = 0;
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Implementation of xBegin() method.
|
|
*/
|
|
static int fts5BeginMethod(sqlite3_vtab *pVtab){
|
|
UNUSED_PARAM(pVtab); /* Call below is a no-op for NDEBUG builds */
|
|
fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_BEGIN, 0);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Implementation of xCommit() method. This is a no-op. The contents of
|
|
** the pending-terms hash-table have already been flushed into the database
|
|
** by fts5SyncMethod().
|
|
*/
|
|
static int fts5CommitMethod(sqlite3_vtab *pVtab){
|
|
UNUSED_PARAM(pVtab); /* Call below is a no-op for NDEBUG builds */
|
|
fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_COMMIT, 0);
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
/*
|
|
** Implementation of xRollback(). Discard the contents of the pending-terms
|
|
** hash-table. Any changes made to the database are reverted by SQLite.
|
|
*/
|
|
static int fts5RollbackMethod(sqlite3_vtab *pVtab){
|
|
int rc;
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
|
|
rc = sqlite3Fts5StorageRollback(pTab->pStorage);
|
|
return rc;
|
|
}
|
|
|
|
static int fts5CsrPoslist(Fts5Cursor*, int, const u8**, int*);
|
|
|
|
static void *fts5ApiUserData(Fts5Context *pCtx){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
return pCsr->pAux->pUserData;
|
|
}
|
|
|
|
static int fts5ApiColumnCount(Fts5Context *pCtx){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
return ((Fts5Table*)(pCsr->base.pVtab))->pConfig->nCol;
|
|
}
|
|
|
|
static int fts5ApiColumnTotalSize(
|
|
Fts5Context *pCtx,
|
|
int iCol,
|
|
sqlite3_int64 *pnToken
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
return sqlite3Fts5StorageSize(pTab->pStorage, iCol, pnToken);
|
|
}
|
|
|
|
static int fts5ApiRowCount(Fts5Context *pCtx, i64 *pnRow){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
return sqlite3Fts5StorageRowCount(pTab->pStorage, pnRow);
|
|
}
|
|
|
|
static int fts5ApiTokenize(
|
|
Fts5Context *pCtx,
|
|
const char *pText, int nText,
|
|
void *pUserData,
|
|
int (*xToken)(void*, int, const char*, int, int, int)
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
return sqlite3Fts5Tokenize(
|
|
pTab->pConfig, FTS5_TOKENIZE_AUX, pText, nText, pUserData, xToken
|
|
);
|
|
}
|
|
|
|
static int fts5ApiPhraseCount(Fts5Context *pCtx){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
return sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
|
|
}
|
|
|
|
static int fts5ApiPhraseSize(Fts5Context *pCtx, int iPhrase){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
return sqlite3Fts5ExprPhraseSize(pCsr->pExpr, iPhrase);
|
|
}
|
|
|
|
static int fts5ApiColumnText(
|
|
Fts5Context *pCtx,
|
|
int iCol,
|
|
const char **pz,
|
|
int *pn
|
|
){
|
|
int rc = SQLITE_OK;
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
if( fts5IsContentless((Fts5Table*)(pCsr->base.pVtab)) ){
|
|
*pz = 0;
|
|
*pn = 0;
|
|
}else{
|
|
rc = fts5SeekCursor(pCsr, 0);
|
|
if( rc==SQLITE_OK ){
|
|
*pz = (const char*)sqlite3_column_text(pCsr->pStmt, iCol+1);
|
|
*pn = sqlite3_column_bytes(pCsr->pStmt, iCol+1);
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static int fts5CsrPoslist(
|
|
Fts5Cursor *pCsr,
|
|
int iPhrase,
|
|
const u8 **pa,
|
|
int *pn
|
|
){
|
|
Fts5Config *pConfig = ((Fts5Table*)(pCsr->base.pVtab))->pConfig;
|
|
int rc = SQLITE_OK;
|
|
int bLive = (pCsr->pSorter==0);
|
|
|
|
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_POSLIST) ){
|
|
|
|
if( pConfig->eDetail!=FTS5_DETAIL_FULL ){
|
|
Fts5PoslistPopulator *aPopulator;
|
|
int i;
|
|
aPopulator = sqlite3Fts5ExprClearPoslists(pCsr->pExpr, bLive);
|
|
if( aPopulator==0 ) rc = SQLITE_NOMEM;
|
|
for(i=0; i<pConfig->nCol && rc==SQLITE_OK; i++){
|
|
int n; const char *z;
|
|
rc = fts5ApiColumnText((Fts5Context*)pCsr, i, &z, &n);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5ExprPopulatePoslists(
|
|
pConfig, pCsr->pExpr, aPopulator, i, z, n
|
|
);
|
|
}
|
|
}
|
|
sqlite3_free(aPopulator);
|
|
|
|
if( pCsr->pSorter ){
|
|
sqlite3Fts5ExprCheckPoslists(pCsr->pExpr, pCsr->pSorter->iRowid);
|
|
}
|
|
}
|
|
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_POSLIST);
|
|
}
|
|
|
|
if( pCsr->pSorter && pConfig->eDetail==FTS5_DETAIL_FULL ){
|
|
Fts5Sorter *pSorter = pCsr->pSorter;
|
|
int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
|
|
*pn = pSorter->aIdx[iPhrase] - i1;
|
|
*pa = &pSorter->aPoslist[i1];
|
|
}else{
|
|
*pn = sqlite3Fts5ExprPoslist(pCsr->pExpr, iPhrase, pa);
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Ensure that the Fts5Cursor.nInstCount and aInst[] variables are populated
|
|
** correctly for the current view. Return SQLITE_OK if successful, or an
|
|
** SQLite error code otherwise.
|
|
*/
|
|
static int fts5CacheInstArray(Fts5Cursor *pCsr){
|
|
int rc = SQLITE_OK;
|
|
Fts5PoslistReader *aIter; /* One iterator for each phrase */
|
|
int nIter; /* Number of iterators/phrases */
|
|
|
|
nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
|
|
if( pCsr->aInstIter==0 ){
|
|
int nByte = sizeof(Fts5PoslistReader) * nIter;
|
|
pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
|
|
}
|
|
aIter = pCsr->aInstIter;
|
|
|
|
if( aIter ){
|
|
int nInst = 0; /* Number instances seen so far */
|
|
int i;
|
|
|
|
/* Initialize all iterators */
|
|
for(i=0; i<nIter && rc==SQLITE_OK; i++){
|
|
const u8 *a;
|
|
int n;
|
|
rc = fts5CsrPoslist(pCsr, i, &a, &n);
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3Fts5PoslistReaderInit(a, n, &aIter[i]);
|
|
}
|
|
}
|
|
|
|
if( rc==SQLITE_OK ){
|
|
while( 1 ){
|
|
int *aInst;
|
|
int iBest = -1;
|
|
for(i=0; i<nIter; i++){
|
|
if( (aIter[i].bEof==0)
|
|
&& (iBest<0 || aIter[i].iPos<aIter[iBest].iPos)
|
|
){
|
|
iBest = i;
|
|
}
|
|
}
|
|
if( iBest<0 ) break;
|
|
|
|
nInst++;
|
|
if( nInst>=pCsr->nInstAlloc ){
|
|
pCsr->nInstAlloc = pCsr->nInstAlloc ? pCsr->nInstAlloc*2 : 32;
|
|
aInst = (int*)sqlite3_realloc(
|
|
pCsr->aInst, pCsr->nInstAlloc*sizeof(int)*3
|
|
);
|
|
if( aInst ){
|
|
pCsr->aInst = aInst;
|
|
}else{
|
|
rc = SQLITE_NOMEM;
|
|
break;
|
|
}
|
|
}
|
|
|
|
aInst = &pCsr->aInst[3 * (nInst-1)];
|
|
aInst[0] = iBest;
|
|
aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
|
|
aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
|
|
sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
|
|
}
|
|
}
|
|
|
|
pCsr->nInstCount = nInst;
|
|
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_INST);
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static int fts5ApiInstCount(Fts5Context *pCtx, int *pnInst){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
int rc = SQLITE_OK;
|
|
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
|
|
|| SQLITE_OK==(rc = fts5CacheInstArray(pCsr)) ){
|
|
*pnInst = pCsr->nInstCount;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static int fts5ApiInst(
|
|
Fts5Context *pCtx,
|
|
int iIdx,
|
|
int *piPhrase,
|
|
int *piCol,
|
|
int *piOff
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
int rc = SQLITE_OK;
|
|
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_INST)==0
|
|
|| SQLITE_OK==(rc = fts5CacheInstArray(pCsr))
|
|
){
|
|
if( iIdx<0 || iIdx>=pCsr->nInstCount ){
|
|
rc = SQLITE_RANGE;
|
|
#if 0
|
|
}else if( fts5IsOffsetless((Fts5Table*)pCsr->base.pVtab) ){
|
|
*piPhrase = pCsr->aInst[iIdx*3];
|
|
*piCol = pCsr->aInst[iIdx*3 + 2];
|
|
*piOff = -1;
|
|
#endif
|
|
}else{
|
|
*piPhrase = pCsr->aInst[iIdx*3];
|
|
*piCol = pCsr->aInst[iIdx*3 + 1];
|
|
*piOff = pCsr->aInst[iIdx*3 + 2];
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static sqlite3_int64 fts5ApiRowid(Fts5Context *pCtx){
|
|
return fts5CursorRowid((Fts5Cursor*)pCtx);
|
|
}
|
|
|
|
static int fts5ColumnSizeCb(
|
|
void *pContext, /* Pointer to int */
|
|
int tflags,
|
|
const char *pUnused, /* Buffer containing token */
|
|
int nUnused, /* Size of token in bytes */
|
|
int iUnused1, /* Start offset of token */
|
|
int iUnused2 /* End offset of token */
|
|
){
|
|
int *pCnt = (int*)pContext;
|
|
UNUSED_PARAM2(pUnused, nUnused);
|
|
UNUSED_PARAM2(iUnused1, iUnused2);
|
|
if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
|
|
(*pCnt)++;
|
|
}
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
static int fts5ApiColumnSize(Fts5Context *pCtx, int iCol, int *pnToken){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
int rc = SQLITE_OK;
|
|
|
|
if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_DOCSIZE) ){
|
|
if( pConfig->bColumnsize ){
|
|
i64 iRowid = fts5CursorRowid(pCsr);
|
|
rc = sqlite3Fts5StorageDocsize(pTab->pStorage, iRowid, pCsr->aColumnSize);
|
|
}else if( pConfig->zContent==0 ){
|
|
int i;
|
|
for(i=0; i<pConfig->nCol; i++){
|
|
if( pConfig->abUnindexed[i]==0 ){
|
|
pCsr->aColumnSize[i] = -1;
|
|
}
|
|
}
|
|
}else{
|
|
int i;
|
|
for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
|
|
if( pConfig->abUnindexed[i]==0 ){
|
|
const char *z; int n;
|
|
void *p = (void*)(&pCsr->aColumnSize[i]);
|
|
pCsr->aColumnSize[i] = 0;
|
|
rc = fts5ApiColumnText(pCtx, i, &z, &n);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3Fts5Tokenize(
|
|
pConfig, FTS5_TOKENIZE_AUX, z, n, p, fts5ColumnSizeCb
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_DOCSIZE);
|
|
}
|
|
if( iCol<0 ){
|
|
int i;
|
|
*pnToken = 0;
|
|
for(i=0; i<pConfig->nCol; i++){
|
|
*pnToken += pCsr->aColumnSize[i];
|
|
}
|
|
}else if( iCol<pConfig->nCol ){
|
|
*pnToken = pCsr->aColumnSize[iCol];
|
|
}else{
|
|
*pnToken = 0;
|
|
rc = SQLITE_RANGE;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Implementation of the xSetAuxdata() method.
|
|
*/
|
|
static int fts5ApiSetAuxdata(
|
|
Fts5Context *pCtx, /* Fts5 context */
|
|
void *pPtr, /* Pointer to save as auxdata */
|
|
void(*xDelete)(void*) /* Destructor for pPtr (or NULL) */
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Auxdata *pData;
|
|
|
|
/* Search through the cursors list of Fts5Auxdata objects for one that
|
|
** corresponds to the currently executing auxiliary function. */
|
|
for(pData=pCsr->pAuxdata; pData; pData=pData->pNext){
|
|
if( pData->pAux==pCsr->pAux ) break;
|
|
}
|
|
|
|
if( pData ){
|
|
if( pData->xDelete ){
|
|
pData->xDelete(pData->pPtr);
|
|
}
|
|
}else{
|
|
int rc = SQLITE_OK;
|
|
pData = (Fts5Auxdata*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Auxdata));
|
|
if( pData==0 ){
|
|
if( xDelete ) xDelete(pPtr);
|
|
return rc;
|
|
}
|
|
pData->pAux = pCsr->pAux;
|
|
pData->pNext = pCsr->pAuxdata;
|
|
pCsr->pAuxdata = pData;
|
|
}
|
|
|
|
pData->xDelete = xDelete;
|
|
pData->pPtr = pPtr;
|
|
return SQLITE_OK;
|
|
}
|
|
|
|
static void *fts5ApiGetAuxdata(Fts5Context *pCtx, int bClear){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Auxdata *pData;
|
|
void *pRet = 0;
|
|
|
|
for(pData=pCsr->pAuxdata; pData; pData=pData->pNext){
|
|
if( pData->pAux==pCsr->pAux ) break;
|
|
}
|
|
|
|
if( pData ){
|
|
pRet = pData->pPtr;
|
|
if( bClear ){
|
|
pData->pPtr = 0;
|
|
pData->xDelete = 0;
|
|
}
|
|
}
|
|
|
|
return pRet;
|
|
}
|
|
|
|
static void fts5ApiPhraseNext(
|
|
Fts5Context *pUnused,
|
|
Fts5PhraseIter *pIter,
|
|
int *piCol, int *piOff
|
|
){
|
|
UNUSED_PARAM(pUnused);
|
|
if( pIter->a>=pIter->b ){
|
|
*piCol = -1;
|
|
*piOff = -1;
|
|
}else{
|
|
int iVal;
|
|
pIter->a += fts5GetVarint32(pIter->a, iVal);
|
|
if( iVal==1 ){
|
|
pIter->a += fts5GetVarint32(pIter->a, iVal);
|
|
*piCol = iVal;
|
|
*piOff = 0;
|
|
pIter->a += fts5GetVarint32(pIter->a, iVal);
|
|
}
|
|
*piOff += (iVal-2);
|
|
}
|
|
}
|
|
|
|
static int fts5ApiPhraseFirst(
|
|
Fts5Context *pCtx,
|
|
int iPhrase,
|
|
Fts5PhraseIter *pIter,
|
|
int *piCol, int *piOff
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
int n;
|
|
int rc = fts5CsrPoslist(pCsr, iPhrase, &pIter->a, &n);
|
|
if( rc==SQLITE_OK ){
|
|
pIter->b = &pIter->a[n];
|
|
*piCol = 0;
|
|
*piOff = 0;
|
|
fts5ApiPhraseNext(pCtx, pIter, piCol, piOff);
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
static void fts5ApiPhraseNextColumn(
|
|
Fts5Context *pCtx,
|
|
Fts5PhraseIter *pIter,
|
|
int *piCol
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Config *pConfig = ((Fts5Table*)(pCsr->base.pVtab))->pConfig;
|
|
|
|
if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
|
|
if( pIter->a>=pIter->b ){
|
|
*piCol = -1;
|
|
}else{
|
|
int iIncr;
|
|
pIter->a += fts5GetVarint32(&pIter->a[0], iIncr);
|
|
*piCol += (iIncr-2);
|
|
}
|
|
}else{
|
|
while( 1 ){
|
|
int dummy;
|
|
if( pIter->a>=pIter->b ){
|
|
*piCol = -1;
|
|
return;
|
|
}
|
|
if( pIter->a[0]==0x01 ) break;
|
|
pIter->a += fts5GetVarint32(pIter->a, dummy);
|
|
}
|
|
pIter->a += 1 + fts5GetVarint32(&pIter->a[1], *piCol);
|
|
}
|
|
}
|
|
|
|
static int fts5ApiPhraseFirstColumn(
|
|
Fts5Context *pCtx,
|
|
int iPhrase,
|
|
Fts5PhraseIter *pIter,
|
|
int *piCol
|
|
){
|
|
int rc = SQLITE_OK;
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Config *pConfig = ((Fts5Table*)(pCsr->base.pVtab))->pConfig;
|
|
|
|
if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
|
|
Fts5Sorter *pSorter = pCsr->pSorter;
|
|
int n;
|
|
if( pSorter ){
|
|
int i1 = (iPhrase==0 ? 0 : pSorter->aIdx[iPhrase-1]);
|
|
n = pSorter->aIdx[iPhrase] - i1;
|
|
pIter->a = &pSorter->aPoslist[i1];
|
|
}else{
|
|
rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, iPhrase, &pIter->a, &n);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
pIter->b = &pIter->a[n];
|
|
*piCol = 0;
|
|
fts5ApiPhraseNextColumn(pCtx, pIter, piCol);
|
|
}
|
|
}else{
|
|
int n;
|
|
rc = fts5CsrPoslist(pCsr, iPhrase, &pIter->a, &n);
|
|
if( rc==SQLITE_OK ){
|
|
pIter->b = &pIter->a[n];
|
|
if( n<=0 ){
|
|
*piCol = -1;
|
|
}else if( pIter->a[0]==0x01 ){
|
|
pIter->a += 1 + fts5GetVarint32(&pIter->a[1], *piCol);
|
|
}else{
|
|
*piCol = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
|
|
static int fts5ApiQueryPhrase(Fts5Context*, int, void*,
|
|
int(*)(const Fts5ExtensionApi*, Fts5Context*, void*)
|
|
);
|
|
|
|
static const Fts5ExtensionApi sFts5Api = {
|
|
2, /* iVersion */
|
|
fts5ApiUserData,
|
|
fts5ApiColumnCount,
|
|
fts5ApiRowCount,
|
|
fts5ApiColumnTotalSize,
|
|
fts5ApiTokenize,
|
|
fts5ApiPhraseCount,
|
|
fts5ApiPhraseSize,
|
|
fts5ApiInstCount,
|
|
fts5ApiInst,
|
|
fts5ApiRowid,
|
|
fts5ApiColumnText,
|
|
fts5ApiColumnSize,
|
|
fts5ApiQueryPhrase,
|
|
fts5ApiSetAuxdata,
|
|
fts5ApiGetAuxdata,
|
|
fts5ApiPhraseFirst,
|
|
fts5ApiPhraseNext,
|
|
fts5ApiPhraseFirstColumn,
|
|
fts5ApiPhraseNextColumn,
|
|
};
|
|
|
|
/*
|
|
** Implementation of API function xQueryPhrase().
|
|
*/
|
|
static int fts5ApiQueryPhrase(
|
|
Fts5Context *pCtx,
|
|
int iPhrase,
|
|
void *pUserData,
|
|
int(*xCallback)(const Fts5ExtensionApi*, Fts5Context*, void*)
|
|
){
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
|
|
Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
|
|
int rc;
|
|
Fts5Cursor *pNew = 0;
|
|
|
|
rc = fts5OpenMethod(pCsr->base.pVtab, (sqlite3_vtab_cursor**)&pNew);
|
|
if( rc==SQLITE_OK ){
|
|
pNew->ePlan = FTS5_PLAN_MATCH;
|
|
pNew->iFirstRowid = SMALLEST_INT64;
|
|
pNew->iLastRowid = LARGEST_INT64;
|
|
pNew->base.pVtab = (sqlite3_vtab*)pTab;
|
|
rc = sqlite3Fts5ExprClonePhrase(pCsr->pExpr, iPhrase, &pNew->pExpr);
|
|
}
|
|
|
|
if( rc==SQLITE_OK ){
|
|
for(rc = fts5CursorFirst(pTab, pNew, 0);
|
|
rc==SQLITE_OK && CsrFlagTest(pNew, FTS5CSR_EOF)==0;
|
|
rc = fts5NextMethod((sqlite3_vtab_cursor*)pNew)
|
|
){
|
|
rc = xCallback(&sFts5Api, (Fts5Context*)pNew, pUserData);
|
|
if( rc!=SQLITE_OK ){
|
|
if( rc==SQLITE_DONE ) rc = SQLITE_OK;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
fts5CloseMethod((sqlite3_vtab_cursor*)pNew);
|
|
return rc;
|
|
}
|
|
|
|
static void fts5ApiInvoke(
|
|
Fts5Auxiliary *pAux,
|
|
Fts5Cursor *pCsr,
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
assert( pCsr->pAux==0 );
|
|
pCsr->pAux = pAux;
|
|
pAux->xFunc(&sFts5Api, (Fts5Context*)pCsr, context, argc, argv);
|
|
pCsr->pAux = 0;
|
|
}
|
|
|
|
static Fts5Cursor *fts5CursorFromCsrid(Fts5Global *pGlobal, i64 iCsrId){
|
|
Fts5Cursor *pCsr;
|
|
for(pCsr=pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){
|
|
if( pCsr->iCsrId==iCsrId ) break;
|
|
}
|
|
return pCsr;
|
|
}
|
|
|
|
static void fts5ApiCallback(
|
|
sqlite3_context *context,
|
|
int argc,
|
|
sqlite3_value **argv
|
|
){
|
|
|
|
Fts5Auxiliary *pAux;
|
|
Fts5Cursor *pCsr;
|
|
i64 iCsrId;
|
|
|
|
assert( argc>=1 );
|
|
pAux = (Fts5Auxiliary*)sqlite3_user_data(context);
|
|
iCsrId = sqlite3_value_int64(argv[0]);
|
|
|
|
pCsr = fts5CursorFromCsrid(pAux->pGlobal, iCsrId);
|
|
if( pCsr==0 ){
|
|
char *zErr = sqlite3_mprintf("no such cursor: %lld", iCsrId);
|
|
sqlite3_result_error(context, zErr, -1);
|
|
sqlite3_free(zErr);
|
|
}else{
|
|
fts5ApiInvoke(pAux, pCsr, context, argc-1, &argv[1]);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
** Given cursor id iId, return a pointer to the corresponding Fts5Index
|
|
** object. Or NULL If the cursor id does not exist.
|
|
**
|
|
** If successful, set *ppConfig to point to the associated config object
|
|
** before returning.
|
|
*/
|
|
Fts5Index *sqlite3Fts5IndexFromCsrid(
|
|
Fts5Global *pGlobal, /* FTS5 global context for db handle */
|
|
i64 iCsrId, /* Id of cursor to find */
|
|
Fts5Config **ppConfig /* OUT: Configuration object */
|
|
){
|
|
Fts5Cursor *pCsr;
|
|
Fts5Table *pTab;
|
|
|
|
pCsr = fts5CursorFromCsrid(pGlobal, iCsrId);
|
|
pTab = (Fts5Table*)pCsr->base.pVtab;
|
|
*ppConfig = pTab->pConfig;
|
|
|
|
return pTab->pIndex;
|
|
}
|
|
|
|
/*
|
|
** Return a "position-list blob" corresponding to the current position of
|
|
** cursor pCsr via sqlite3_result_blob(). A position-list blob contains
|
|
** the current position-list for each phrase in the query associated with
|
|
** cursor pCsr.
|
|
**
|
|
** A position-list blob begins with (nPhrase-1) varints, where nPhrase is
|
|
** the number of phrases in the query. Following the varints are the
|
|
** concatenated position lists for each phrase, in order.
|
|
**
|
|
** The first varint (if it exists) contains the size of the position list
|
|
** for phrase 0. The second (same disclaimer) contains the size of position
|
|
** list 1. And so on. There is no size field for the final position list,
|
|
** as it can be derived from the total size of the blob.
|
|
*/
|
|
static int fts5PoslistBlob(sqlite3_context *pCtx, Fts5Cursor *pCsr){
|
|
int i;
|
|
int rc = SQLITE_OK;
|
|
int nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
|
|
Fts5Buffer val;
|
|
|
|
memset(&val, 0, sizeof(Fts5Buffer));
|
|
switch( ((Fts5Table*)(pCsr->base.pVtab))->pConfig->eDetail ){
|
|
case FTS5_DETAIL_FULL:
|
|
|
|
/* Append the varints */
|
|
for(i=0; i<(nPhrase-1); i++){
|
|
const u8 *dummy;
|
|
int nByte = sqlite3Fts5ExprPoslist(pCsr->pExpr, i, &dummy);
|
|
sqlite3Fts5BufferAppendVarint(&rc, &val, nByte);
|
|
}
|
|
|
|
/* Append the position lists */
|
|
for(i=0; i<nPhrase; i++){
|
|
const u8 *pPoslist;
|
|
int nPoslist;
|
|
nPoslist = sqlite3Fts5ExprPoslist(pCsr->pExpr, i, &pPoslist);
|
|
sqlite3Fts5BufferAppendBlob(&rc, &val, nPoslist, pPoslist);
|
|
}
|
|
break;
|
|
|
|
case FTS5_DETAIL_COLUMNS:
|
|
|
|
/* Append the varints */
|
|
for(i=0; rc==SQLITE_OK && i<(nPhrase-1); i++){
|
|
const u8 *dummy;
|
|
int nByte;
|
|
rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, i, &dummy, &nByte);
|
|
sqlite3Fts5BufferAppendVarint(&rc, &val, nByte);
|
|
}
|
|
|
|
/* Append the position lists */
|
|
for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
|
|
const u8 *pPoslist;
|
|
int nPoslist;
|
|
rc = sqlite3Fts5ExprPhraseCollist(pCsr->pExpr, i, &pPoslist, &nPoslist);
|
|
sqlite3Fts5BufferAppendBlob(&rc, &val, nPoslist, pPoslist);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
sqlite3_result_blob(pCtx, val.p, val.n, sqlite3_free);
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** This is the xColumn method, called by SQLite to request a value from
|
|
** the row that the supplied cursor currently points to.
|
|
*/
|
|
static int fts5ColumnMethod(
|
|
sqlite3_vtab_cursor *pCursor, /* Cursor to retrieve value from */
|
|
sqlite3_context *pCtx, /* Context for sqlite3_result_xxx() calls */
|
|
int iCol /* Index of column to read value from */
|
|
){
|
|
Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
|
|
Fts5Config *pConfig = pTab->pConfig;
|
|
Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
|
|
int rc = SQLITE_OK;
|
|
|
|
assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
|
|
|
|
if( pCsr->ePlan==FTS5_PLAN_SPECIAL ){
|
|
if( iCol==pConfig->nCol ){
|
|
sqlite3_result_int64(pCtx, pCsr->iSpecial);
|
|
}
|
|
}else
|
|
|
|
if( iCol==pConfig->nCol ){
|
|
/* User is requesting the value of the special column with the same name
|
|
** as the table. Return the cursor integer id number. This value is only
|
|
** useful in that it may be passed as the first argument to an FTS5
|
|
** auxiliary function. */
|
|
sqlite3_result_int64(pCtx, pCsr->iCsrId);
|
|
}else if( iCol==pConfig->nCol+1 ){
|
|
|
|
/* The value of the "rank" column. */
|
|
if( pCsr->ePlan==FTS5_PLAN_SOURCE ){
|
|
fts5PoslistBlob(pCtx, pCsr);
|
|
}else if(
|
|
pCsr->ePlan==FTS5_PLAN_MATCH
|
|
|| pCsr->ePlan==FTS5_PLAN_SORTED_MATCH
|
|
){
|
|
if( pCsr->pRank || SQLITE_OK==(rc = fts5FindRankFunction(pCsr)) ){
|
|
fts5ApiInvoke(pCsr->pRank, pCsr, pCtx, pCsr->nRankArg, pCsr->apRankArg);
|
|
}
|
|
}
|
|
}else if( !fts5IsContentless(pTab) ){
|
|
rc = fts5SeekCursor(pCsr, 1);
|
|
if( rc==SQLITE_OK ){
|
|
sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
|
|
}
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
|
|
/*
|
|
** This routine implements the xFindFunction method for the FTS3
|
|
** virtual table.
|
|
*/
|
|
static int fts5FindFunctionMethod(
|
|
sqlite3_vtab *pVtab, /* Virtual table handle */
|
|
int nUnused, /* Number of SQL function arguments */
|
|
const char *zName, /* Name of SQL function */
|
|
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
|
|
void **ppArg /* OUT: User data for *pxFunc */
|
|
){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
Fts5Auxiliary *pAux;
|
|
|
|
UNUSED_PARAM(nUnused);
|
|
pAux = fts5FindAuxiliary(pTab, zName);
|
|
if( pAux ){
|
|
*pxFunc = fts5ApiCallback;
|
|
*ppArg = (void*)pAux;
|
|
return 1;
|
|
}
|
|
|
|
/* No function of the specified name was found. Return 0. */
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
** Implementation of FTS5 xRename method. Rename an fts5 table.
|
|
*/
|
|
static int fts5RenameMethod(
|
|
sqlite3_vtab *pVtab, /* Virtual table handle */
|
|
const char *zName /* New name of table */
|
|
){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
return sqlite3Fts5StorageRename(pTab->pStorage, zName);
|
|
}
|
|
|
|
/*
|
|
** The xSavepoint() method.
|
|
**
|
|
** Flush the contents of the pending-terms table to disk.
|
|
*/
|
|
static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
|
fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
|
|
fts5TripCursors(pTab);
|
|
return sqlite3Fts5StorageSync(pTab->pStorage, 0);
|
|
}
|
|
|
|
/*
|
|
** The xRelease() method.
|
|
**
|
|
** This is a no-op.
|
|
*/
|
|
static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
|
fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
|
|
fts5TripCursors(pTab);
|
|
return sqlite3Fts5StorageSync(pTab->pStorage, 0);
|
|
}
|
|
|
|
/*
|
|
** The xRollbackTo() method.
|
|
**
|
|
** Discard the contents of the pending terms table.
|
|
*/
|
|
static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
|
Fts5Table *pTab = (Fts5Table*)pVtab;
|
|
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
|
fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
|
|
fts5TripCursors(pTab);
|
|
return sqlite3Fts5StorageRollback(pTab->pStorage);
|
|
}
|
|
|
|
/*
|
|
** Register a new auxiliary function with global context pGlobal.
|
|
*/
|
|
static int fts5CreateAux(
|
|
fts5_api *pApi, /* Global context (one per db handle) */
|
|
const char *zName, /* Name of new function */
|
|
void *pUserData, /* User data for aux. function */
|
|
fts5_extension_function xFunc, /* Aux. function implementation */
|
|
void(*xDestroy)(void*) /* Destructor for pUserData */
|
|
){
|
|
Fts5Global *pGlobal = (Fts5Global*)pApi;
|
|
int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
|
|
if( rc==SQLITE_OK ){
|
|
Fts5Auxiliary *pAux;
|
|
int nName; /* Size of zName in bytes, including \0 */
|
|
int nByte; /* Bytes of space to allocate */
|
|
|
|
nName = (int)strlen(zName) + 1;
|
|
nByte = sizeof(Fts5Auxiliary) + nName;
|
|
pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte);
|
|
if( pAux ){
|
|
memset(pAux, 0, nByte);
|
|
pAux->zFunc = (char*)&pAux[1];
|
|
memcpy(pAux->zFunc, zName, nName);
|
|
pAux->pGlobal = pGlobal;
|
|
pAux->pUserData = pUserData;
|
|
pAux->xFunc = xFunc;
|
|
pAux->xDestroy = xDestroy;
|
|
pAux->pNext = pGlobal->pAux;
|
|
pGlobal->pAux = pAux;
|
|
}else{
|
|
rc = SQLITE_NOMEM;
|
|
}
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** Register a new tokenizer. This is the implementation of the
|
|
** fts5_api.xCreateTokenizer() method.
|
|
*/
|
|
static int fts5CreateTokenizer(
|
|
fts5_api *pApi, /* Global context (one per db handle) */
|
|
const char *zName, /* Name of new function */
|
|
void *pUserData, /* User data for aux. function */
|
|
fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
|
|
void(*xDestroy)(void*) /* Destructor for pUserData */
|
|
){
|
|
Fts5Global *pGlobal = (Fts5Global*)pApi;
|
|
Fts5TokenizerModule *pNew;
|
|
int nName; /* Size of zName and its \0 terminator */
|
|
int nByte; /* Bytes of space to allocate */
|
|
int rc = SQLITE_OK;
|
|
|
|
nName = (int)strlen(zName) + 1;
|
|
nByte = sizeof(Fts5TokenizerModule) + nName;
|
|
pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte);
|
|
if( pNew ){
|
|
memset(pNew, 0, nByte);
|
|
pNew->zName = (char*)&pNew[1];
|
|
memcpy(pNew->zName, zName, nName);
|
|
pNew->pUserData = pUserData;
|
|
pNew->x = *pTokenizer;
|
|
pNew->xDestroy = xDestroy;
|
|
pNew->pNext = pGlobal->pTok;
|
|
pGlobal->pTok = pNew;
|
|
if( pNew->pNext==0 ){
|
|
pGlobal->pDfltTok = pNew;
|
|
}
|
|
}else{
|
|
rc = SQLITE_NOMEM;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static Fts5TokenizerModule *fts5LocateTokenizer(
|
|
Fts5Global *pGlobal,
|
|
const char *zName
|
|
){
|
|
Fts5TokenizerModule *pMod = 0;
|
|
|
|
if( zName==0 ){
|
|
pMod = pGlobal->pDfltTok;
|
|
}else{
|
|
for(pMod=pGlobal->pTok; pMod; pMod=pMod->pNext){
|
|
if( sqlite3_stricmp(zName, pMod->zName)==0 ) break;
|
|
}
|
|
}
|
|
|
|
return pMod;
|
|
}
|
|
|
|
/*
|
|
** Find a tokenizer. This is the implementation of the
|
|
** fts5_api.xFindTokenizer() method.
|
|
*/
|
|
static int fts5FindTokenizer(
|
|
fts5_api *pApi, /* Global context (one per db handle) */
|
|
const char *zName, /* Name of new function */
|
|
void **ppUserData,
|
|
fts5_tokenizer *pTokenizer /* Populate this object */
|
|
){
|
|
int rc = SQLITE_OK;
|
|
Fts5TokenizerModule *pMod;
|
|
|
|
pMod = fts5LocateTokenizer((Fts5Global*)pApi, zName);
|
|
if( pMod ){
|
|
*pTokenizer = pMod->x;
|
|
*ppUserData = pMod->pUserData;
|
|
}else{
|
|
memset(pTokenizer, 0, sizeof(fts5_tokenizer));
|
|
rc = SQLITE_ERROR;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
int sqlite3Fts5GetTokenizer(
|
|
Fts5Global *pGlobal,
|
|
const char **azArg,
|
|
int nArg,
|
|
Fts5Tokenizer **ppTok,
|
|
fts5_tokenizer **ppTokApi,
|
|
char **pzErr
|
|
){
|
|
Fts5TokenizerModule *pMod;
|
|
int rc = SQLITE_OK;
|
|
|
|
pMod = fts5LocateTokenizer(pGlobal, nArg==0 ? 0 : azArg[0]);
|
|
if( pMod==0 ){
|
|
assert( nArg>0 );
|
|
rc = SQLITE_ERROR;
|
|
*pzErr = sqlite3_mprintf("no such tokenizer: %s", azArg[0]);
|
|
}else{
|
|
rc = pMod->x.xCreate(pMod->pUserData, &azArg[1], (nArg?nArg-1:0), ppTok);
|
|
*ppTokApi = &pMod->x;
|
|
if( rc!=SQLITE_OK && pzErr ){
|
|
*pzErr = sqlite3_mprintf("error in tokenizer constructor");
|
|
}
|
|
}
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
*ppTokApi = 0;
|
|
*ppTok = 0;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static void fts5ModuleDestroy(void *pCtx){
|
|
Fts5TokenizerModule *pTok, *pNextTok;
|
|
Fts5Auxiliary *pAux, *pNextAux;
|
|
Fts5Global *pGlobal = (Fts5Global*)pCtx;
|
|
|
|
for(pAux=pGlobal->pAux; pAux; pAux=pNextAux){
|
|
pNextAux = pAux->pNext;
|
|
if( pAux->xDestroy ) pAux->xDestroy(pAux->pUserData);
|
|
sqlite3_free(pAux);
|
|
}
|
|
|
|
for(pTok=pGlobal->pTok; pTok; pTok=pNextTok){
|
|
pNextTok = pTok->pNext;
|
|
if( pTok->xDestroy ) pTok->xDestroy(pTok->pUserData);
|
|
sqlite3_free(pTok);
|
|
}
|
|
|
|
sqlite3_free(pGlobal);
|
|
}
|
|
|
|
static void fts5Fts5Func(
|
|
sqlite3_context *pCtx, /* Function call context */
|
|
int nArg, /* Number of args */
|
|
sqlite3_value **apUnused /* Function arguments */
|
|
){
|
|
Fts5Global *pGlobal = (Fts5Global*)sqlite3_user_data(pCtx);
|
|
char buf[8];
|
|
UNUSED_PARAM2(nArg, apUnused);
|
|
assert( nArg==0 );
|
|
assert( sizeof(buf)>=sizeof(pGlobal) );
|
|
memcpy(buf, (void*)&pGlobal, sizeof(pGlobal));
|
|
sqlite3_result_blob(pCtx, buf, sizeof(pGlobal), SQLITE_TRANSIENT);
|
|
}
|
|
|
|
/*
|
|
** Implementation of fts5_source_id() function.
|
|
*/
|
|
static void fts5SourceIdFunc(
|
|
sqlite3_context *pCtx, /* Function call context */
|
|
int nArg, /* Number of args */
|
|
sqlite3_value **apUnused /* Function arguments */
|
|
){
|
|
assert( nArg==0 );
|
|
UNUSED_PARAM2(nArg, apUnused);
|
|
sqlite3_result_text(pCtx, "--FTS5-SOURCE-ID--", -1, SQLITE_TRANSIENT);
|
|
}
|
|
|
|
static int fts5Init(sqlite3 *db){
|
|
static const sqlite3_module fts5Mod = {
|
|
/* iVersion */ 2,
|
|
/* xCreate */ fts5CreateMethod,
|
|
/* xConnect */ fts5ConnectMethod,
|
|
/* xBestIndex */ fts5BestIndexMethod,
|
|
/* xDisconnect */ fts5DisconnectMethod,
|
|
/* xDestroy */ fts5DestroyMethod,
|
|
/* xOpen */ fts5OpenMethod,
|
|
/* xClose */ fts5CloseMethod,
|
|
/* xFilter */ fts5FilterMethod,
|
|
/* xNext */ fts5NextMethod,
|
|
/* xEof */ fts5EofMethod,
|
|
/* xColumn */ fts5ColumnMethod,
|
|
/* xRowid */ fts5RowidMethod,
|
|
/* xUpdate */ fts5UpdateMethod,
|
|
/* xBegin */ fts5BeginMethod,
|
|
/* xSync */ fts5SyncMethod,
|
|
/* xCommit */ fts5CommitMethod,
|
|
/* xRollback */ fts5RollbackMethod,
|
|
/* xFindFunction */ fts5FindFunctionMethod,
|
|
/* xRename */ fts5RenameMethod,
|
|
/* xSavepoint */ fts5SavepointMethod,
|
|
/* xRelease */ fts5ReleaseMethod,
|
|
/* xRollbackTo */ fts5RollbackToMethod,
|
|
};
|
|
|
|
int rc;
|
|
Fts5Global *pGlobal = 0;
|
|
|
|
pGlobal = (Fts5Global*)sqlite3_malloc(sizeof(Fts5Global));
|
|
if( pGlobal==0 ){
|
|
rc = SQLITE_NOMEM;
|
|
}else{
|
|
void *p = (void*)pGlobal;
|
|
memset(pGlobal, 0, sizeof(Fts5Global));
|
|
pGlobal->db = db;
|
|
pGlobal->api.iVersion = 2;
|
|
pGlobal->api.xCreateFunction = fts5CreateAux;
|
|
pGlobal->api.xCreateTokenizer = fts5CreateTokenizer;
|
|
pGlobal->api.xFindTokenizer = fts5FindTokenizer;
|
|
rc = sqlite3_create_module_v2(db, "fts5", &fts5Mod, p, fts5ModuleDestroy);
|
|
if( rc==SQLITE_OK ) rc = sqlite3Fts5IndexInit(db);
|
|
if( rc==SQLITE_OK ) rc = sqlite3Fts5ExprInit(pGlobal, db);
|
|
if( rc==SQLITE_OK ) rc = sqlite3Fts5AuxInit(&pGlobal->api);
|
|
if( rc==SQLITE_OK ) rc = sqlite3Fts5TokenizerInit(&pGlobal->api);
|
|
if( rc==SQLITE_OK ) rc = sqlite3Fts5VocabInit(pGlobal, db);
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(
|
|
db, "fts5", 0, SQLITE_UTF8, p, fts5Fts5Func, 0, 0
|
|
);
|
|
}
|
|
if( rc==SQLITE_OK ){
|
|
rc = sqlite3_create_function(
|
|
db, "fts5_source_id", 0, SQLITE_UTF8, p, fts5SourceIdFunc, 0, 0
|
|
);
|
|
}
|
|
}
|
|
|
|
/* If SQLITE_FTS5_ENABLE_TEST_MI is defined, assume that the file
|
|
** fts5_test_mi.c is compiled and linked into the executable. And call
|
|
** its entry point to enable the matchinfo() demo. */
|
|
#ifdef SQLITE_FTS5_ENABLE_TEST_MI
|
|
if( rc==SQLITE_OK ){
|
|
extern int sqlite3Fts5TestRegisterMatchinfo(sqlite3*);
|
|
rc = sqlite3Fts5TestRegisterMatchinfo(db);
|
|
}
|
|
#endif
|
|
|
|
return rc;
|
|
}
|
|
|
|
/*
|
|
** The following functions are used to register the module with SQLite. If
|
|
** this module is being built as part of the SQLite core (SQLITE_CORE is
|
|
** defined), then sqlite3_open() will call sqlite3Fts5Init() directly.
|
|
**
|
|
** Or, if this module is being built as a loadable extension,
|
|
** sqlite3Fts5Init() is omitted and the two standard entry points
|
|
** sqlite3_fts_init() and sqlite3_fts5_init() defined instead.
|
|
*/
|
|
#ifndef SQLITE_CORE
|
|
#ifdef _WIN32
|
|
__declspec(dllexport)
|
|
#endif
|
|
int sqlite3_fts_init(
|
|
sqlite3 *db,
|
|
char **pzErrMsg,
|
|
const sqlite3_api_routines *pApi
|
|
){
|
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
(void)pzErrMsg; /* Unused parameter */
|
|
return fts5Init(db);
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
__declspec(dllexport)
|
|
#endif
|
|
int sqlite3_fts5_init(
|
|
sqlite3 *db,
|
|
char **pzErrMsg,
|
|
const sqlite3_api_routines *pApi
|
|
){
|
|
SQLITE_EXTENSION_INIT2(pApi);
|
|
(void)pzErrMsg; /* Unused parameter */
|
|
return fts5Init(db);
|
|
}
|
|
#else
|
|
int sqlite3Fts5Init(sqlite3 *db){
|
|
return fts5Init(db);
|
|
}
|
|
#endif
|