diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 7c93e8d3ebd..7a54a693cb4 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -49,6 +49,8 @@ #include "mysqld.h" +#include + Rpl_filter *binlog_filter= 0; #define BIN_LOG_HEADER_SIZE 4 @@ -67,6 +69,7 @@ ulong server_id = 0; ulong bytes_sent = 0L, bytes_received = 0L; ulong mysqld_net_retry_count = 10L; ulong open_files_limit; +ulong opt_binlog_rows_event_max_size; uint test_flags = 0; static uint opt_protocol= 0; static FILE *result_file; @@ -1436,6 +1439,12 @@ that may lead to an endless loop.", "Used to reserve file descriptors for use by this program.", &open_files_limit, &open_files_limit, 0, GET_ULONG, REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0}, + {"binlog-row-event-max-size", 0, + "The maximum size of a row-based binary log event in bytes. Rows will be " + "grouped into events smaller than this size if possible. " + "This value must be a multiple of 256.", + &opt_binlog_rows_event_max_size, &opt_binlog_rows_event_max_size, 0, + GET_ULONG, REQUIRED_ARG, UINT_MAX, 256, ULONG_MAX, 0, 256, 0}, {"verify-binlog-checksum", 'c', "Verify checksum binlog events.", (uchar**) &opt_verify_binlog_checksum, (uchar**) &opt_verify_binlog_checksum, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake index 872d61d9aac..625ecb5a221 100644 --- a/cmake/maintainer.cmake +++ b/cmake/maintainer.cmake @@ -35,7 +35,7 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") ENDIF() # Turn on Werror (warning => error) when using maintainer mode. -IF(MYSQL_MAINTAINER_MODE MATCHES "ON") +IF(MYSQL_MAINTAINER_MODE MATCHES "ERR") SET(MY_C_WARNING_FLAGS "${MY_C_WARNING_FLAGS} -DFORCE_INIT_OF_VARS -Werror") SET(MY_CXX_WARNING_FLAGS "${MY_CXX_WARNING_FLAGS} -DFORCE_INIT_OF_VARS -Werror") ENDIF() diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 2a8d1f17fbc..26df7a47e0a 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -156,37 +156,37 @@ MACRO (MYSQL_CHECK_SSL) LIST(REVERSE CMAKE_FIND_LIBRARY_SUFFIXES) ENDIF() - # Verify version number. Version information looks like: - # #define OPENSSL_VERSION_NUMBER 0x1000103fL - # Encoded as MNNFFPPS: major minor fix patch status - FILE(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" - OPENSSL_VERSION_NUMBER - REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x[0-9].*" - ) - STRING(REGEX REPLACE - "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9]).*$" "\\1" - OPENSSL_MAJOR_VERSION "${OPENSSL_VERSION_NUMBER}" - ) - IF(OPENSSL_INCLUDE_DIR AND OPENSSL_LIBRARIES AND CRYPTO_LIBRARY ) + # Verify version number. Version information looks like: + # #define OPENSSL_VERSION_NUMBER 0x1000103fL + # Encoded as MNNFFPPS: major minor fix patch status + FILE(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" + OPENSSL_VERSION_NUMBER + REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x[0-9].*" + ) + STRING(REGEX REPLACE + "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9]).*$" "\\1" + OPENSSL_MAJOR_VERSION "${OPENSSL_VERSION_NUMBER}" + ) + INCLUDE(CheckSymbolExists) + SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) + CHECK_SYMBOL_EXISTS(SHA512_DIGEST_LENGTH "openssl/sha.h" + HAVE_SHA512_DIGEST_LENGTH) SET(OPENSSL_FOUND TRUE) ELSE() SET(OPENSSL_FOUND FALSE) ENDIF() - MESSAGE(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}") - MESSAGE(STATUS "OPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}") - MESSAGE(STATUS "CRYPTO_LIBRARY = ${CRYPTO_LIBRARY}") - MESSAGE(STATUS "OPENSSL_MAJOR_VERSION = ${OPENSSL_MAJOR_VERSION}") - - INCLUDE(CheckSymbolExists) - SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) - CHECK_SYMBOL_EXISTS(SHA512_DIGEST_LENGTH "openssl/sha.h" - HAVE_SHA512_DIGEST_LENGTH) IF(OPENSSL_FOUND AND HAVE_SHA512_DIGEST_LENGTH) + MESSAGE(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}") + MESSAGE(STATUS "OPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}") + MESSAGE(STATUS "CRYPTO_LIBRARY = ${CRYPTO_LIBRARY}") + MESSAGE(STATUS "OPENSSL_MAJOR_VERSION = ${OPENSSL_MAJOR_VERSION}") + + SET(SSL_SOURCES "") SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES} ${CRYPTO_LIBRARY}) IF(CMAKE_SYSTEM_NAME MATCHES "SunOS") diff --git a/debian/dist/Debian/mariadb-galera-server-10.0.files.in b/debian/dist/Debian/mariadb-galera-server-10.0.files.in index fd914e77e7f..bf1b04b5787 100644 --- a/debian/dist/Debian/mariadb-galera-server-10.0.files.in +++ b/debian/dist/Debian/mariadb-galera-server-10.0.files.in @@ -2,7 +2,6 @@ usr/sbin/mysqld usr/lib/mysql/plugin/auth_pam.so usr/lib/mysql/plugin/auth_socket.so usr/lib/mysql/plugin/ha_mroonga.so -usr/lib/mysql/plugin/ha_oqgraph.so usr/lib/mysql/plugin/ha_sequence.so usr/lib/mysql/plugin/ha_sphinx.so usr/lib/mysql/plugin/ha_innodb.so @@ -15,7 +14,6 @@ usr/lib/mysql/plugin/semisync_master.so usr/lib/mysql/plugin/semisync_slave.so usr/lib/mysql/plugin/sql_errlog.so usr/lib/mysql/plugin/server_audit.so -usr/lib/mysql/plugin/sphinx.so usr/lib/libhsclient.so.* etc/mysql/debian-start etc/mysql/conf.d/mysqld_safe_syslog.cnf diff --git a/debian/dist/Debian/mariadb-galera-server-10.0.postinst b/debian/dist/Debian/mariadb-galera-server-10.0.postinst index 9f79b61fd05..19594fb910e 100644 --- a/debian/dist/Debian/mariadb-galera-server-10.0.postinst +++ b/debian/dist/Debian/mariadb-galera-server-10.0.postinst @@ -21,7 +21,7 @@ invoke() { fi } -MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --default-storage-engine=myisam" +MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --disable-log-bin --skip-grant-tables --default-storage-engine=myisam" test_mysql_access() { mysql --no-defaults -u root -h localhost /dev/null 2>&1 @@ -40,6 +40,7 @@ set_mysql_rootpw() { # this avoids us having to call "test" or "[" on $rootpw cat << EOF > $tfile USE mysql; +SET sql_log_bin=0; UPDATE user SET password=PASSWORD("$rootpw") WHERE user='root'; FLUSH PRIVILEGES; EOF @@ -144,7 +145,7 @@ EOF # Debian: beware of the bashisms... # Debian: can safely run on upgrades with existing databases set +e - /bin/bash /usr/bin/mysql_install_db --rpm --user=mysql 2>&1 | $ERR_LOGGER + /bin/bash /usr/bin/mysql_install_db --rpm --user=mysql --disable-log-bin 2>&1 | $ERR_LOGGER set -e ## On every reconfiguration the maintenance user is recreated. diff --git a/debian/dist/Ubuntu/mariadb-galera-server-10.0.files.in b/debian/dist/Ubuntu/mariadb-galera-server-10.0.files.in index a3587d10cc4..368400c68b8 100644 --- a/debian/dist/Ubuntu/mariadb-galera-server-10.0.files.in +++ b/debian/dist/Ubuntu/mariadb-galera-server-10.0.files.in @@ -2,7 +2,6 @@ usr/sbin/mysqld usr/lib/mysql/plugin/auth_pam.so usr/lib/mysql/plugin/auth_socket.so usr/lib/mysql/plugin/ha_mroonga.so -usr/lib/mysql/plugin/ha_oqgraph.so usr/lib/mysql/plugin/ha_sequence.so usr/lib/mysql/plugin/ha_sphinx.so usr/lib/mysql/plugin/ha_innodb.so @@ -15,7 +14,6 @@ usr/lib/mysql/plugin/semisync_master.so usr/lib/mysql/plugin/semisync_slave.so usr/lib/mysql/plugin/sql_errlog.so usr/lib/mysql/plugin/server_audit.so -usr/lib/mysql/plugin/sphinx.so usr/lib/libhsclient.so.* etc/apparmor.d/usr.sbin.mysqld usr/share/apport/package-hooks/source_mariadb-10.0.py diff --git a/debian/dist/Ubuntu/mariadb-galera-server-10.0.postinst b/debian/dist/Ubuntu/mariadb-galera-server-10.0.postinst index f6da8c442ad..1acfbc80970 100644 --- a/debian/dist/Ubuntu/mariadb-galera-server-10.0.postinst +++ b/debian/dist/Ubuntu/mariadb-galera-server-10.0.postinst @@ -21,7 +21,7 @@ invoke() { fi } -MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --default-storage-engine=myisam" +MYSQL_BOOTSTRAP="/usr/sbin/mysqld --bootstrap --user=mysql --disable-log-bin --skip-grant-tables --default-storage-engine=myisam" test_mysql_access() { mysql --no-defaults -u root -h localhost /dev/null 2>&1 @@ -41,6 +41,7 @@ set_mysql_rootpw() { # this avoids us having to call "test" or "[" on $rootpw cat << EOF > $tfile USE mysql; +SET sql_log_bin=0; UPDATE user SET password=PASSWORD("$rootpw") WHERE user='root'; FLUSH PRIVILEGES; EOF @@ -145,7 +146,7 @@ EOF # Debian: beware of the bashisms... # Debian: can safely run on upgrades with existing databases set +e - /bin/bash /usr/bin/mysql_install_db --rpm --user=mysql 2>&1 | $ERR_LOGGER + /bin/bash /usr/bin/mysql_install_db --rpm --user=mysql --disable-log-bin 2>&1 | $ERR_LOGGER set -e ## On every reconfiguration the maintenance user is recreated. diff --git a/include/mysql_com.h b/include/mysql_com.h index 43be28f87a0..8fdac38dd66 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -618,14 +618,17 @@ void scramble_323(char *to, const char *message, const char *password); my_bool check_scramble_323(const unsigned char *reply, const char *message, unsigned long *salt); void get_salt_from_password_323(unsigned long *res, const char *password); +#if MYSQL_VERSION_ID < 100100 void make_password_from_salt_323(char *to, const unsigned long *salt); - +#endif void make_scrambled_password(char *to, const char *password); void scramble(char *to, const char *message, const char *password); my_bool check_scramble(const unsigned char *reply, const char *message, const unsigned char *hash_stage2); void get_salt_from_password(unsigned char *res, const char *password); +#if MYSQL_VERSION_ID < 100100 void make_password_from_salt(char *to, const unsigned char *hash_stage2); +#endif char *octet2hex(char *to, const char *str, unsigned int len); /* end of password.c */ diff --git a/mysql-test/extra/binlog_tests/database.test b/mysql-test/extra/binlog_tests/database.test index 61e8b594185..cd0266434ff 100644 --- a/mysql-test/extra/binlog_tests/database.test +++ b/mysql-test/extra/binlog_tests/database.test @@ -52,7 +52,7 @@ eval SELECT 'hello' INTO OUTFILE 'fake_file.$prefix'; # Use '/' instead of '\' in the error message. On windows platform, dir is # formed with '\'. ---replace_regex /\\testing_1\\*/\/testing_1\// +--replace_regex /\\testing_1\\*/\/testing_1\// /66/39/ --error 1010 DROP DATABASE testing_1; let $wait_binlog_event= DROP TABLE IF EXIST; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 6bb6e5a3c79..6959e9417a3 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1506,7 +1506,12 @@ sub command_line_setup { { $default_vardir= "$glob_mysql_test_dir/var"; } - $default_vardir = realpath $default_vardir unless IS_WINDOWS; + unless (IS_WINDOWS) { + my $realpath = realpath($default_vardir); + die "realpath('$default_vardir') failed: $!\n" + unless defined($realpath) && $realpath ne ''; + $default_vardir = $realpath; + } if ( ! $opt_vardir ) { diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index f35e6fd8265..aead73b3090 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -3008,5 +3008,11 @@ Warnings: Note 1003 select `test`.`t1`.`c1` AS `c1` from `test`.`t1` where ('%' = concat(`test`.`t1`.`c1`)) DROP TABLE t1; # +# MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +# +SELECT _binary 0x7E, _binary X'7E', _binary B'01111110'; +_binary 0x7E _binary X'7E' _binary B'01111110' +~ ~ ~ +# # End of 10.0 tests # diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index 970c067b25c..383ea3ca8f2 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -7907,5 +7907,11 @@ HEX(a) a 3F23 ?# DROP TABLE t1; # +# MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +# +SELECT _latin1 0x7E, _latin1 X'7E', _latin1 B'01111110'; +_latin1 0x7E _latin1 X'7E' _latin1 B'01111110' +~ ~ ~ +# # End of 10.0 tests # diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index c752024ec7f..40854183a92 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -6259,6 +6259,12 @@ EXECUTE stmt USING @b,@b; ERROR HY000: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'concat' DEALLOCATE PREPARE stmt; DROP TABLE t1; +# +# MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +# +SELECT _utf8 0x7E, _utf8 X'7E', _utf8 B'01111110'; +_utf8 0x7E _utf8 X'7E' _utf8 B'01111110' +~ ~ ~ # Start of ctype_unescape.inc SET @query=_binary'SELECT CHARSET(\'test\'),@@character_set_client,@@character_set_connection'; PREPARE stmt FROM @query; diff --git a/mysql-test/r/func_set.result b/mysql-test/r/func_set.result index 93757800505..dfc3faf3fac 100644 --- a/mysql-test/r/func_set.result +++ b/mysql-test/r/func_set.result @@ -5,7 +5,7 @@ explain extended select INTERVAL(55,10,20,30,40,50,60,70,80,90,100),interval(3,1 id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 select interval((55,10,20,30,40,50,60,70,80,90,100)) AS `INTERVAL(55,10,20,30,40,50,60,70,80,90,100)`,interval((3,1,(1 + 1),(((1 + 1) + 1) + 1))) AS `interval(3,1,1+1,1+1+1+1)`,field('IBM','NCA','ICL','SUN','IBM','DIGITAL') AS `field("IBM","NCA","ICL","SUN","IBM","DIGITAL")`,field('A','B','C') AS `field("A","B","C")`,elt(2,'ONE','TWO','THREE') AS `elt(2,"ONE","TWO","THREE")`,interval((0,1,2,3,4)) AS `interval(0,1,2,3,4)`,(elt(1,1,2,3) | 0) AS `elt(1,1,2,3)|0`,(elt(1,1.1,1.2,1.3) + 0) AS `elt(1,1.1,1.2,1.3)+0` +Note 1003 select interval(55,10,20,30,40,50,60,70,80,90,100) AS `INTERVAL(55,10,20,30,40,50,60,70,80,90,100)`,interval(3,1,(1 + 1),(((1 + 1) + 1) + 1)) AS `interval(3,1,1+1,1+1+1+1)`,field('IBM','NCA','ICL','SUN','IBM','DIGITAL') AS `field("IBM","NCA","ICL","SUN","IBM","DIGITAL")`,field('A','B','C') AS `field("A","B","C")`,elt(2,'ONE','TWO','THREE') AS `elt(2,"ONE","TWO","THREE")`,interval(0,1,2,3,4) AS `interval(0,1,2,3,4)`,(elt(1,1,2,3) | 0) AS `elt(1,1,2,3)|0`,(elt(1,1.1,1.2,1.3) + 0) AS `elt(1,1.1,1.2,1.3)+0` SELECT INTERVAL(13, 7, 14, 21, 28, 35, 42, 49, 56); INTERVAL(13, 7, 14, 21, 28, 35, 42, 49, 56) 1 diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result index 456e17a91f7..c1dbef08c04 100644 --- a/mysql-test/r/join_cache.result +++ b/mysql-test/r/join_cache.result @@ -5874,4 +5874,17 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 11 Using where set join_buffer_space_limit=default; drop table t1; +# +# MDEV-6687: Assertion `0' failed in Protocol::end_statement on query +# +SET join_cache_level = 3; +# The following should have +# - table order PROFILING,user, +# - table user accessed with hash_ALL: +explain +SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user WHERE password_expired = PAGE_FAULTS_MINOR; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE PROFILING ALL NULL NULL NULL NULL NULL Using where +1 SIMPLE user hash_ALL NULL #hash#$hj 1 information_schema.PROFILING.PAGE_FAULTS_MINOR 4 Using where; Using join buffer (flat, BNLH join) +set join_cache_level=default; set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/partition_innodb_plugin.result b/mysql-test/r/partition_innodb_plugin.result index 7a84745e611..7057bb0a55b 100644 --- a/mysql-test/r/partition_innodb_plugin.result +++ b/mysql-test/r/partition_innodb_plugin.result @@ -141,12 +141,12 @@ ERROR 40001: Deadlock found when trying to get lock; try restarting transaction # First table reported in 'SHOW ENGINE InnoDB STATUS' SHOW ENGINE InnoDB STATUS; Type Name Status -InnoDB index `PRIMARY` of table `test`.`t``\""e` /* Partition `p0``\""e`, Subpartition `sp0``\""e` */ +InnoDB index `PRIMARY` of table `test`.`t``\""e` /* Partition `p0``\""e`, Subpartition `sp0``\""e` */ set @old_sql_mode = @@sql_mode; set sql_mode = 'ANSI_QUOTES'; SHOW ENGINE InnoDB STATUS; Type Name Status -InnoDB index `PRIMARY` of table `test`.`t``\""e` /* Partition `p0``\""e`, Subpartition `sp0``\""e` */ +InnoDB index `PRIMARY` of table `test`.`t``\""e` /* Partition `p0``\""e`, Subpartition `sp0``\""e` */ set @@sql_mode = @old_sql_mode; # con1 ROLLBACK; diff --git a/mysql-test/r/selectivity.result b/mysql-test/r/selectivity.result index 3f2343fa365..620bdc6bd50 100644 --- a/mysql-test/r/selectivity.result +++ b/mysql-test/r/selectivity.result @@ -1409,4 +1409,40 @@ Note 1003 select `test`.`a`.`a` AS `a`,`test`.`a`.`b` AS `b`,`test`.`b`.`a` AS ` set histogram_size=@save_histogram_size; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; drop table t0,t1,t2; +# +# Bug mdev-7316: a conjunct in WHERE with selectivity == 0 +# +CREATE TABLE t1 (a varchar(16), b int, PRIMARY KEY(a), KEY(b)) ENGINE=INNODB; +Warnings: +Warning 1286 Unknown storage engine 'INNODB' +Warning 1266 Using storage engine MyISAM for table 't1' +INSERT INTO t1 VALUES +('USAChinese',10), ('USAEnglish',20), ('USAFrench',30); +CREATE TABLE t2 (i int) ENGINE=INNODB; +Warnings: +Warning 1286 Unknown storage engine 'INNODB' +Warning 1266 Using storage engine MyISAM for table 't2' +INSERT INTO t2 VALUES +(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(1),(2),(3),(4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +test.t2 analyze status Engine-independent statistics collected +test.t2 analyze status OK +set use_stat_tables='preferably'; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 +WHERE a <> 'USARussian' AND b IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref PRIMARY,b b 5 const 1 100.00 Using index condition; Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`i` AS `i` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` <> 'USARussian') and isnull(`test`.`t1`.`b`)) +SELECT * FROM t1, t2 +WHERE a <> 'USARussian' AND b IS NULL; +a b i +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/selectivity_innodb.result b/mysql-test/r/selectivity_innodb.result index 0b7f1c950e5..0acbb465ba8 100644 --- a/mysql-test/r/selectivity_innodb.result +++ b/mysql-test/r/selectivity_innodb.result @@ -1419,6 +1419,36 @@ Note 1003 select `test`.`a`.`a` AS `a`,`test`.`a`.`b` AS `b`,`test`.`b`.`a` AS ` set histogram_size=@save_histogram_size; set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; drop table t0,t1,t2; +# +# Bug mdev-7316: a conjunct in WHERE with selectivity == 0 +# +CREATE TABLE t1 (a varchar(16), b int, PRIMARY KEY(a), KEY(b)) ENGINE=INNODB; +INSERT INTO t1 VALUES +('USAChinese',10), ('USAEnglish',20), ('USAFrench',30); +CREATE TABLE t2 (i int) ENGINE=INNODB; +INSERT INTO t2 VALUES +(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(1),(2),(3),(4); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +test.t2 analyze status Engine-independent statistics collected +test.t2 analyze status OK +set use_stat_tables='preferably'; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 +WHERE a <> 'USARussian' AND b IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref PRIMARY,b b 5 const 2 66.67 Using where; Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`i` AS `i` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` <> 'USARussian') and isnull(`test`.`t1`.`b`)) +SELECT * FROM t1, t2 +WHERE a <> 'USARussian' AND b IS NULL; +a b i +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; set use_stat_tables=@save_use_stat_tables; set optimizer_switch=@save_optimizer_switch_for_selectivity_test; set @tmp_ust= @@use_stat_tables; @@ -1482,6 +1512,30 @@ select * from t1 where col2 != true; col1 col2 drop table t1; # +# MDEV-7413: optimizer_use_condition_selectivity > 2 crashes 10.0.15+maria-1~wheezy +# +CREATE TABLE t1 ( +parent_id int, +child_group_id int, +child_user_id int, +KEY (parent_id,child_group_id,child_user_id) +) ENGINE=InnoDB; +CREATE TABLE t2 ( +id int, +lower_group_name varchar(255), +directory_id int(20), +UNIQUE KEY (directory_id) +) ENGINE=InnoDB; +CREATE TABLE t3 (id int) ENGINE=InnoDB; +insert into t1 values (1,1,1),(2,2,2); +insert into t2 values (10,'foo',10),(20,'bar',20); +insert into t3 values (101),(102); +set use_stat_tables = PREFERABLY, optimizer_use_condition_selectivity = 3; +select * from t1, t2, t3 +where t1.child_user_id=t3.id and t1.child_group_id is null and t2.lower_group_name='foo' and t1.parent_id=t2.id and t2.directory_id=10; +parent_id child_group_id child_user_id id lower_group_name directory_id id +drop table t1,t2,t3; +# # End of 10.0 tests # set use_stat_tables= @tmp_ust; diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result index 410441b63e3..3cc4ff4238b 100644 --- a/mysql-test/r/sp_notembedded.result +++ b/mysql-test/r/sp_notembedded.result @@ -284,4 +284,23 @@ DROP EVENT teste_bug11763507; # ------------------------------------------------------------------ # -- End of 5.1 tests # ------------------------------------------------------------------ +grant create routine on test.* to foo1@localhost identified by 'foo'; +update mysql.user set password = replace(password, '*', '-') where user='foo1'; +show grants; +Grants for foo1@localhost +GRANT USAGE ON *.* TO 'foo1'@'localhost' IDENTIFIED BY PASSWORD '*F3A2A51A9B0F2BE2468926B4132313728C250DBF' +GRANT CREATE ROUTINE ON `test`.* TO 'foo1'@'localhost' +flush privileges; +show grants; +Grants for foo1@localhost +GRANT USAGE ON *.* TO 'foo1'@'localhost' IDENTIFIED BY PASSWORD '-F3A2A51A9B0F2BE2468926B4132313728C250DBF' +GRANT CREATE ROUTINE ON `test`.* TO 'foo1'@'localhost' +create procedure spfoo() select 1; +show grants; +Grants for foo1@localhost +GRANT USAGE ON *.* TO 'foo1'@'localhost' IDENTIFIED BY PASSWORD '-F3A2A51A9B0F2BE2468926B4132313728C250DBF' +GRANT CREATE ROUTINE ON `test`.* TO 'foo1'@'localhost' +GRANT EXECUTE, ALTER ROUTINE ON PROCEDURE `test`.`spfoo` TO 'foo1'@'localhost' +drop procedure spfoo; +drop user foo1@localhost; set @@global.concurrent_insert= @old_concurrent_insert; diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index 4103a3424e9..7b421c624bf 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -2146,6 +2146,57 @@ drop database mysqltest2; drop database mysqltest3; drop database mysqltest4; # End of 5.5 tests +# +# MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +# +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; +create table t3 as select * from t2 limit 1; +# The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1000 Using where +1 PRIMARY eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4000 Using temporary +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +# Sequential reads: +# 1K is read from t1 +# 4K is read from t2 +# 1K groups is read from the tmp. table +# +# Lookups: +# 4K lookups in group by table +# 1K lookups in temp.table +# +# Writes: +# 2x 1K writes to temporary tables (grouping table and subquery materialization table +# +# The point is that neither counter should be in the millions (this +# will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 5000 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 6003 +Handler_tmp_write 2000 +Handler_write 1000 +drop table t0,t1,t2,t3; set @subselect_mat_test_optimizer_switch_value=null; set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index c6a0344c8a3..55b54ea4eb2 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -2186,3 +2186,54 @@ drop database mysqltest2; drop database mysqltest3; drop database mysqltest4; # End of 5.5 tests +# +# MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +# +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; +create table t3 as select * from t2 limit 1; +# The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1000 Using where +1 PRIMARY eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4000 Using temporary +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +# Sequential reads: +# 1K is read from t1 +# 4K is read from t2 +# 1K groups is read from the tmp. table +# +# Lookups: +# 4K lookups in group by table +# 1K lookups in temp.table +# +# Writes: +# 2x 1K writes to temporary tables (grouping table and subquery materialization table +# +# The point is that neither counter should be in the millions (this +# will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 5000 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 6003 +Handler_tmp_write 2000 +Handler_write 1000 +drop table t0,t1,t2,t3; diff --git a/mysql-test/r/view_alias.result b/mysql-test/r/view_alias.result index 72c4bf29f25..e07b40dba13 100644 --- a/mysql-test/r/view_alias.result +++ b/mysql-test/r/view_alias.result @@ -109,3 +109,11 @@ DROP VIEW v1; CREATE VIEW v1 AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(select ' a ' AS `alias` from `test`.`t1` group by ' a '); DROP VIEW v1; DROP TABLE t1, t2; +create view v1 as select interval(55,10) as my_col; +show create view v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select interval(55,10) AS `my_col` latin1 latin1_swedish_ci +select * from v1; +my_col +1 +drop view v1; diff --git a/mysql-test/suite/innodb/r/innodb-alter-table-disk-full.result b/mysql-test/suite/innodb/r/innodb-alter-table-disk-full.result index ffeacae7951..a357fe27f37 100644 --- a/mysql-test/suite/innodb/r/innodb-alter-table-disk-full.result +++ b/mysql-test/suite/innodb/r/innodb-alter-table-disk-full.result @@ -1,4 +1,5 @@ -create table t1(a int not null primary key, b int) engine=innodb; +call mtr.add_suppression("InnoDB: Error: row_merge_drop_indexes_dict failed with error code*"); +create table t1(a int, b int) engine=innodb; create procedure innodb_insert_proc (repeat_count int) begin declare current_num int; @@ -10,41 +11,53 @@ end while; end// commit; set autocommit=0; -call innodb_insert_proc(10000); +call innodb_insert_proc(20000); commit; set autocommit=1; +create table t2(a int) engine=innodb; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 set DEBUG_DBUG='+d,ib_os_aio_func_io_failure_28'; alter table t1 add testcol int; ERROR HY000: The table 't1' is full show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` int(11) NOT NULL, - `b` int(11) DEFAULT NULL, - PRIMARY KEY (`a`) + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 -set DEBUG_DBUG='+d,ib_os_aio_func_io_failure_28_2'; +alter table t2 add testcol int; +ERROR HY000: The table 't2' is full +alter table t1 add testcol int; +ERROR HY000: The table 't1' is full +alter table t1 add testcol int; +ERROR HY000: The table 't1' is full +alter table t1 add testcol2 int; +ERROR HY000: The table 't1' is full +alter table t1 add testcol3 int; +ERROR HY000: The table 't1' is full alter table t1 add testcol int; ERROR HY000: The table 't1' is full show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` int(11) NOT NULL, - `b` int(11) DEFAULT NULL, - PRIMARY KEY (`a`) + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 -set DEBUG_DBUG=NULL; +drop table t2; alter table t1 add testcol2 int; -show create table t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) NOT NULL, - `b` int(11) DEFAULT NULL, - `testcol2` int(11) DEFAULT NULL, - PRIMARY KEY (`a`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1 -select count(1) from t1; -count(1) -10000 +ERROR HY000: The table 't1' is full +alter table t1 add testcol3 int; +ERROR HY000: The table 't1' is full +call innodb_insert_proc(20000); +set autocommit=0; +call innodb_insert_proc(20000); +commit; +set autocommit=1; +set DEBUG_DBUG=''; drop procedure innodb_insert_proc; drop table t1; +drop table if exists t2; diff --git a/mysql-test/suite/innodb/r/innodb-mdev-7408.result b/mysql-test/suite/innodb/r/innodb-mdev-7408.result new file mode 100644 index 00000000000..8f6ad139192 --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-mdev-7408.result @@ -0,0 +1,12 @@ +select @@global.innodb_ft_server_stopword_table; +@@global.innodb_ft_server_stopword_table +NULL +CREATE TABLE `stop_it-IT` ENGINE = InnoDB SELECT * FROM information_schema.INNODB_FT_DEFAULT_STOPWORD; +SET @@global.innodb_ft_server_stopword_table = 'test/stop_it-IT'; +ERROR 42000: Variable 'innodb_ft_server_stopword_table' can't be set to the value of 'test/stop_it-IT' +SET @@global.innodb_ft_server_stopword_table = 'test/stop_it@002dIT'; +drop table `stop_it-IT`; +CREATE TABLE stop_it ENGINE = InnoDB SELECT * FROM information_schema.INNODB_FT_DEFAULT_STOPWORD; +SET @@global.innodb_ft_server_stopword_table = 'test/stop_it'; +SET @@global.innodb_ft_server_stopword_table = NULL; +drop table stop_it; diff --git a/mysql-test/suite/innodb/r/innodb_bug34300.result b/mysql-test/suite/innodb/r/innodb_bug34300.result index bf07febca73..09fc0b44579 100644 --- a/mysql-test/suite/innodb/r/innodb_bug34300.result +++ b/mysql-test/suite/innodb/r/innodb_bug34300.result @@ -1,3 +1,3 @@ -ERROR 42000: Row size too large (> ####). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline. +ERROR 42000: The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb_log_file_size. f4 f8 f4 f8 diff --git a/mysql-test/suite/innodb/t/innodb-alter-table-disk-full.test b/mysql-test/suite/innodb/t/innodb-alter-table-disk-full.test index adeb2ef9fd2..8fd8e3914c4 100644 --- a/mysql-test/suite/innodb/t/innodb-alter-table-disk-full.test +++ b/mysql-test/suite/innodb/t/innodb-alter-table-disk-full.test @@ -7,7 +7,9 @@ # DEBUG_SYNC must be compiled in. --source include/have_debug_sync.inc -create table t1(a int not null primary key, b int) engine=innodb; +call mtr.add_suppression("InnoDB: Error: row_merge_drop_indexes_dict failed with error code*"); + +create table t1(a int, b int) engine=innodb; delimiter //; create procedure innodb_insert_proc (repeat_count int) @@ -23,28 +25,51 @@ delimiter ;// commit; set autocommit=0; -call innodb_insert_proc(10000); +call innodb_insert_proc(20000); commit; set autocommit=1; +create table t2(a int) engine=innodb; +show create table t2; + # This caused crash earlier set DEBUG_DBUG='+d,ib_os_aio_func_io_failure_28'; --error 1114 alter table t1 add testcol int; show create table t1; - -# This caused crash earlier -set DEBUG_DBUG='+d,ib_os_aio_func_io_failure_28_2'; +--error 1114 +alter table t2 add testcol int; +--error 1114 +alter table t1 add testcol int; +--error 1114 +alter table t1 add testcol int; +--error 1114 +alter table t1 add testcol2 int; +--error 1114 +alter table t1 add testcol3 int; --error 1114 alter table t1 add testcol int; show create table t1; - -set DEBUG_DBUG=NULL; +--error 0,1051 +drop table t2; +--error 1114 alter table t1 add testcol2 int; -show create table t1; +--error 1114 +alter table t1 add testcol3 int; +--error 0,1114 +call innodb_insert_proc(20000); +set autocommit=0; +--error 0,1114 +call innodb_insert_proc(20000); +commit; +set autocommit=1; -select count(1) from t1; +set DEBUG_DBUG=''; drop procedure innodb_insert_proc; drop table t1; +--disable_warnings +drop table if exists t2; +--enable_warnings + diff --git a/mysql-test/suite/innodb/t/innodb-mdev-7408.opt b/mysql-test/suite/innodb/t/innodb-mdev-7408.opt new file mode 100644 index 00000000000..1c256483e10 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-mdev-7408.opt @@ -0,0 +1,2 @@ +--innodb_ft_default_stopword + diff --git a/mysql-test/suite/innodb/t/innodb-mdev-7408.test b/mysql-test/suite/innodb/t/innodb-mdev-7408.test new file mode 100644 index 00000000000..d1cd1879bb1 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-mdev-7408.test @@ -0,0 +1,16 @@ +--source include/have_innodb.inc + +select @@global.innodb_ft_server_stopword_table; +CREATE TABLE `stop_it-IT` ENGINE = InnoDB SELECT * FROM information_schema.INNODB_FT_DEFAULT_STOPWORD; +--error 1231 +SET @@global.innodb_ft_server_stopword_table = 'test/stop_it-IT'; +--error 0,1231 +SET @@global.innodb_ft_server_stopword_table = 'test/stop_it@002dIT'; +drop table `stop_it-IT`; + +CREATE TABLE stop_it ENGINE = InnoDB SELECT * FROM information_schema.INNODB_FT_DEFAULT_STOPWORD; +SET @@global.innodb_ft_server_stopword_table = 'test/stop_it'; + +SET @@global.innodb_ft_server_stopword_table = NULL; + +drop table stop_it; diff --git a/mysql-test/suite/innodb/t/innodb-mdev7046.test b/mysql-test/suite/innodb/t/innodb-mdev7046.test index 4033f284e65..b4085228e02 100644 --- a/mysql-test/suite/innodb/t/innodb-mdev7046.test +++ b/mysql-test/suite/innodb/t/innodb-mdev7046.test @@ -1,5 +1,7 @@ --source include/have_innodb.inc --source include/have_partition.inc +# Test causes OS error printout +--source include/not_windows.inc --disable_query_log --disable_result_log diff --git a/mysql-test/suite/innodb/t/innodb_bug34300.test b/mysql-test/suite/innodb/t/innodb_bug34300.test index 800f326707d..13c708b48d6 100644 --- a/mysql-test/suite/innodb/t/innodb_bug34300.test +++ b/mysql-test/suite/innodb/t/innodb_bug34300.test @@ -5,6 +5,11 @@ -- source include/have_innodb.inc +if (`select plugin_auth_version <= "5.6.22-MariaDB-72.0" from information_schema.plugins where plugin_name='innodb'`) +{ + --skip Not fixed in XtraDB as of 5.6.22-MariaDB-72.0 or earlier +} + -- disable_query_log -- disable_result_log diff --git a/mysql-test/suite/rpl/r/rpl_parallel.result b/mysql-test/suite/rpl/r/rpl_parallel.result index 7ceb5ee6622..3c66a541cc1 100644 --- a/mysql-test/suite/rpl/r/rpl_parallel.result +++ b/mysql-test/suite/rpl/r/rpl_parallel.result @@ -1136,6 +1136,80 @@ SET GLOBAL debug_dbug=@old_dbug; SET GLOBAL slave_parallel_threads=0; SET GLOBAL slave_parallel_threads=10; include/start_slave.inc +*** MDEV-7335: Potential parallel slave deadlock with specific binlog corruption *** +include/stop_slave.inc +SET GLOBAL slave_parallel_threads=1; +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,slave_discard_xid_for_gtid_0_x_1000"; +INSERT INTO t2 VALUES (101); +INSERT INTO t2 VALUES (102); +INSERT INTO t2 VALUES (103); +INSERT INTO t2 VALUES (104); +INSERT INTO t2 VALUES (105); +SET gtid_seq_no=1000; +INSERT INTO t2 VALUES (106); +INSERT INTO t2 VALUES (107); +INSERT INTO t2 VALUES (108); +INSERT INTO t2 VALUES (109); +INSERT INTO t2 VALUES (110); +INSERT INTO t2 VALUES (111); +INSERT INTO t2 VALUES (112); +INSERT INTO t2 VALUES (113); +INSERT INTO t2 VALUES (114); +INSERT INTO t2 VALUES (115); +INSERT INTO t2 VALUES (116); +INSERT INTO t2 VALUES (117); +INSERT INTO t2 VALUES (118); +INSERT INTO t2 VALUES (119); +INSERT INTO t2 VALUES (120); +INSERT INTO t2 VALUES (121); +INSERT INTO t2 VALUES (122); +INSERT INTO t2 VALUES (123); +INSERT INTO t2 VALUES (124); +INSERT INTO t2 VALUES (125); +INSERT INTO t2 VALUES (126); +INSERT INTO t2 VALUES (127); +INSERT INTO t2 VALUES (128); +INSERT INTO t2 VALUES (129); +INSERT INTO t2 VALUES (130); +include/save_master_gtid.inc +include/start_slave.inc +include/sync_with_master_gtid.inc +SELECT * FROM t2 WHERE a >= 100 ORDER BY a; +a +101 +102 +103 +104 +105 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL slave_parallel_threads=10; +include/start_slave.inc include/stop_slave.inc SET GLOBAL slave_parallel_threads=@old_parallel_threads; include/start_slave.inc diff --git a/mysql-test/suite/rpl/r/rpl_trigger.result b/mysql-test/suite/rpl/r/rpl_trigger.result index ac6d9155f4b..c0e35274594 100644 --- a/mysql-test/suite/rpl/r/rpl_trigger.result +++ b/mysql-test/suite/rpl/r/rpl_trigger.result @@ -986,4 +986,15 @@ Warning 1196 Some non-transactional changed tables couldn't be rolled back include/diff_tables.inc [master:t1, slave:t1] include/diff_tables.inc [master:log, slave:log] drop table t1, log; +drop trigger if exists notexistent; +Warnings: +Note 1360 Trigger does not exist +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; drop trigger if exists notexistent +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +slave-bin.000001 # Gtid # # GTID #-#-# +slave-bin.000001 # Query # # use `test`; drop trigger if exists notexistent include/rpl_end.inc diff --git a/mysql-test/suite/rpl/r/semisync_future-7591.result b/mysql-test/suite/rpl/r/semisync_future-7591.result new file mode 100644 index 00000000000..732ae09daaf --- /dev/null +++ b/mysql-test/suite/rpl/r/semisync_future-7591.result @@ -0,0 +1,19 @@ +include/master-slave.inc +[connection master] +call mtr.add_suppression("Timeout waiting for reply of binlog*"); +create table t1 (i int); +set global rpl_semi_sync_master_enabled = ON; +include/stop_slave.inc +set global rpl_semi_sync_slave_enabled = ON; +change master to master_log_file='master-bin.000002', master_log_pos = 320; +start slave; +include/wait_for_slave_io_error.inc [errno=1236] +insert into t1 values (1); +reset master; +include/stop_slave.inc +reset slave; +include/start_slave.inc +set global rpl_semi_sync_slave_enabled = OFF; +drop table t1; +set global rpl_semi_sync_master_enabled = OFF; +include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_parallel.test b/mysql-test/suite/rpl/t/rpl_parallel.test index d4b99d4b0f7..7397ede14b3 100644 --- a/mysql-test/suite/rpl/t/rpl_parallel.test +++ b/mysql-test/suite/rpl/t/rpl_parallel.test @@ -1843,6 +1843,62 @@ SET GLOBAL slave_parallel_threads=10; --source include/start_slave.inc +--echo *** MDEV-7335: Potential parallel slave deadlock with specific binlog corruption *** + +--connection server_2 +--source include/stop_slave.inc +SET GLOBAL slave_parallel_threads=1; +SET @old_dbug= @@GLOBAL.debug_dbug; +SET GLOBAL debug_dbug="+d,slave_discard_xid_for_gtid_0_x_1000"; + +--connection server_1 +INSERT INTO t2 VALUES (101); +INSERT INTO t2 VALUES (102); +INSERT INTO t2 VALUES (103); +INSERT INTO t2 VALUES (104); +INSERT INTO t2 VALUES (105); +# Inject a partial event group (missing XID at the end). The bug was that such +# partial group was not handled appropriately, leading to server deadlock. +SET gtid_seq_no=1000; +INSERT INTO t2 VALUES (106); +INSERT INTO t2 VALUES (107); +INSERT INTO t2 VALUES (108); +INSERT INTO t2 VALUES (109); +INSERT INTO t2 VALUES (110); +INSERT INTO t2 VALUES (111); +INSERT INTO t2 VALUES (112); +INSERT INTO t2 VALUES (113); +INSERT INTO t2 VALUES (114); +INSERT INTO t2 VALUES (115); +INSERT INTO t2 VALUES (116); +INSERT INTO t2 VALUES (117); +INSERT INTO t2 VALUES (118); +INSERT INTO t2 VALUES (119); +INSERT INTO t2 VALUES (120); +INSERT INTO t2 VALUES (121); +INSERT INTO t2 VALUES (122); +INSERT INTO t2 VALUES (123); +INSERT INTO t2 VALUES (124); +INSERT INTO t2 VALUES (125); +INSERT INTO t2 VALUES (126); +INSERT INTO t2 VALUES (127); +INSERT INTO t2 VALUES (128); +INSERT INTO t2 VALUES (129); +INSERT INTO t2 VALUES (130); +--source include/save_master_gtid.inc + +--connection server_2 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc +# The partial event group (a=106) should be rolled back and thus missing. +SELECT * FROM t2 WHERE a >= 100 ORDER BY a; + +--source include/stop_slave.inc +SET GLOBAL debug_dbug=@old_dbug; +SET GLOBAL slave_parallel_threads=10; +--source include/start_slave.inc + + # Clean up. --connection server_2 --source include/stop_slave.inc diff --git a/mysql-test/suite/rpl/t/rpl_trigger.test b/mysql-test/suite/rpl/t/rpl_trigger.test index 723fa3e44e2..e062e821a25 100644 --- a/mysql-test/suite/rpl/t/rpl_trigger.test +++ b/mysql-test/suite/rpl/t/rpl_trigger.test @@ -532,6 +532,19 @@ connection master; drop table t1, log; sync_slave_with_master; +# +# MDEV-6769 DROP TRIGGER IF NOT EXIST binlogged on master but not on slave +# +let $slave_pos= query_get_value(SHOW MASTER STATUS, Position, 1); +connection master; +let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1); +drop trigger if exists notexistent; +source include/show_binlog_events.inc; +sync_slave_with_master; +let $binlog_start= $slave_pos; +source include/show_binlog_events.inc; +connection master; + # # End of tests # diff --git a/mysql-test/suite/rpl/t/semisync_future-7591.test b/mysql-test/suite/rpl/t/semisync_future-7591.test new file mode 100644 index 00000000000..772a36b5632 --- /dev/null +++ b/mysql-test/suite/rpl/t/semisync_future-7591.test @@ -0,0 +1,31 @@ +--source include/have_semisync.inc +--source include/master-slave.inc + +call mtr.add_suppression("Timeout waiting for reply of binlog*"); +create table t1 (i int); + +set global rpl_semi_sync_master_enabled = ON; + +--connection slave +--source include/stop_slave.inc +set global rpl_semi_sync_slave_enabled = ON; +change master to master_log_file='master-bin.000002', master_log_pos = 320; + +start slave; +--let $slave_io_errno=1236 +--source include/wait_for_slave_io_error.inc + +--connection master +insert into t1 values (1); +reset master; + +--connection slave +--source include/stop_slave.inc +reset slave; +--source include/start_slave.inc + +set global rpl_semi_sync_slave_enabled = OFF; +--connection master +drop table t1; +set global rpl_semi_sync_master_enabled = OFF; +--source include/rpl_end.inc diff --git a/mysql-test/t/ctype_binary.test b/mysql-test/t/ctype_binary.test index 4a2646d1db5..3d3f90b444b 100644 --- a/mysql-test/t/ctype_binary.test +++ b/mysql-test/t/ctype_binary.test @@ -19,6 +19,11 @@ set names binary; SET NAMES binary; --source include/ctype_like_cond_propagation.inc +--echo # +--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +--echo # +SELECT _binary 0x7E, _binary X'7E', _binary B'01111110'; + --echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/ctype_latin1.test b/mysql-test/t/ctype_latin1.test index 336d8ca761d..aeaad2cc026 100644 --- a/mysql-test/t/ctype_latin1.test +++ b/mysql-test/t/ctype_latin1.test @@ -240,6 +240,11 @@ SHOW WARNINGS; SELECT HEX(a),a FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +--echo # +SELECT _latin1 0x7E, _latin1 X'7E', _latin1 B'01111110'; + --echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 1e9047cca8e..af5f4b8ccf8 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1744,6 +1744,11 @@ EXECUTE stmt USING @b,@b; DEALLOCATE PREPARE stmt; DROP TABLE t1; +--echo # +--echo # MDEV-7629 Regression: Bit and hex string literals changed column names in 10.0.14 +--echo # +SELECT _utf8 0x7E, _utf8 X'7E', _utf8 B'01111110'; + let $ctype_unescape_combinations=selected; --source include/ctype_unescape.inc diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test index 0e4610b9f54..7d873c555f6 100644 --- a/mysql-test/t/join_cache.test +++ b/mysql-test/t/join_cache.test @@ -3848,6 +3848,18 @@ set join_buffer_space_limit=default; drop table t1; +--echo # +--echo # MDEV-6687: Assertion `0' failed in Protocol::end_statement on query +--echo # +SET join_cache_level = 3; +--echo # The following should have +--echo # - table order PROFILING,user, +--echo # - table user accessed with hash_ALL: +explain +SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.user WHERE password_expired = PAGE_FAULTS_MINOR; + +set join_cache_level=default; + # The following command must be the last one the file # this must be the last command in the file set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/t/partition_innodb_plugin.test b/mysql-test/t/partition_innodb_plugin.test index 8044ae9ec5c..fd6e60c27fb 100644 --- a/mysql-test/t/partition_innodb_plugin.test +++ b/mysql-test/t/partition_innodb_plugin.test @@ -149,11 +149,11 @@ UPDATE `t``\""e` SET a = 4 WHERE a = 22; # NOTE: replace_regex is very slow on match copy/past '(.*)' regex's # on big texts, removing a lot of text before + after makes it much faster. #/.*in (.*) trx.*/\1/ ---replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // +--replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* // SHOW ENGINE InnoDB STATUS; set @old_sql_mode = @@sql_mode; set sql_mode = 'ANSI_QUOTES'; ---replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // +--replace_regex /.*RECORD LOCKS space id [0-9]* page no [0-9]* n bits [0-9]* // / trx id .*// /.*index .* in // /trx table locks [0-9]* // /total table locks [0-9]* // SHOW ENGINE InnoDB STATUS; set @@sql_mode = @old_sql_mode; --echo # con1 diff --git a/mysql-test/t/selectivity.test b/mysql-test/t/selectivity.test index 77ee5f49bef..c46ff69295f 100644 --- a/mysql-test/t/selectivity.test +++ b/mysql-test/t/selectivity.test @@ -942,5 +942,34 @@ set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivit drop table t0,t1,t2; +--echo # +--echo # Bug mdev-7316: a conjunct in WHERE with selectivity == 0 +--echo # + +CREATE TABLE t1 (a varchar(16), b int, PRIMARY KEY(a), KEY(b)) ENGINE=INNODB; +INSERT INTO t1 VALUES + ('USAChinese',10), ('USAEnglish',20), ('USAFrench',30); + +CREATE TABLE t2 (i int) ENGINE=INNODB; +INSERT INTO t2 VALUES + (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(1),(2),(3),(4); + +ANALYZE TABLE t1, t2; + +set use_stat_tables='preferably'; +set optimizer_use_condition_selectivity=3; + +EXPLAIN EXTENDED +SELECT * FROM t1, t2 + WHERE a <> 'USARussian' AND b IS NULL; + +SELECT * FROM t1, t2 + WHERE a <> 'USARussian' AND b IS NULL; + +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; + +DROP TABLE t1,t2; + + set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/t/selectivity_innodb.test b/mysql-test/t/selectivity_innodb.test index 5674cb5c006..d6a77eac600 100644 --- a/mysql-test/t/selectivity_innodb.test +++ b/mysql-test/t/selectivity_innodb.test @@ -79,6 +79,36 @@ select * from t1 where col2 != true; drop table t1; +--echo # +--echo # MDEV-7413: optimizer_use_condition_selectivity > 2 crashes 10.0.15+maria-1~wheezy +--echo # + +CREATE TABLE t1 ( + parent_id int, + child_group_id int, + child_user_id int, + KEY (parent_id,child_group_id,child_user_id) +) ENGINE=InnoDB; + +CREATE TABLE t2 ( + id int, + lower_group_name varchar(255), + directory_id int(20), + UNIQUE KEY (directory_id) +) ENGINE=InnoDB; + +CREATE TABLE t3 (id int) ENGINE=InnoDB; + +insert into t1 values (1,1,1),(2,2,2); +insert into t2 values (10,'foo',10),(20,'bar',20); +insert into t3 values (101),(102); +set use_stat_tables = PREFERABLY, optimizer_use_condition_selectivity = 3; + +select * from t1, t2, t3 +where t1.child_user_id=t3.id and t1.child_group_id is null and t2.lower_group_name='foo' and t1.parent_id=t2.id and t2.directory_id=10; + +drop table t1,t2,t3; + --echo # --echo # End of 10.0 tests --echo # diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test index 42a3dd193c4..2a24ab3d005 100644 --- a/mysql-test/t/sp_notembedded.test +++ b/mysql-test/t/sp_notembedded.test @@ -461,6 +461,26 @@ DROP EVENT teste_bug11763507; --echo # -- End of 5.1 tests --echo # ------------------------------------------------------------------ +# +# A case of SHOW GRANTS +# (creating a new procedure changes the password) +# +grant create routine on test.* to foo1@localhost identified by 'foo'; +update mysql.user set password = replace(password, '*', '-') where user='foo1'; +--connect (foo,localhost,foo1,foo) +show grants; +--connection default +flush privileges; +--connection foo +show grants; +create procedure spfoo() select 1; +show grants; + +--connection default +--disconnect foo +drop procedure spfoo; +drop user foo1@localhost; + # # Restore global concurrent_insert value. Keep in the end of the test file. # diff --git a/mysql-test/t/subselect_sj_mat.test b/mysql-test/t/subselect_sj_mat.test index 912e9d5befd..c34c805f90c 100644 --- a/mysql-test/t/subselect_sj_mat.test +++ b/mysql-test/t/subselect_sj_mat.test @@ -1843,3 +1843,45 @@ drop database mysqltest4; --echo # End of 5.5 tests +--echo # +--echo # MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +--echo # +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; + +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; + +create table t3 as select * from t2 limit 1; + +--echo # The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); + +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +--echo # Sequential reads: +--echo # 1K is read from t1 +--echo # 4K is read from t2 +--echo # 1K groups is read from the tmp. table +--echo # +--echo # Lookups: +--echo # 4K lookups in group by table +--echo # 1K lookups in temp.table +--echo # +--echo # Writes: +--echo # 2x 1K writes to temporary tables (grouping table and subquery materialization table +--echo # +--echo # The point is that neither counter should be in the millions (this +--echo # will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; + +drop table t0,t1,t2,t3; diff --git a/mysql-test/t/view_alias.test b/mysql-test/t/view_alias.test index b155ba6c2a9..09d707296bb 100644 --- a/mysql-test/t/view_alias.test +++ b/mysql-test/t/view_alias.test @@ -90,3 +90,12 @@ eval CREATE VIEW v1 AS $query; DROP VIEW v1; DROP TABLE t1, t2; + +# +# MDEV-7482 VIEW containing INTERVAL(...) +# +create view v1 as select interval(55,10) as my_col; +show create view v1; +select * from v1; +drop view v1; + diff --git a/mysys/my_default.c b/mysys/my_default.c index a39c61a9d16..d5ed1256f9c 100644 --- a/mysys/my_default.c +++ b/mysys/my_default.c @@ -855,7 +855,7 @@ static int search_default_file_with_ext(Process_option_func opt_handler, ptr, name, line))) goto err; - if (!(search_dir= my_dir(ptr, MYF(MY_WME)))) + if (!(search_dir= my_dir(ptr, MYF(MY_WME | MY_WANT_SORT)))) goto err; for (i= 0; i < (uint) search_dir->number_of_files; i++) diff --git a/sql/handler.cc b/sql/handler.cc index 234c9408b74..18cf61906a6 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1503,7 +1503,13 @@ done: /* Come here if error and we need to rollback. */ err: error= 1; /* Transaction was rolled back */ - ha_rollback_trans(thd, all); + /* + In parallel replication, rollback is delayed, as there is extra replication + book-keeping to be done before rolling back and allowing a conflicting + transaction to continue (MDEV-7458). + */ + if (!(thd->rgi_slave && thd->rgi_slave->is_parallel_exec)) + ha_rollback_trans(thd, all); end: if (rw_trans && mdl_request.ticket) diff --git a/sql/item.h b/sql/item.h index 13e80639657..7c61c5fc65f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2931,8 +2931,9 @@ public: { set_cs_specified(true); } - Item_string_with_introducer(const String *str, CHARSET_INFO *tocs) - :Item_string(str->ptr(), str->length(), tocs) + Item_string_with_introducer(const char *name, + const char *str, uint length, CHARSET_INFO *tocs) + :Item_string(name, str, length, tocs) { set_cs_specified(true); } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 5d11057228c..8611182f32d 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -734,6 +734,11 @@ public: void fix_length_and_dec(); const char *func_name() const { return "interval"; } uint decimal_precision() const { return 2; } + void print(String *str, enum_query_type query_type) + { + str->append(func_name()); + print_args(str, 0, query_type); + } }; diff --git a/sql/log_event.cc b/sql/log_event.cc index 95c81258216..31abf461f58 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -55,6 +55,8 @@ #define my_b_write_string(A, B) my_b_write((A), (B), (uint) (sizeof(B) - 1)) +using std::max; + /** BINLOG_CHECKSUM variable. */ @@ -1329,9 +1331,10 @@ int Log_event::read_log_event(IO_CACHE* file, String* packet, } data_len= uint4korr(buf + EVENT_LEN_OFFSET); if (data_len < LOG_EVENT_MINIMAL_HEADER_LEN || - data_len > current_thd->variables.max_allowed_packet) + data_len > max(current_thd->variables.max_allowed_packet, + opt_binlog_rows_event_max_size + MAX_LOG_EVENT_HEADER)) { - DBUG_PRINT("error",("data_len: %ld", data_len)); + DBUG_PRINT("error",("data_len: %lu", data_len)); result= ((data_len < LOG_EVENT_MINIMAL_HEADER_LEN) ? LOG_READ_BOGUS : LOG_READ_TOO_LARGE); goto end; @@ -1452,7 +1455,7 @@ failed my_b_read")); */ DBUG_RETURN(0); } - uint data_len = uint4korr(head + EVENT_LEN_OFFSET); + ulong data_len = uint4korr(head + EVENT_LEN_OFFSET); char *buf= 0; const char *error= 0; Log_event *res= 0; @@ -1461,7 +1464,8 @@ failed my_b_read")); uint max_allowed_packet= thd ? slave_max_allowed_packet:~(uint)0; #endif - if (data_len > max_allowed_packet) + if (data_len > max(max_allowed_packet, + opt_binlog_rows_event_max_size + MAX_LOG_EVENT_HEADER)) { error = "Event too big"; goto err; @@ -1495,7 +1499,7 @@ err: { DBUG_ASSERT(error != 0); sql_print_error("Error in Log_event::read_log_event(): " - "'%s', data_len: %d, event_type: %d", + "'%s', data_len: %lu, event_type: %d", error,data_len,(uchar)(head[EVENT_TYPE_OFFSET])); my_free(buf); /* diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 7d1f6dfbf9d..d5e3334d961 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -513,8 +513,6 @@ bool is_materialization_applicable(THD *thd, Item_in_subselect *in_subs, Subquery !contains {GROUP BY, ORDER BY [LIMIT], aggregate functions}) && subquery predicate is not under "NOT IN")) - (*) The subquery must be part of a SELECT or CREATE TABLE ... SELECT statement. - The current condition also excludes multi-table update statements. A note about prepared statements: we want the if-branch to be taken on PREPARE and each EXECUTE. The rewrites are only done once, but we need select_lex->sj_subselects list to be populated for every EXECUTE. @@ -523,9 +521,7 @@ bool is_materialization_applicable(THD *thd, Item_in_subselect *in_subs, if (optimizer_flag(thd, OPTIMIZER_SWITCH_MATERIALIZATION) && // 0 !child_select->is_part_of_union() && // 1 parent_unit->first_select()->leaf_tables.elements && // 2 - (thd->lex->sql_command == SQLCOM_SELECT || // * - thd->lex->sql_command == SQLCOM_CREATE_TABLE) && // * - child_select->outer_select()->leaf_tables.elements && // 2A + child_select->outer_select()->leaf_tables.elements && // 2A subquery_types_allow_materialization(in_subs) && (in_subs->is_top_level_item() || //3 optimizer_flag(thd, diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index 46c3e4aaaf4..c6bb974f62f 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -640,7 +640,7 @@ handle_rpl_parallel_thread(void *arg) } DBUG_ASSERT(qev->typ==rpl_parallel_thread::queued_event::QUEUED_EVENT); - thd->rgi_slave= group_rgi= rgi; + thd->rgi_slave= rgi; gco= rgi->gco; /* Handle a new event group, which will be initiated by a GTID event. */ if ((event_type= qev->ev->get_type_code()) == GTID_EVENT) @@ -657,6 +657,21 @@ handle_rpl_parallel_thread(void *arg) } }); + if(unlikely(thd->wait_for_commit_ptr) && group_rgi != NULL) + { + /* + This indicates that we get a new GTID event in the middle of + a not completed event group. This is corrupt binlog (the master + will never write such binlog), so it does not happen unless + someone tries to inject wrong crafted binlog, but let us still + try to handle it somewhat nicely. + */ + group_rgi->cleanup_context(thd, true); + finish_event_group(rpt, group_rgi->gtid_sub_id, + group_rgi->parallel_entry, group_rgi); + rpt->loc_free_rgi(group_rgi); + } + in_event_group= true; /* If the standalone flag is set, then this event group consists of a @@ -742,19 +757,6 @@ handle_rpl_parallel_thread(void *arg) unlock_or_exit_cond(thd, &entry->LOCK_parallel_entry, &did_enter_cond, &old_stage); - if(thd->wait_for_commit_ptr) - { - /* - This indicates that we get a new GTID event in the middle of - a not completed event group. This is corrupt binlog (the master - will never write such binlog), so it does not happen unless - someone tries to inject wrong crafted binlog, but let us still - try to handle it somewhat nicely. - */ - rgi->cleanup_context(thd, true); - thd->wait_for_commit_ptr->unregister_wait_for_prior_commit(); - thd->wait_for_commit_ptr->wakeup_subsequent_commits(rgi->worker_error); - } thd->wait_for_commit_ptr= &rgi->commit_orderer; if (opt_gtid_ignore_duplicates) @@ -780,6 +782,7 @@ handle_rpl_parallel_thread(void *arg) } } + group_rgi= rgi; group_ending= is_group_ending(qev->ev, event_type); if (group_ending && likely(!rgi->worker_error)) { diff --git a/sql/slave.cc b/sql/slave.cc index 237c1c57ccc..d24f72ff891 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -374,6 +374,9 @@ int init_slave() if (run_slave_init_thread()) return 1; + if (global_rpl_thread_pool.init(opt_slave_parallel_threads)) + return 1; + /* This is called when mysqld starts. Before client connections are accepted. However bootstrap may conflict with us if it does START SLAVE. @@ -407,9 +410,6 @@ int init_slave() goto err; } - if (global_rpl_thread_pool.init(opt_slave_parallel_threads)) - return 1; - /* If --slave-skip-errors=... was not used, the string value for the system variable has not been set up yet. Do it now. @@ -5691,6 +5691,18 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len) } break; +#ifndef DBUG_OFF + case XID_EVENT: + DBUG_EXECUTE_IF("slave_discard_xid_for_gtid_0_x_1000", + { + /* Inject an event group that is missing its XID commit event. */ + if (mi->last_queued_gtid.domain_id == 0 && + mi->last_queued_gtid.seq_no == 1000) + goto skip_relay_logging; + }); + /* Fall through to default case ... */ +#endif + default: default_action: if (mi->using_gtid != Master_info::USE_GTID_NO && mi->gtid_event_seen) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 0cc71083613..fc64c4059f2 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -9879,7 +9879,6 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, List user_list; bool result; ACL_USER *au; - char passwd_buff[SCRAMBLED_PASSWORD_CHAR_LENGTH+1]; Dummy_error_handler error_handler; DBUG_ENTER("sp_grant_privileges"); @@ -9920,33 +9919,10 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, if(au) { - if (au->salt_len) - { - if (au->salt_len == SCRAMBLE_LENGTH) - { - make_password_from_salt(passwd_buff, au->salt); - combo->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH; - } - else if (au->salt_len == SCRAMBLE_LENGTH_323) - { - make_password_from_salt_323(passwd_buff, (ulong *) au->salt); - combo->password.length= SCRAMBLED_PASSWORD_CHAR_LENGTH_323; - } - else - { - push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_PASSWD_LENGTH, - ER(ER_PASSWD_LENGTH), SCRAMBLED_PASSWORD_CHAR_LENGTH); - return TRUE; - } - combo->password.str= passwd_buff; - } - if (au->plugin.str != native_password_plugin_name.str && au->plugin.str != old_password_plugin_name.str) - { combo->plugin= au->plugin; - combo->auth= au->auth_string; - } + combo->auth= au->auth_string; } if (user_list.push_back(combo)) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 730adfe94ed..280c2202d90 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2499,11 +2499,15 @@ mysql_execute_command(THD *thd) according to slave filtering rules. Returning success without producing any errors in this case. */ - DBUG_RETURN(0); + if (!thd->lex->check_exists) + DBUG_RETURN(0); + /* + DROP TRIGGER IF NOT EXISTS will return without an error later + after possibly writing the query to a binlog + */ } - - // force searching in slave.cc:tables_ok() - all_tables->updating= 1; + else // force searching in slave.cc:tables_ok() + all_tables->updating= 1; } /* diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index dc1c1a9ecaa..eb2c12d550a 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1948,6 +1948,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, slave_connection_state until_gtid_state_obj; rpl_gtid error_gtid; binlog_send_info info(thd, packet, flags, log_file_name); + bool has_transmit_started= false; int old_max_allowed_packet= thd->variables.max_allowed_packet; @@ -2007,16 +2008,6 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, DBUG_SET("+d,corrupt_read_log_event2"); }); - if (global_system_variables.log_warnings > 1) - sql_print_information("Start binlog_dump to slave_server(%lu), pos(%s, %lu)", - thd->variables.server_id, log_ident, (ulong)pos); - if (RUN_HOOK(binlog_transmit, transmit_start, (thd, flags, log_ident, pos))) - { - errmsg= "Failed to run hook 'transmit_start'"; - my_errno= ER_UNKNOWN_ERROR; - goto err; - } - #ifndef DBUG_OFF if (opt_sporadic_binlog_dump_fail && (binlog_dump_count++ % 2)) { @@ -2113,6 +2104,17 @@ impossible position"; goto err; } + if (global_system_variables.log_warnings > 1) + sql_print_information("Start binlog_dump to slave_server(%lu), pos(%s, %lu)", + thd->variables.server_id, log_ident, (ulong)pos); + if (RUN_HOOK(binlog_transmit, transmit_start, (thd, flags, log_ident, pos))) + { + errmsg= "Failed to run hook 'transmit_start'"; + my_errno= ER_UNKNOWN_ERROR; + goto err; + } + has_transmit_started= true; + /* reset transmit packet for the fake rotate event below */ if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg)) goto err; @@ -2680,7 +2682,8 @@ end: end_io_cache(&log); mysql_file_close(file, MYF(MY_WME)); - RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags)); + if (has_transmit_started) + RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags)); my_eof(thd); THD_STAGE_INFO(thd, stage_waiting_to_finalize_termination); mysql_mutex_lock(&LOCK_thread_count); @@ -2749,7 +2752,8 @@ err: else strcpy(error_text, errmsg); end_io_cache(&log); - RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags)); + if (has_transmit_started) + RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags)); /* Exclude iteration through thread list this is needed for purge_logs() - it will iterate through diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 55dc0494594..66d3432526f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4958,7 +4958,18 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array, KEY_FIELD *key_field) } -#define FT_KEYPART (MAX_REF_PARTS+10) +/* + A key part number that means we're using a fulltext scan. + + In order not to confuse it with regular equalities, we need to pick + a number that's greater than MAX_REF_PARTS. + + Hash Join code stores field->field_index in KEYUSE::keypart, so the + number needs to be bigger than MAX_FIELDS, also. + + CAUTION: sql_test.cc has its own definition of FT_KEYPART. +*/ +#define FT_KEYPART (MAX_FIELDS+10) static bool add_ft_keys(DYNAMIC_ARRAY *keyuse_array, @@ -7451,8 +7462,12 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, else fldno= table->key_info[key].key_part[keyparts-1].fieldnr - 1; if (keyuse->val->const_item()) - { - sel /= table->field[fldno]->cond_selectivity; + { + if (table->field[fldno]->cond_selectivity > 0) + { + sel /= table->field[fldno]->cond_selectivity; + set_if_smaller(sel, 1.0); + } /* TODO: we could do better here: 1. cond_selectivity might be =1 (the default) because quick @@ -7506,7 +7521,10 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, if (!(next_field->table->map & rem_tables) && next_field->table != table) { if (field->cond_selectivity > 0) + { sel/= field->cond_selectivity; + set_if_smaller(sel, 1.0); + } break; } } diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 8992ff24a1e..82abc861ec4 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -220,7 +220,7 @@ TEST_join(JOIN *join) } -#define FT_KEYPART (MAX_REF_PARTS+10) +#define FT_KEYPART (MAX_FIELDS+10) void print_keyuse(KEYUSE *keyuse) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 8716e39a94f..d9d63727441 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -13404,7 +13404,12 @@ literal: | UNDERSCORE_CHARSET hex_or_bin_String { Item_string_with_introducer *item_str; - item_str= new (thd->mem_root) Item_string_with_introducer($2, $1); + /* + Pass NULL as name. Name will be set in the "select_item" rule and + will include the introducer and the original hex/bin notation. + */ + item_str= new (thd->mem_root) + Item_string_with_introducer(NULL, $2->ptr(), $2->length(), $1); if (!item_str || !item_str->check_well_formed_result(true)) MYSQL_YYABORT; diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 956372e4960..1950b9bf125 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -21,9 +21,9 @@ ha_connect.cc connect.cc user_connect.cc mycat.cc fmdlex.c osutil.c plugutil.c rcmsg.c rcmsg.h array.cpp blkfil.cpp colblk.cpp csort.cpp filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamvct.cpp filamzip.cpp -filter.cpp json.cpp maputil.cpp myutil.cpp plgdbutl.cpp reldef.cpp tabcol.cpp -tabdos.cpp tabfix.cpp tabfmt.cpp tabjson.cpp table.cpp tabmul.cpp taboccur.cpp -tabpivot.cpp tabsys.cpp tabtbl.cpp tabutil.cpp tabvct.cpp tabvir.cpp +filter.cpp json.cpp jsonudf.cpp maputil.cpp myutil.cpp plgdbutl.cpp reldef.cpp +tabcol.cpp tabdos.cpp tabfix.cpp tabfmt.cpp tabjson.cpp table.cpp tabmul.cpp +taboccur.cpp tabpivot.cpp tabsys.cpp tabtbl.cpp tabutil.cpp tabvct.cpp tabvir.cpp tabxcl.cpp valblk.cpp value.cpp xindex.cpp xobject.cpp array.h blkfil.h block.h catalog.h checklvl.h colblk.h connect.h csort.h diff --git a/storage/connect/array.h b/storage/connect/array.h index 4a818414e9c..6fb38ae6b47 100644 --- a/storage/connect/array.h +++ b/storage/connect/array.h @@ -50,6 +50,7 @@ class DllExport ARRAY : public XOBJECT, public CSORT { // Array descblock // void SetCorrel(bool b) {Correlated = b;} // Methods + using XOBJECT::GetIntValue; virtual void Reset(void) {Bot = -1;} virtual int Qcompare(int *, int *); virtual bool Compare(PXOB) {assert(FALSE); return FALSE;} diff --git a/storage/connect/checklvl.h b/storage/connect/checklvl.h index d1e37afbc93..0c234dfb8b8 100644 --- a/storage/connect/checklvl.h +++ b/storage/connect/checklvl.h @@ -40,4 +40,11 @@ enum USETEMP {TMP_NO = 0, /* Never */ TMP_FORCE = 3, /* Forced for MAP tables */ TMP_TEST = 4}; /* Testing value */ +/***********************************************************************/ +/* Following definitions indicate conversion of TEXT columns. */ +/***********************************************************************/ +enum TYPCONV {TPC_NO = 0, /* Never */ + TPC_YES = 1, /* Always */ + TPC_SKIP = 2}; /* Skip TEXT columns */ + #endif // _CHKLVL_DEFINED_ diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index a54d8ebcc44..1b0db6dca6b 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -469,9 +469,12 @@ RCODE CntReadNext(PGLOBAL g, PTDB tdbp) } while (rc == RC_NF); + if (rc == RC_OK) + rc= EvalColumns(g, tdbp, false); + err: g->jump_level--; - return (rc != RC_OK) ? rc : EvalColumns(g, tdbp, false); + return rc; } // end of CntReadNext /***********************************************************************/ diff --git a/storage/connect/global.h b/storage/connect/global.h index 88e5094d6d2..a67bb605755 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -235,7 +235,7 @@ typedef struct _global { /* Global structure */ void *Xchk; /* indexes in create/alter */ short Alchecked; /* Checked for ALTER */ short Mrr; /* True when doing mrr */ - short Trace; + int N; /* Utility */ int jump_level; jmp_buf jumper[MAX_JUMP + 2]; } GLOBAL; diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index a0ac4668eba..e73a64a150c 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -165,23 +165,24 @@ /***********************************************************************/ /* Initialize the ha_connect static members. */ /***********************************************************************/ -#define SZCONV 8192 -#define SZWORK 67108864 // Default work area size 64M -#define SZWMIN 4194304 // Minimum work area size 4M +#define SZCONV 8192 +#define SZWORK 67108864 // Default work area size 64M +#define SZWMIN 4194304 // Minimum work area size 4M +#define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.03.0006 January 13, 2015"; - char compver[]= "Version 1.03.0006 " __DATE__ " " __TIME__; + char version[]= "Version 1.03.0006 February 06, 2015"; #if defined(WIN32) + char compver[]= "Version 1.03.0006 " __DATE__ " " __TIME__; char slash= '\\'; #else // !WIN32 char slash= '/'; #endif // !WIN32 // int trace= 0; // The general trace value - ulong xconv= 0; // The type conversion option - int zconv= 0; // The text conversion size +// ulong xconv= 0; // The type conversion option +// int zconv= 0; // The text conversion size } // extern "C" #if defined(XMAP) @@ -215,6 +216,9 @@ bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, const char *host, const char *db, char *tab, const char *src, int port); bool ExactInfo(void); USETEMP UseTemp(void); +int GetConvSize(void); +TYPCONV GetTypeConv(void); +uint GetJsonGrpSize(void); uint GetWorkSize(void); void SetWorkSize(uint); extern "C" const char *msglang(void); @@ -289,6 +293,44 @@ static MYSQL_THDVAR_UINT(work_size, "Size of the CONNECT work area.", NULL, NULL, SZWORK, SZWMIN, UINT_MAX, 1); +// Size used when converting TEXT columns to VARCHAR +static MYSQL_THDVAR_INT(conv_size, + PLUGIN_VAR_RQCMDARG, // opt + "Size used when converting TEXT columns.", + NULL, NULL, SZCONV, 0, 65500, 1); + +/** + Type conversion: + no: Unsupported types -> TYPE_ERROR + yes: TEXT -> VARCHAR + skip: skip unsupported type columns in Discovery +*/ +const char *xconv_names[]= +{ + "NO", "YES", "SKIP", NullS +}; + +TYPELIB xconv_typelib= +{ + array_elements(xconv_names) - 1, "xconv_typelib", + xconv_names, NULL +}; + +static MYSQL_THDVAR_ENUM( + type_conv, // name + PLUGIN_VAR_RQCMDARG, // opt + "Unsupported types conversion.", // comment + NULL, // check + NULL, // update function + 0, // def (no) + &xconv_typelib); // typelib + +// Estimate max number of rows for JSON aggregate functions +static MYSQL_THDVAR_UINT(json_grp_size, + PLUGIN_VAR_RQCMDARG, // opt + "max number of rows for JSON aggregate functions.", + NULL, NULL, JSONMAX, 1, INT_MAX, 1); + #if defined(XMSG) || defined(NEWMSG) const char *language_names[]= { @@ -317,6 +359,9 @@ static MYSQL_THDVAR_ENUM( extern "C" int GetTraceValue(void) {return THDVAR(current_thd, xtrace);} bool ExactInfo(void) {return THDVAR(current_thd, exact_info);} USETEMP UseTemp(void) {return (USETEMP)THDVAR(current_thd, use_tempfile);} +int GetConvSize(void) {return THDVAR(current_thd, conv_size);} +TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);} +uint GetJsonGrpSize(void) {return THDVAR(current_thd, json_grp_size);} uint GetWorkSize(void) {return THDVAR(current_thd, work_size);} void SetWorkSize(uint n) { @@ -598,7 +643,11 @@ static int connect_init_func(void *p) } #endif // 0 (LINUX) +#if defined(WIN32) sql_print_information("CONNECT: %s", compver); +#else // !WIN32 + sql_print_information("CONNECT: %s", version); +#endif // !WIN32 #ifdef LIBXML2_SUPPORT XmlInitParserLib(); @@ -934,6 +983,9 @@ ulonglong ha_connect::table_flags() const char *GetListOption(PGLOBAL g, const char *opname, const char *oplist, const char *def) { + if (!oplist) + return (char*)def; + char key[16], val[256]; char *pk, *pv, *pn; char *opval= (char*) def; @@ -997,8 +1049,12 @@ char *ha_connect::GetRealString(const char *s) char *sv; if (IsPartitioned() && s) { - sv= (char*)PlugSubAlloc(xp->g, NULL, strlen(s) + strlen(partname)); +// sv= (char*)PlugSubAlloc(xp->g, NULL, strlen(s) + strlen(partname)); + // With wrong string pattern, the size of the constructed string + // can be more than strlen(s) + strlen(partname) + sv= (char*)PlugSubAlloc(xp->g, NULL, 0); sprintf(sv, s, partname); + PlugSubAlloc(xp->g, NULL, strlen(sv) + 1); } else sv= (char*)s; @@ -1064,9 +1120,16 @@ char *ha_connect::GetStringOption(char *opname, char *sdef) } // endif Table_charset - if (!opval && options && options->oplist) + if (!opval && options && options->oplist) { opval= GetListOption(xp->g, opname, options->oplist); + if (opval && (!stricmp(opname, "connect") + || !stricmp(opname, "tabname") + || !stricmp(opname, "filename"))) + opval = GetRealString(opval); + + } // endif opval + if (!opval) { if (sdef && !strcmp(sdef, "*")) { // Return the handler default value @@ -2467,6 +2530,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond) char *body= filp->Body; unsigned int i; bool ismul= false, x= (tty == TYPE_AM_MYX || tty == TYPE_AM_XDBC); + bool nonul= (tty == TYPE_AM_ODBC && (tdbp->GetMode() == MODE_INSERT || + tdbp->GetMode() == MODE_DELETE)); OPVAL vop= OP_XX; if (!cond) @@ -2484,7 +2549,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond) if (trace) htrc("Cond: Ftype=%d name=%s\n", cond_item->functype(), - cond_item->func_name()); + cond_item->func_name()); switch (cond_item->functype()) { case Item_func::COND_AND_FUNC: vop= OP_AND; break; @@ -2503,7 +2568,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond) for (i= 0; i < arglist->elements; i++) if ((subitem= li++)) { if (!CheckCond(g, filp, tty, subitem)) { - if (vop == OP_OR) + if (vop == OP_OR || nonul) return NULL; else *p2= 0; @@ -2599,6 +2664,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond) if (trace) { htrc("Field index=%d\n", pField->field->field_index); htrc("Field name=%s\n", pField->field->field_name); + htrc("Field type=%d\n", pField->field->type()); + htrc("Field_type=%d\n", args[i]->field_type()); } // endif trace // IN and BETWEEN clauses should be col VOP list @@ -2618,8 +2685,9 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond) char buff[256]; String *res, tmp(buff, sizeof(buff), &my_charset_bin); Item_basic_constant *pval= (Item_basic_constant *)args[i]; + Item::Type type= args[i]->real_type(); - switch (args[i]->real_type()) { + switch (type) { case COND::STRING_ITEM: case COND::INT_ITEM: case COND::REAL_ITEM: @@ -2644,10 +2712,64 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, AMT tty, Item *cond) if (!x) { // Append the value to the filter - if (args[i]->field_type() == MYSQL_TYPE_VARCHAR) - strcat(strncat(strcat(body, "'"), res->ptr(), res->length()), "'"); - else - strncat(body, res->ptr(), res->length()); + switch (args[i]->field_type()) { + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_DATETIME: + if (tty == TYPE_AM_ODBC) { + strcat(body, "{ts '"); + strcat(strncat(body, res->ptr(), res->length()), "'}"); + break; + } // endif ODBC + + case MYSQL_TYPE_DATE: + if (tty == TYPE_AM_ODBC) { + strcat(body, "{d '"); + strcat(strncat(body, res->ptr(), res->length()), "'}"); + break; + } // endif ODBC + + case MYSQL_TYPE_TIME: + if (tty == TYPE_AM_ODBC) { + strcat(body, "{t '"); + strcat(strncat(body, res->ptr(), res->length()), "'}"); + break; + } // endif ODBC + + case MYSQL_TYPE_VARCHAR: + if (tty == TYPE_AM_ODBC && i) { + switch (args[0]->field_type()) { + case MYSQL_TYPE_TIMESTAMP: + case MYSQL_TYPE_DATETIME: + strcat(body, "{ts '"); + strncat(body, res->ptr(), res->length()); + strcat(body, "'}"); + break; + case MYSQL_TYPE_DATE: + strcat(body, "{d '"); + strncat(body, res->ptr(), res->length()); + strcat(body, "'}"); + break; + case MYSQL_TYPE_TIME: + strcat(body, "{t '"); + strncat(body, res->ptr(), res->length()); + strcat(body, "'}"); + break; + default: + strcat(body, "'"); + strncat(body, res->ptr(), res->length()); + strcat(body, "'"); + } // endswitch field type + + } else { + strcat(body, "'"); + strncat(body, res->ptr(), res->length()); + strcat(body, "'"); + } // endif tty + + break; + default: + strncat(body, res->ptr(), res->length()); + } // endswitch field type } else { if (args[i]->field_type() == MYSQL_TYPE_VARCHAR) { @@ -2753,7 +2875,7 @@ const COND *ha_connect::cond_push(const COND *cond) } else if (x && cond) tdbp->SetCondFil(filp); // Wrong filter - } else + } else if (tty != TYPE_AM_JSN && tty != TYPE_AM_JSON) tdbp->SetFilter(CondFilter(g, (Item *)cond)); fin: @@ -4620,7 +4742,7 @@ static bool add_field(String *sql, const char *field_name, int typ, char *dft, char *xtra, int flag, bool dbf, char v) { char var = (len > 255) ? 'V' : v; - bool error= false; + bool q, error= false; const char *type= PLGtoMYSQLtype(typ, dbf, var); error|= sql->append('`'); @@ -4661,7 +4783,12 @@ static bool add_field(String *sql, const char *field_name, int typ, if (dft && *dft) { error|= sql->append(" DEFAULT "); - if (!IsTypeNum(typ)) { + if (typ == TYPE_DATE) + q = (strspn(dft, "0123456789 -:/") == strlen(dft)); + else + q = !IsTypeNum(typ); + + if (q) { error|= sql->append("'"); error|= sql->append_for_single_quote(dft, strlen(dft)); error|= sql->append("'"); @@ -4831,6 +4958,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, int port= 0, hdr= 0, mxr __attribute__((unused))= 0, mxe= 0, rc= 0; int cop __attribute__((unused)) = 0; #if defined(ODBC_SUPPORT) + POPARM sop = NULL; + char *ucnc = NULL; + bool cnc= false; int cto= -1, qto= -1; #endif // ODBC_SUPPORT uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL); @@ -4875,7 +5005,8 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, if (topt->oplist) { host= GetListOption(g, "host", topt->oplist, "localhost"); - user= GetListOption(g, "user", topt->oplist, "root"); + user= GetListOption(g, "user", topt->oplist, + (ttp == TAB_ODBC ? NULL : "root")); // Default value db can come from the DBNAME=xxx option. db= GetListOption(g, "database", topt->oplist, db); col= GetListOption(g, "colist", topt->oplist, col); @@ -4894,6 +5025,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0")); cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1")); qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1")); + + if ((ucnc= GetListOption(g, "UseDSN", topt->oplist))) + cnc= (!*ucnc || *ucnc == 'y' || *ucnc == 'Y' || atoi(ucnc) != 0); #endif mxe= atoi(GetListOption(g,"maxerr", topt->oplist, "0")); #if defined(PROMPT_OK) @@ -4901,7 +5035,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, #endif // PROMPT_OK } else { host= "localhost"; - user= "root"; + user= (ttp == TAB_ODBC ? NULL : "root"); } // endif option_list if (!(shm= (char*)db)) @@ -4978,10 +5112,18 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, } // endif dsn #endif // PROMPT_OK - } else if (!dsn) + } else if (!dsn) { sprintf(g->Message, "Missing %s connection string", topt->type); - else + } else { + // Store ODBC additional parameters + sop= (POPARM)PlugSubAlloc(g, NULL, sizeof(ODBCPARM)); + sop->User= (char*)user; + sop->Pwd= (char*)pwd; + sop->Cto= cto; + sop->Qto= qto; + sop->UseCnc= cnc; ok= true; + } // endif's supfnc |= (FNC_TABLE | FNC_DSN | FNC_DRIVER); break; @@ -5112,15 +5254,15 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, case FNC_NO: case FNC_COL: if (src) { - qrp= ODBCSrcCols(g, dsn, (char*)src, cto, qto); + qrp= ODBCSrcCols(g, dsn, (char*)src, sop); src= NULL; // for next tests } else - qrp= ODBCColumns(g, dsn, shm, tab, NULL, - mxr, cto, qto, fnc == FNC_COL); + qrp= ODBCColumns(g, dsn, shm, tab, NULL, + mxr, fnc == FNC_COL, sop); break; case FNC_TABLE: - qrp= ODBCTables(g, dsn, shm, tab, mxr, cto, qto, true); + qrp= ODBCTables(g, dsn, shm, tab, mxr, true, sop); break; case FNC_DSN: qrp= ODBCDataSources(g, mxr, true); @@ -5237,9 +5379,10 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, for (crp= qrp->Colresp; crp; crp= crp->Next) switch (crp->Fld) { case FLD_NAME: - if (ttp == TAB_CSV && topt->data_charset && + if (ttp == TAB_PRX || + (ttp == TAB_CSV && topt->data_charset && (!stricmp(topt->data_charset, "UTF8") || - !stricmp(topt->data_charset, "UTF-8"))) + !stricmp(topt->data_charset, "UTF-8")))) cnm= crp->Kdata->GetCharValue(i); else cnm= encode(g, crp->Kdata->GetCharValue(i)); @@ -5299,9 +5442,18 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, // typ must be PLG type, not SQL type if (!(plgtyp= TranslateSQLType(typ, dec, prec, v))) { - sprintf(g->Message, "Unsupported SQL type %d", typ); - my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); - goto err; + if (GetTypeConv() == TPC_SKIP) { + // Skip this column + sprintf(g->Message, "Column %s skipped (unsupported type %d)", + cnm, typ); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); + continue; + } else { + sprintf(g->Message, "Unsupported SQL type %d", typ); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + goto err; + } // endif type_conv + } else typ= plgtyp; @@ -6341,58 +6493,6 @@ struct st_mysql_storage_engine connect_storage_engine= /***********************************************************************/ /* CONNECT global variables definitions. */ /***********************************************************************/ -// Size used when converting TEXT columns to VARCHAR -#if defined(_DEBUG) -static MYSQL_SYSVAR_INT(conv_size, zconv, - PLUGIN_VAR_RQCMDARG, // opt - "Size used when converting TEXT columns.", - NULL, NULL, SZCONV, 0, 65500, 1); -#else -static MYSQL_SYSVAR_INT(conv_size, zconv, - PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, // opt - "Size used when converting TEXT columns.", - NULL, NULL, SZCONV, 0, 65500, 1); -#endif - -/** - Type conversion: - no: Unsupported types -> TYPE_ERROR - yes: TEXT -> VARCHAR - skip: skip unsupported type columns in Discovery -*/ -const char *xconv_names[]= -{ - "NO", "YES", "SKIP", NullS -}; - -TYPELIB xconv_typelib= -{ - array_elements(xconv_names) - 1, "xconv_typelib", - xconv_names, NULL -}; - -#if defined(_DEBUG) -static MYSQL_SYSVAR_ENUM( - type_conv, // name - xconv, // varname - PLUGIN_VAR_RQCMDARG, // opt - "Unsupported types conversion.", // comment - NULL, // check - NULL, // update function - 0, // def (no) - &xconv_typelib); // typelib -#else -static MYSQL_SYSVAR_ENUM( - type_conv, // name - xconv, // varname - PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, - "Unsupported types conversion.", // comment - NULL, // check - NULL, // update function - 0, // def (no) - &xconv_typelib); // typelib -#endif - #if defined(XMAP) // Using file mapping for indexes if true static MYSQL_SYSVAR_BOOL(indx_map, xmap, PLUGIN_VAR_RQCMDARG, @@ -6425,6 +6525,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= { #if defined(XMSG) MYSQL_SYSVAR(errmsg_dir_path), #endif // XMSG + MYSQL_SYSVAR(json_grp_size), NULL }; diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp index 983f45d9cee..8031ba51b19 100644 --- a/storage/connect/json.cpp +++ b/storage/connect/json.cpp @@ -1,1055 +1,1112 @@ -/*************** json CPP Declares Source Code File (.H) ***************/ -/* Name: json.cpp Version 1.0 */ -/* */ -/* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */ -/* */ -/* This file contains the JSON classes functions. */ -/***********************************************************************/ - -/***********************************************************************/ -/* Include relevant sections of the MariaDB header file. */ -/***********************************************************************/ -#include - -/***********************************************************************/ -/* Include application header files: */ -/* global.h is header containing all global declarations. */ -/* plgdbsem.h is header containing the DB application declarations. */ -/* xjson.h is header containing the JSON classes declarations. */ -/***********************************************************************/ -#include "global.h" -#include "plgdbsem.h" -#include "json.h" - -#define ARGS MY_MIN(24,len-i),s+MY_MAX(i-3,0) - -#if defined(WIN32) -#define EL "\r\n" -#else -#define EL "\n" -#endif - -/***********************************************************************/ -/* Parse a json string. */ -/***********************************************************************/ -PJSON ParseJson(PGLOBAL g, char *s, int len, int pretty, bool *comma) -{ - int i; - bool b = false; - PJSON jsp = NULL; - STRG src; - - if (!s || !len) { - strcpy(g->Message, "Void JSON object"); - return NULL; - } else if (comma) - *comma = false; - - src.str = s; - src.len = len; - - for (i = 0; i < len; i++) - switch (s[i]) { - case '[': - if (jsp) { - strcpy(g->Message, "More than one item in file"); - return NULL; - } else if (!(jsp = ParseArray(g, ++i, src))) - return NULL; - - break; - case '{': - if (jsp) { - strcpy(g->Message, "More than one item in file"); - return NULL; - } else if (!(jsp = ParseObject(g, ++i, src))) - return NULL; - break; - case ' ': - case '\t': - case '\n': - case '\r': - break; - case ',': - if (jsp && pretty == 1) { - if (comma) - *comma = true; - - break; - } // endif pretty - - sprintf(g->Message, "Unexpected ',' (pretty=%d)", pretty); - return NULL; - case '(': - b = true; - break; - case ')': - if (b) { - b = false; - break; - } // endif b - - default: - sprintf(g->Message, "Bad '%c' character near %.*s", - s[i], ARGS); - return NULL; - }; // endswitch s[i] - - if (!jsp) - sprintf(g->Message, "Invalid Json string '%.*s'", 50, s); - - return jsp; -} // end of ParseJson - -/***********************************************************************/ -/* Parse a JSON Array. */ -/***********************************************************************/ -PJAR ParseArray(PGLOBAL g, int& i, STRG& src) -{ - char *s = src.str; - int len = src.len; - int level = 0; - PJAR jarp = new(g) JARRAY; - PJVAL jvp = NULL; - - for (; i < len; i++) - switch (s[i]) { - case ',': - if (level < 2) { - sprintf(g->Message, "Unexpected ',' near %.*s",ARGS); - return NULL; - } else - level = 1; - - break; - case ']': - if (level == 1) { - sprintf(g->Message, "Unexpected ',]' near %.*s", ARGS); - return NULL; - } // endif level - - jarp->InitArray(g); - return jarp; - case ' ': - case '\t': - case '\n': - case '\r': - break; - default: - if (level == 2) { - sprintf(g->Message, "Unexpected value near %.*s", ARGS); - return NULL; - } else if ((jvp = ParseValue(g, i, src))) { - jarp->AddValue(g, jvp); - level = 2; - } else - return NULL; - - level = 2; - break; - }; // endswitch s[i] - - strcpy(g->Message, "Unexpected EOF in array"); - return NULL; -} // end of ParseArray - -/***********************************************************************/ -/* Parse a JSON Object. */ -/***********************************************************************/ -PJOB ParseObject(PGLOBAL g, int& i, STRG& src) -{ - PSZ key; - char *s = src.str; - int len = src.len; - int level = 0; - PJOB jobp = new(g) JOBJECT; - PJPR jpp = NULL; - - for (; i < len; i++) - switch (s[i]) { - case '"': - if (level < 2) { - if ((key = ParseString(g, ++i, src))) { - jpp = jobp->AddPair(g, key); - level = 1; - } else - return NULL; - - } else { - sprintf(g->Message, "misplaced string near %.*s", ARGS); - return NULL; - } // endif level - - break; - case ':': - if (level == 1) { - if (!(jpp->Val = ParseValue(g, ++i, src))) - return NULL; - - level = 2; - } else { - sprintf(g->Message, "Unexpected ':' near %.*s", ARGS); - return NULL; - } // endif level - - break; - case ',': - if (level < 2) { - sprintf(g->Message, "Unexpected ',' near %.*s", ARGS); - return NULL; - } else - level = 1; - - break; - case '}': - if (level == 1) { - sprintf(g->Message, "Unexpected '}' near %.*s", ARGS); - return NULL; - } // endif level - - return jobp; - case ' ': - case '\t': - case '\n': - case '\r': - break; - default: - sprintf(g->Message, "Unexpected character '%c' near %.*s", - s[i], ARGS); - return NULL; - }; // endswitch s[i] - - strcpy(g->Message, "Unexpected EOF in Object"); - return NULL; -} // end of ParseObject - -/***********************************************************************/ -/* Parse a JSON Value. */ -/***********************************************************************/ -PJVAL ParseValue(PGLOBAL g, int& i, STRG& src) -{ - char *strval, *s = src.str; - int n, len = src.len; - PJVAL jvp = new(g) JVALUE; - - for (; i < len; i++) - switch (s[i]) { - case ' ': - case '\t': - case '\n': - case '\r': - break; - default: - goto suite; - } // endswitch - - suite: - switch (s[i]) { - case '[': - if (!(jvp->Jsp = ParseArray(g, ++i, src))) - return NULL; - - break; - case '{': - if (!(jvp->Jsp = ParseObject(g, ++i, src))) - return NULL; - - break; - case '"': - if ((strval = ParseString(g, ++i, src))) - jvp->Value = AllocateValue(g, strval, TYPE_STRING); - else - return NULL; - - break; - case 't': - if (!strncmp(s + i, "true", 4)) { - n = 1; - jvp->Value = AllocateValue(g, &n, TYPE_TINY); - i += 3; - } else - goto err; - - break; - case 'f': - if (!strncmp(s + i, "false", 5)) { - n = 0; - jvp->Value = AllocateValue(g, &n, TYPE_TINY); - i += 4; - } else - goto err; - - break; - case 'n': - if (!strncmp(s + i, "null", 4)) - i += 3; - else - goto err; - - break; - case '-': - default: - if (s[i] == '-' || isdigit(s[i])) { - if (!(jvp->Value = ParseNumeric(g, i, src))) - goto err; - - } else - goto err; - - }; // endswitch s[i] - - jvp->Size = 1; - return jvp; - -err: - sprintf(g->Message, "Unexpected character '%c' near %.*s", - s[i], ARGS); - return NULL; -} // end of ParseValue - -/***********************************************************************/ -/* Unescape and parse a JSON string. */ -/***********************************************************************/ -char *ParseString(PGLOBAL g, int& i, STRG& src) -{ - char *p, *s = src.str; - int n = 0, len = src.len; - - // The size to allocate is not known yet - p = (char*)PlugSubAlloc(g, NULL, 0); - - for (; i < len; i++) - switch (s[i]) { - case '"': - p[n++] = 0; - PlugSubAlloc(g, NULL, n); - return p; - case '\\': - if (++i < len) { - if (s[i] == 'u') { - if (len - i > 5) { -// if (charset == utf8) { - char xs[5]; - uint hex; - - xs[0] = s[++i]; - xs[1] = s[++i]; - xs[2] = s[++i]; - xs[3] = s[++i]; - xs[4] = 0; - hex = strtoul(xs, NULL, 16); - - if (hex < 0x80) { - p[n] = (uchar)hex; - } else if (hex < 0x800) { - p[n++] = (uchar)(0xC0 | (hex >> 6)); - p[n] = (uchar)(0x80 | (hex & 0x3F)); - } else if (hex < 0x10000) { - p[n++] = (uchar)(0xE0 | (hex >> 12)); - p[n++] = (uchar)(0x80 | ((hex >> 6) & 0x3f)); - p[n] = (uchar)(0x80 | (hex & 0x3f)); - } else - p[n] = '?'; - -#if 0 - } else { - char xs[3]; - UINT hex; - - i += 2; - xs[0] = s[++i]; - xs[1] = s[++i]; - xs[2] = 0; - hex = strtoul(xs, NULL, 16); - p[n] = (char)hex; - } // endif charset -#endif // 0 - } else - goto err; - - } else switch(s[i]) { - case 't': p[n] = '\t'; break; - case 'n': p[n] = '\n'; break; - case 'r': p[n] = '\r'; break; - case 'b': p[n] = '\b'; break; - case 'f': p[n] = '\f'; break; - default: p[n] = s[i]; break; - } // endswitch - - n++; - } else - goto err; - - break; - default: - p[n++] = s[i]; - break; - }; // endswitch s[i] - - err: - strcpy(g->Message, "Unexpected EOF in String"); - return NULL; -} // end of ParseString - -/***********************************************************************/ -/* Parse a JSON numeric value. */ -/***********************************************************************/ -PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src) -{ - char *s = src.str, buf[50]; - int n = 0, len = src.len; - short nd = 0; - bool has_dot = false; - bool has_e = false; - bool found_digit = false; - PVAL valp = NULL; - - for (; i < len; i++) { - switch (s[i]) { - case '.': - if (!found_digit || has_dot || has_e) - goto err; - - has_dot = true; - break; - case 'e': - case 'E': - if (!found_digit || has_e) - goto err; - - has_e = true; - found_digit = false; - break; - case '+': - if (!has_e) - goto err; - - // passthru - case '-': - if (found_digit) - goto err; - - break; - default: - if (isdigit(s[i])) { - if (has_dot && !has_e) - nd++; // Number of decimals - - found_digit = true; - } else - goto fin; - - }; // endswitch s[i] - - buf[n++] = s[i]; - } // endfor i - - fin: - if (found_digit) { - buf[n] = 0; - - if (has_dot || has_e) { - double dv = strtod(buf, NULL); - - valp = AllocateValue(g, &dv, TYPE_DOUBLE, nd); - } else { - int iv = strtol(buf, NULL, 10); - - valp = AllocateValue(g, &iv, TYPE_INT); - } // endif has - - i--; // Unstack following character - return valp; - } else { - strcpy(g->Message, "No digit found"); - return NULL; - } // endif found_digit - - err: - strcpy(g->Message, "Unexpected EOF in number"); - return NULL; -} // end of ParseNumeric - -/***********************************************************************/ -/* Serialize a JSON tree: */ -/***********************************************************************/ -PSZ Serialize(PGLOBAL g, PJSON jsp, FILE *fs, int pretty) -{ - bool b = false, err = true; - JOUT *jp; - - g->Message[0] = 0; - - if (!jsp) { - strcpy(g->Message, "Null json tree"); - return NULL; - } else if (!fs) { - // Serialize to a string - jp = new(g) JOUTSTR(g); - b = pretty == 1; - } else if (pretty == 2) { - // Serialize to a pretty file - jp = new(g) JOUTPRT(g, fs); - } else { - // Serialize to a flat file - jp = new(g) JOUTFILE(g, fs); - b = pretty == 1; - } // endif's - - switch (jsp->GetType()) { - case TYPE_JAR: - err = SerializeArray(jp, (PJAR)jsp, b); - break; - case TYPE_JOB: - err = (b && jp->WriteChr('\t')); - err |= SerializeObject(jp, (PJOB)jsp); - break; - default: - strcpy(g->Message, "json tree is not an Array or an Object"); - } // endswitch Type - - if (fs) { - fputc('\n', fs); - fclose(fs); - return (err) ? g->Message : NULL; - } else if (!err) { - PSZ str = ((JOUTSTR*)jp)->Strp; - - jp->WriteChr('\0'); - PlugSubAlloc(g, NULL, ((JOUTSTR*)jp)->N); - return str; - } else { - if (!g->Message[0]) - strcpy(g->Message, "Error in Serialize"); - - return NULL; - } // endif's - -} // end of Serialize - -/***********************************************************************/ -/* Serialize a JSON Array. */ -/***********************************************************************/ -bool SerializeArray(JOUT *js, PJAR jarp, bool b) -{ - bool first = true; - - - if (js->WriteChr('[')) - return true; - else if (b && (js->WriteStr(EL) || js->WriteChr('\t'))) - return true; - - for (int i = 0; i < jarp->size(); i++) { - if (first) - first = false; - else if (js->WriteChr(',')) - return true; - else if (b && (js->WriteStr(EL) || js->WriteChr('\t'))) - return true; - - if (SerializeValue(js, jarp->GetValue(i))) - return true; - - } // endfor i - - if (b && js->WriteStr(EL)) - return true; - - return js->WriteChr(']'); -} // end of SerializeArray - -/***********************************************************************/ -/* Serialize a JSON Object. */ -/***********************************************************************/ -bool SerializeObject(JOUT *js, PJOB jobp) -{ - bool first = true; - - if (js->WriteChr('{')) - return true; - - for (PJPR pair = jobp->First; pair; pair = pair->Next) { - if (first) - first = false; - else if (js->WriteChr(',')) - return true; - - if (js->WriteChr('\"') || - js->WriteStr(pair->Key) || - js->WriteChr('\"') || - js->WriteChr(':') || - SerializeValue(js, pair->Val)) - return true; - - } // endfor i - - return js->WriteChr('}'); -} // end of SerializeObject - -/***********************************************************************/ -/* Serialize a JSON Value. */ -/***********************************************************************/ -bool SerializeValue(JOUT *js, PJVAL jvp) -{ - PJAR jap; - PJOB jop; - PVAL valp; - - if ((jap = jvp->GetArray())) - return SerializeArray(js, jap, false); - else if ((jop = jvp->GetObject())) - return SerializeObject(js, jop); - else if (!(valp = jvp->Value) || valp->IsNull()) - return js->WriteStr("null"); - else switch (valp->GetType()) { - case TYPE_TINY: - return js->WriteStr(valp->GetTinyValue() ? "true" : "false"); - case TYPE_STRING: - return js->Escape(valp->GetCharValue()); - default: - if (valp->IsTypeNum()) { - char buf[32]; - - return js->WriteStr(valp->GetCharString(buf)); - } // endif valp - - } // endswitch Type - -strcpy(js->g->Message, "Unrecognized value"); -return true; -} // end of SerializeValue - -/* -------------------------- Class JOUTSTR -------------------------- */ - -/***********************************************************************/ -/* JOUTSTR constructor. */ -/***********************************************************************/ -JOUTSTR::JOUTSTR(PGLOBAL g) : JOUT(g) -{ - PPOOLHEADER pph = (PPOOLHEADER)g->Sarea; - - N = 0; - Max = pph->FreeBlk; - Max = (Max > 512) ? Max - 512 : Max; - Strp = (char*)PlugSubAlloc(g, NULL, 0); // Size not know yet -} // end of JOUTSTR constructor - -/***********************************************************************/ -/* Concatenate a string to the Serialize string. */ -/***********************************************************************/ -bool JOUTSTR::WriteStr(const char *s) -{ - if (s) { - size_t len = strlen(s); - - if (N + len > Max) - return true; - - memcpy(Strp + N, s, len); - N += len; - return false; - } else - return true; - -} // end of WriteStr - -/***********************************************************************/ -/* Concatenate a character to the Serialize string. */ -/***********************************************************************/ -bool JOUTSTR::WriteChr(const char c) -{ - if (N + 1 > Max) - return true; - - Strp[N++] = c; - return false; -} // end of WriteChr - -/***********************************************************************/ -/* Escape and Concatenate a string to the Serialize string. */ -/***********************************************************************/ -bool JOUTSTR::Escape(const char *s) -{ - WriteChr('"'); - - for (unsigned int i = 0; i < strlen(s); i++) - switch (s[i]) { - case '\t': - case '\n': - case '\r': - case '\b': - case '\f': - case '"': WriteChr('\\'); - // passthru - default: - WriteChr(s[i]); - break; - } // endswitch s[i] - - WriteChr('"'); - return false; -} // end of Escape - -/* ------------------------- Class JOUTFILE -------------------------- */ - -/***********************************************************************/ -/* Write a string to the Serialize file. */ -/***********************************************************************/ -bool JOUTFILE::WriteStr(const char *s) -{ - // This is temporary - fputs(s, Stream); - return false; -} // end of WriteStr - -/***********************************************************************/ -/* Write a character to the Serialize file. */ -/***********************************************************************/ -bool JOUTFILE::WriteChr(const char c) -{ - // This is temporary - fputc(c, Stream); - return false; -} // end of WriteChr - -/***********************************************************************/ -/* Escape and Concatenate a string to the Serialize string. */ -/***********************************************************************/ -bool JOUTFILE::Escape(const char *s) -{ - // This is temporary - fputc('"', Stream); - - for (unsigned int i = 0; i < strlen(s); i++) - switch (s[i]) { - case '\t': fputs("\\t", Stream); break; - case '\n': fputs("\\n", Stream); break; - case '\r': fputs("\\r", Stream); break; - case '\b': fputs("\\b", Stream); break; - case '\f': fputs("\\f", Stream); break; - case '"': fputs("\\\"", Stream); break; - default: - fputc(s[i], Stream); - break; - } // endswitch s[i] - - fputc('"', Stream); - return false; -} // end of Escape - -/* ------------------------- Class JOUTPRT --------------------------- */ - -/***********************************************************************/ -/* Write a string to the Serialize pretty file. */ -/***********************************************************************/ -bool JOUTPRT::WriteStr(const char *s) -{ - // This is temporary - if (B) { - fputs(EL, Stream); - M--; - - for (int i = 0; i < M; i++) - fputc('\t', Stream); - - B = false; - } // endif B - - fputs(s, Stream); - return false; -} // end of WriteStr - -/***********************************************************************/ -/* Write a character to the Serialize pretty file. */ -/***********************************************************************/ -bool JOUTPRT::WriteChr(const char c) -{ - switch (c) { - case ':': - fputs(": ", Stream); - break; - case '{': - case '[': -#if 0 - if (M) - fputs(EL, Stream); - - for (int i = 0; i < M; i++) - fputc('\t', Stream); -#endif // 0 - - fputc(c, Stream); - fputs(EL, Stream); - M++; - - for (int i = 0; i < M; i++) - fputc('\t', Stream); - - break; - case '}': - case ']': - M--; - fputs(EL, Stream); - - for (int i = 0; i < M; i++) - fputc('\t', Stream); - - fputc(c, Stream); - B = true; - break; - case ',': - fputc(c, Stream); - fputs(EL, Stream); - - for (int i = 0; i < M; i++) - fputc('\t', Stream); - - B = false; - break; - default: - fputc(c, Stream); - } // endswitch c - -return false; -} // end of WriteChr - -/* -------------------------- Class JOBJECT -------------------------- */ - -/***********************************************************************/ -/* Add a new pair to an Object. */ -/***********************************************************************/ -PJPR JOBJECT::AddPair(PGLOBAL g, PSZ key) -{ - PJPR jpp = new(g) JPAIR(key); - - if (Last) - Last->Next = jpp; - else - First = jpp; - - Last = jpp; - Size++; - return jpp; -} // end of AddPair - -/***********************************************************************/ -/* Get the value corresponding to the given key. */ -/***********************************************************************/ -PJVAL JOBJECT::GetValue(const char* key) -{ - for (PJPR jp = First; jp; jp = jp->Next) - if (!strcmp(jp->Key, key)) - return jp->Val; - - return NULL; -} // end of GetValue; - -/***********************************************************************/ -/* Return the text corresponding to all keys (XML like). */ -/***********************************************************************/ -PSZ JOBJECT::GetText(PGLOBAL g) -{ - char *p, *text = (char*)PlugSubAlloc(g, NULL, 0); - bool b = true; - - if (!First) - return NULL; - else for (PJPR jp = First; jp; jp = jp->Next) { - if (!(p = jp->Val->GetString())) - p = "???"; - - if (b) { - strcpy(text, p); - b = false; - } else - strcat(strcat(text, " "), p); - - } // endfor jp - - PlugSubAlloc(g, NULL, strlen(text) + 1); - return text; -} // end of GetValue; - -/***********************************************************************/ -/* Set or add a value corresponding to the given key. */ -/***********************************************************************/ -void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PSZ key) -{ - PJPR jp; - - for (jp = First; jp; jp = jp->Next) - if (!strcmp(jp->Key, key)) { - jp->Val = jvp; - break; - } // endif key - - if (!jp) { - jp = AddPair(g, key); - jp->Val = jvp; - } // endif jp - -} // end of SetValue - -/* -------------------------- Class JARRAY --------------------------- */ - -/***********************************************************************/ -/* Make the array of values from the values list. */ -/***********************************************************************/ -void JARRAY::InitArray(PGLOBAL g) -{ - int i; - PJVAL jvp; - - for (Size = 0, jvp = First; jvp; jvp = jvp->Next) - if (!jvp->Del) - Size++; - - if (!Size) { - return; - } else if (Size > Alloc) { - // No need to realloc after deleting values - Mvals = (PJVAL*)PlugSubAlloc(g, NULL, Size * sizeof(PJVAL)); - Alloc = Size; - } // endif Size - - for (i = 0, jvp = First; jvp; jvp = jvp->Next) - if (!jvp->Del) - Mvals[i++] = jvp; - -} // end of InitArray - -/***********************************************************************/ -/* Get the Nth value of an Array. */ -/***********************************************************************/ -PJVAL JARRAY::GetValue(int i) -{ - if (Mvals && i >= 0 && i < Size) - return Mvals[i]; - else - return NULL; -} // end of GetValue - -/***********************************************************************/ -/* Add a Value to the Arrays Value list. */ -/***********************************************************************/ -PJVAL JARRAY::AddValue(PGLOBAL g, PJVAL jvp) -{ - if (!jvp) - jvp = new(g) JVALUE; - - if (Last) - Last->Next = jvp; - else - First = jvp; - - Last = jvp; - return jvp; -} // end of AddValue - -/***********************************************************************/ -/* Add a Value to the Arrays Value list. */ -/***********************************************************************/ -bool JARRAY::SetValue(PGLOBAL g, PJVAL jvp, int n) -{ - int i = 0; - PJVAL jp, *jpp = &First; - - for (i = 0, jp = First; i < n; i++, jp = *(jpp = &jp->Next)) - if (!jp) - *jpp = jp = new(g) JVALUE; - - *jpp = jvp; - jvp->Next = (jp ? jp->Next : NULL); - return false; -} // end of SetValue - -/***********************************************************************/ -/* Delete a Value from the Arrays Value list. */ -/***********************************************************************/ -bool JARRAY::DeleteValue(int n) -{ - PJVAL jvp = GetValue(n); - - if (jvp) { - jvp->Del = true; - return false; - } else - return true; - -} // end of DeleteValue - -/* -------------------------- Class JVALUE- -------------------------- */ - -/***********************************************************************/ -/* Constructor for a Value with a given string or numeric value. */ -/***********************************************************************/ -JVALUE::JVALUE(PGLOBAL g, PVAL valp) : JSON() -{ - Jsp = NULL; - Value = AllocateValue(g, valp); - Next = NULL; - Del = false; -} // end of JVALUE constructor - -/***********************************************************************/ -/* Returns the type of the Value's value. */ -/***********************************************************************/ -JTYP JVALUE::GetValType(void) -{ - if (Jsp) - return Jsp->GetType(); - else if (Value) - return (JTYP)Value->GetType(); - else - return (JTYP)TYPE_VOID; - -} // end of GetValType - -/***********************************************************************/ -/* Return the Value's Object value. */ -/***********************************************************************/ -PJOB JVALUE::GetObject(void) -{ - if (Jsp && Jsp->GetType() == TYPE_JOB) - return (PJOB)Jsp; - - return NULL; -} // end of GetObject - -/***********************************************************************/ -/* Return the Value's Array value. */ -/***********************************************************************/ -PJAR JVALUE::GetArray(void) -{ - if (Jsp && Jsp->GetType() == TYPE_JAR) - return (PJAR)Jsp; - - return NULL; -} // end of GetArray - -/***********************************************************************/ -/* Return the Value's Integer value. */ -/***********************************************************************/ -int JVALUE::GetInteger(void) -{ - return (Value) ? Value->GetIntValue() : 0; -} // end of GetInteger - -/***********************************************************************/ -/* Return the Value's Double value. */ -/***********************************************************************/ -double JVALUE::GetFloat(void) -{ - return (Value) ? Value->GetFloatValue() : 0.0; -} // end of GetFloat - -/***********************************************************************/ -/* Return the Value's String value. */ -/***********************************************************************/ -PSZ JVALUE::GetString(void) -{ - char buf[32]; - return (Value) ? Value->GetCharString(buf) : NULL; -} // end of GetString - +/*************** json CPP Declares Source Code File (.H) ***************/ +/* Name: json.cpp Version 1.0 */ +/* */ +/* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */ +/* */ +/* This file contains the JSON classes functions. */ +/***********************************************************************/ + +/***********************************************************************/ +/* Include relevant sections of the MariaDB header file. */ +/***********************************************************************/ +#include + +/***********************************************************************/ +/* Include application header files: */ +/* global.h is header containing all global declarations. */ +/* plgdbsem.h is header containing the DB application declarations. */ +/* xjson.h is header containing the JSON classes declarations. */ +/***********************************************************************/ +#include "global.h" +#include "plgdbsem.h" +#include "json.h" + +#define ARGS MY_MIN(24,len-i),s+MY_MAX(i-3,0) + +#if defined(WIN32) +#define EL "\r\n" +#else +#define EL "\n" +#endif + +/***********************************************************************/ +/* Parse a json string. */ +/***********************************************************************/ +PJSON ParseJson(PGLOBAL g, char *s, int len, int pretty, bool *comma) +{ + int i, rc; + bool b = false; + PJSON jsp = NULL; + STRG src; + + if (!s || !len) { + strcpy(g->Message, "Void JSON object"); + return NULL; + } else if (comma) + *comma = false; + + src.str = s; + src.len = len; + + // Save stack and allocation environment and prepare error return + if (g->jump_level == MAX_JUMP) { + strcpy(g->Message, MSG(TOO_MANY_JUMPS)); + return NULL; + } // endif jump_level + + if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) { + goto err; + } // endif rc + + for (i = 0; i < len; i++) + switch (s[i]) { + case '[': + if (jsp) { + strcpy(g->Message, "More than one item in file"); + goto err; + } else if (!(jsp = ParseArray(g, ++i, src))) + goto err; + + break; + case '{': + if (jsp) { + strcpy(g->Message, "More than one item in file"); + goto err; + } else if (!(jsp = ParseObject(g, ++i, src))) + goto err; + + break; + case ' ': + case '\t': + case '\n': + case '\r': + break; + case ',': + if (jsp && pretty == 1) { + if (comma) + *comma = true; + + break; + } // endif pretty + + sprintf(g->Message, "Unexpected ',' (pretty=%d)", pretty); + goto err; + case '"': + if (!(jsp = ParseValue(g, i, src))) + goto err; + + break; + case '(': + b = true; + break; + case ')': + if (b) { + b = false; + break; + } // endif b + + default: + sprintf(g->Message, "Bad '%c' character near %.*s", + s[i], ARGS); + goto err; + }; // endswitch s[i] + + if (!jsp) + sprintf(g->Message, "Invalid Json string '%.*s'", 50, s); + + g->jump_level--; + return jsp; + + err: + g->jump_level--; + return NULL; +} // end of ParseJson + +/***********************************************************************/ +/* Parse a JSON Array. */ +/***********************************************************************/ +PJAR ParseArray(PGLOBAL g, int& i, STRG& src) +{ + char *s = src.str; + int len = src.len; + int level = 0; + PJAR jarp = new(g) JARRAY; + PJVAL jvp = NULL; + + for (; i < len; i++) + switch (s[i]) { + case ',': + if (level < 2) { + sprintf(g->Message, "Unexpected ',' near %.*s",ARGS); + return NULL; + } else + level = 1; + + break; + case ']': + if (level == 1) { + sprintf(g->Message, "Unexpected ',]' near %.*s", ARGS); + return NULL; + } // endif level + + jarp->InitArray(g); + return jarp; + case ' ': + case '\t': + case '\n': + case '\r': + break; + default: + if (level == 2) { + sprintf(g->Message, "Unexpected value near %.*s", ARGS); + return NULL; + } else if ((jvp = ParseValue(g, i, src))) { + jarp->AddValue(g, jvp); + level = 2; + } else + return NULL; + + level = 2; + break; + }; // endswitch s[i] + + strcpy(g->Message, "Unexpected EOF in array"); + return NULL; +} // end of ParseArray + +/***********************************************************************/ +/* Parse a JSON Object. */ +/***********************************************************************/ +PJOB ParseObject(PGLOBAL g, int& i, STRG& src) +{ + PSZ key; + char *s = src.str; + int len = src.len; + int level = 0; + PJOB jobp = new(g) JOBJECT; + PJPR jpp = NULL; + + for (; i < len; i++) + switch (s[i]) { + case '"': + if (level < 2) { + if ((key = ParseString(g, ++i, src))) { + jpp = jobp->AddPair(g, key); + level = 1; + } else + return NULL; + + } else { + sprintf(g->Message, "misplaced string near %.*s", ARGS); + return NULL; + } // endif level + + break; + case ':': + if (level == 1) { + if (!(jpp->Val = ParseValue(g, ++i, src))) + return NULL; + + level = 2; + } else { + sprintf(g->Message, "Unexpected ':' near %.*s", ARGS); + return NULL; + } // endif level + + break; + case ',': + if (level < 2) { + sprintf(g->Message, "Unexpected ',' near %.*s", ARGS); + return NULL; + } else + level = 1; + + break; + case '}': + if (level == 1) { + sprintf(g->Message, "Unexpected '}' near %.*s", ARGS); + return NULL; + } // endif level + + return jobp; + case ' ': + case '\t': + case '\n': + case '\r': + break; + default: + sprintf(g->Message, "Unexpected character '%c' near %.*s", + s[i], ARGS); + return NULL; + }; // endswitch s[i] + + strcpy(g->Message, "Unexpected EOF in Object"); + return NULL; +} // end of ParseObject + +/***********************************************************************/ +/* Parse a JSON Value. */ +/***********************************************************************/ +PJVAL ParseValue(PGLOBAL g, int& i, STRG& src) +{ + char *strval, *s = src.str; + int n, len = src.len; + PJVAL jvp = new(g) JVALUE; + + for (; i < len; i++) + switch (s[i]) { + case ' ': + case '\t': + case '\n': + case '\r': + break; + default: + goto suite; + } // endswitch + + suite: + switch (s[i]) { + case '[': + if (!(jvp->Jsp = ParseArray(g, ++i, src))) + return NULL; + + break; + case '{': + if (!(jvp->Jsp = ParseObject(g, ++i, src))) + return NULL; + + break; + case '"': + if ((strval = ParseString(g, ++i, src))) + jvp->Value = AllocateValue(g, strval, TYPE_STRING); + else + return NULL; + + break; + case 't': + if (!strncmp(s + i, "true", 4)) { + n = 1; + jvp->Value = AllocateValue(g, &n, TYPE_TINY); + i += 3; + } else + goto err; + + break; + case 'f': + if (!strncmp(s + i, "false", 5)) { + n = 0; + jvp->Value = AllocateValue(g, &n, TYPE_TINY); + i += 4; + } else + goto err; + + break; + case 'n': + if (!strncmp(s + i, "null", 4)) + i += 3; + else + goto err; + + break; + case '-': + default: + if (s[i] == '-' || isdigit(s[i])) { + if (!(jvp->Value = ParseNumeric(g, i, src))) + goto err; + + } else + goto err; + + }; // endswitch s[i] + + jvp->Size = 1; + return jvp; + +err: + sprintf(g->Message, "Unexpected character '%c' near %.*s", + s[i], ARGS); + return NULL; +} // end of ParseValue + +/***********************************************************************/ +/* Unescape and parse a JSON string. */ +/***********************************************************************/ +char *ParseString(PGLOBAL g, int& i, STRG& src) +{ + char *s = src.str; + uchar *p; + int n = 0, len = src.len; + + // Be sure of memory availability + if (len + 1 - i > (signed)((PPOOLHEADER)g->Sarea)->FreeBlk) { + strcpy(g->Message, "ParseString: Out of memory"); + return NULL; + } // endif len + + // The size to allocate is not known yet + p = (uchar*)PlugSubAlloc(g, NULL, 0); + + for (; i < len; i++) + switch (s[i]) { + case '"': + p[n++] = 0; + PlugSubAlloc(g, NULL, n); + return (char*)p; + case '\\': + if (++i < len) { + if (s[i] == 'u') { + if (len - i > 5) { +// if (charset == utf8) { + char xs[5]; + uint hex; + + xs[0] = s[++i]; + xs[1] = s[++i]; + xs[2] = s[++i]; + xs[3] = s[++i]; + xs[4] = 0; + hex = strtoul(xs, NULL, 16); + + if (hex < 0x80) { + p[n] = (uchar)hex; + } else if (hex < 0x800) { + p[n++] = (uchar)(0xC0 | (hex >> 6)); + p[n] = (uchar)(0x80 | (hex & 0x3F)); + } else if (hex < 0x10000) { + p[n++] = (uchar)(0xE0 | (hex >> 12)); + p[n++] = (uchar)(0x80 | ((hex >> 6) & 0x3f)); + p[n] = (uchar)(0x80 | (hex & 0x3f)); + } else + p[n] = '?'; + +#if 0 + } else { + char xs[3]; + UINT hex; + + i += 2; + xs[0] = s[++i]; + xs[1] = s[++i]; + xs[2] = 0; + hex = strtoul(xs, NULL, 16); + p[n] = (char)hex; + } // endif charset +#endif // 0 + } else + goto err; + + } else switch(s[i]) { + case 't': p[n] = '\t'; break; + case 'n': p[n] = '\n'; break; + case 'r': p[n] = '\r'; break; + case 'b': p[n] = '\b'; break; + case 'f': p[n] = '\f'; break; + default: p[n] = s[i]; break; + } // endswitch + + n++; + } else + goto err; + + break; + default: + p[n++] = s[i]; + break; + }; // endswitch s[i] + + err: + strcpy(g->Message, "Unexpected EOF in String"); + return NULL; +} // end of ParseString + +/***********************************************************************/ +/* Parse a JSON numeric value. */ +/***********************************************************************/ +PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src) +{ + char *s = src.str, buf[50]; + int n = 0, len = src.len; + short nd = 0; + bool has_dot = false; + bool has_e = false; + bool found_digit = false; + PVAL valp = NULL; + + for (; i < len; i++) { + switch (s[i]) { + case '.': + if (!found_digit || has_dot || has_e) + goto err; + + has_dot = true; + break; + case 'e': + case 'E': + if (!found_digit || has_e) + goto err; + + has_e = true; + found_digit = false; + break; + case '+': + if (!has_e) + goto err; + + // passthru + case '-': + if (found_digit) + goto err; + + break; + default: + if (isdigit(s[i])) { + if (has_dot && !has_e) + nd++; // Number of decimals + + found_digit = true; + } else + goto fin; + + }; // endswitch s[i] + + buf[n++] = s[i]; + } // endfor i + + fin: + if (found_digit) { + buf[n] = 0; + + if (has_dot || has_e) { + double dv = strtod(buf, NULL); + + valp = AllocateValue(g, &dv, TYPE_DOUBLE, nd); + } else { + int iv = strtol(buf, NULL, 10); + + valp = AllocateValue(g, &iv, TYPE_INT); + } // endif has + + i--; // Unstack following character + return valp; + } else { + strcpy(g->Message, "No digit found"); + return NULL; + } // endif found_digit + + err: + strcpy(g->Message, "Unexpected EOF in number"); + return NULL; +} // end of ParseNumeric + +/***********************************************************************/ +/* Serialize a JSON tree: */ +/***********************************************************************/ +PSZ Serialize(PGLOBAL g, PJSON jsp, FILE *fs, int pretty) +{ + bool b = false, err = true; + JOUT *jp; + + g->Message[0] = 0; + + if (!jsp) { + strcpy(g->Message, "Null json tree"); + return NULL; + } else if (!fs) { + // Serialize to a string + jp = new(g) JOUTSTR(g); + b = pretty == 1; + } else if (pretty == 2) { + // Serialize to a pretty file + jp = new(g) JOUTPRT(g, fs); + } else { + // Serialize to a flat file + jp = new(g) JOUTFILE(g, fs); + b = pretty == 1; + } // endif's + + switch (jsp->GetType()) { + case TYPE_JAR: + err = SerializeArray(jp, (PJAR)jsp, b); + break; + case TYPE_JOB: + err = (b && jp->WriteChr('\t')); + err |= SerializeObject(jp, (PJOB)jsp); + break; + case TYPE_JVAL: + err = SerializeValue(jp, (PJVAL)jsp); + break; + default: + strcpy(g->Message, "Invalid json tree"); + } // endswitch Type + + if (fs) { + fputc('\n', fs); + fclose(fs); + return (err) ? g->Message : NULL; + } else if (!err) { + PSZ str = ((JOUTSTR*)jp)->Strp; + + jp->WriteChr('\0'); + PlugSubAlloc(g, NULL, ((JOUTSTR*)jp)->N); + return str; + } else { + if (!g->Message[0]) + strcpy(g->Message, "Error in Serialize"); + + return NULL; + } // endif's + +} // end of Serialize + +/***********************************************************************/ +/* Serialize a JSON Array. */ +/***********************************************************************/ +bool SerializeArray(JOUT *js, PJAR jarp, bool b) +{ + bool first = true; + + + if (js->WriteChr('[')) + return true; + else if (b && (js->WriteStr(EL) || js->WriteChr('\t'))) + return true; + + for (int i = 0; i < jarp->size(); i++) { + if (first) + first = false; + else if (js->WriteChr(',')) + return true; + else if (b && (js->WriteStr(EL) || js->WriteChr('\t'))) + return true; + + if (SerializeValue(js, jarp->GetValue(i))) + return true; + + } // endfor i + + if (b && js->WriteStr(EL)) + return true; + + return js->WriteChr(']'); +} // end of SerializeArray + +/***********************************************************************/ +/* Serialize a JSON Object. */ +/***********************************************************************/ +bool SerializeObject(JOUT *js, PJOB jobp) +{ + bool first = true; + + if (js->WriteChr('{')) + return true; + + for (PJPR pair = jobp->First; pair; pair = pair->Next) { + if (first) + first = false; + else if (js->WriteChr(',')) + return true; + + if (js->WriteChr('"') || + js->WriteStr(pair->Key) || + js->WriteChr('"') || + js->WriteChr(':') || + SerializeValue(js, pair->Val)) + return true; + + } // endfor i + + return js->WriteChr('}'); +} // end of SerializeObject + +/***********************************************************************/ +/* Serialize a JSON Value. */ +/***********************************************************************/ +bool SerializeValue(JOUT *js, PJVAL jvp) +{ + PJAR jap; + PJOB jop; + PVAL valp; + + if ((jap = jvp->GetArray())) + return SerializeArray(js, jap, false); + else if ((jop = jvp->GetObject())) + return SerializeObject(js, jop); + else if (!(valp = jvp->Value) || valp->IsNull()) + return js->WriteStr("null"); + else switch (valp->GetType()) { + case TYPE_TINY: + return js->WriteStr(valp->GetTinyValue() ? "true" : "false"); + case TYPE_STRING: + return js->Escape(valp->GetCharValue()); + default: + if (valp->IsTypeNum()) { + char buf[32]; + + return js->WriteStr(valp->GetCharString(buf)); + } // endif valp + + } // endswitch Type + +strcpy(js->g->Message, "Unrecognized value"); +return true; +} // end of SerializeValue + +/* -------------------------- Class JOUTSTR -------------------------- */ + +/***********************************************************************/ +/* JOUTSTR constructor. */ +/***********************************************************************/ +JOUTSTR::JOUTSTR(PGLOBAL g) : JOUT(g) +{ + PPOOLHEADER pph = (PPOOLHEADER)g->Sarea; + + N = 0; + Max = pph->FreeBlk; + Max = (Max > 512) ? Max - 512 : Max; + Strp = (char*)PlugSubAlloc(g, NULL, 0); // Size not know yet +} // end of JOUTSTR constructor + +/***********************************************************************/ +/* Concatenate a string to the Serialize string. */ +/***********************************************************************/ +bool JOUTSTR::WriteStr(const char *s) +{ + if (s) { + size_t len = strlen(s); + + if (N + len > Max) + return true; + + memcpy(Strp + N, s, len); + N += len; + return false; + } else + return true; + +} // end of WriteStr + +/***********************************************************************/ +/* Concatenate a character to the Serialize string. */ +/***********************************************************************/ +bool JOUTSTR::WriteChr(const char c) +{ + if (N + 1 > Max) + return true; + + Strp[N++] = c; + return false; +} // end of WriteChr + +/***********************************************************************/ +/* Escape and Concatenate a string to the Serialize string. */ +/***********************************************************************/ +bool JOUTSTR::Escape(const char *s) +{ + WriteChr('"'); + + for (unsigned int i = 0; i < strlen(s); i++) + switch (s[i]) { + case '"': + case '\\': + case '\t': + case '\n': + case '\r': + case '\b': + case '\f': WriteChr('\\'); + // passthru + default: + WriteChr(s[i]); + break; + } // endswitch s[i] + + WriteChr('"'); + return false; +} // end of Escape + +/* ------------------------- Class JOUTFILE -------------------------- */ + +/***********************************************************************/ +/* Write a string to the Serialize file. */ +/***********************************************************************/ +bool JOUTFILE::WriteStr(const char *s) +{ + // This is temporary + fputs(s, Stream); + return false; +} // end of WriteStr + +/***********************************************************************/ +/* Write a character to the Serialize file. */ +/***********************************************************************/ +bool JOUTFILE::WriteChr(const char c) +{ + // This is temporary + fputc(c, Stream); + return false; +} // end of WriteChr + +/***********************************************************************/ +/* Escape and Concatenate a string to the Serialize string. */ +/***********************************************************************/ +bool JOUTFILE::Escape(const char *s) +{ + // This is temporary + fputc('"', Stream); + + for (unsigned int i = 0; i < strlen(s); i++) + switch (s[i]) { + case '"': fputs("\\\"", Stream); break; + case '\\': fputs("\\\\", Stream); break; + case '\t': fputs("\\t", Stream); break; + case '\n': fputs("\\n", Stream); break; + case '\r': fputs("\\r", Stream); break; + case '\b': fputs("\\b", Stream); break; + case '\f': fputs("\\f", Stream); break; + default: + fputc(s[i], Stream); + break; + } // endswitch s[i] + + fputc('"', Stream); + return false; +} // end of Escape + +/* ------------------------- Class JOUTPRT --------------------------- */ + +/***********************************************************************/ +/* Write a string to the Serialize pretty file. */ +/***********************************************************************/ +bool JOUTPRT::WriteStr(const char *s) +{ + // This is temporary + if (B) { + fputs(EL, Stream); + M--; + + for (int i = 0; i < M; i++) + fputc('\t', Stream); + + B = false; + } // endif B + + fputs(s, Stream); + return false; +} // end of WriteStr + +/***********************************************************************/ +/* Write a character to the Serialize pretty file. */ +/***********************************************************************/ +bool JOUTPRT::WriteChr(const char c) +{ + switch (c) { + case ':': + fputs(": ", Stream); + break; + case '{': + case '[': +#if 0 + if (M) + fputs(EL, Stream); + + for (int i = 0; i < M; i++) + fputc('\t', Stream); +#endif // 0 + + fputc(c, Stream); + fputs(EL, Stream); + M++; + + for (int i = 0; i < M; i++) + fputc('\t', Stream); + + break; + case '}': + case ']': + M--; + fputs(EL, Stream); + + for (int i = 0; i < M; i++) + fputc('\t', Stream); + + fputc(c, Stream); + B = true; + break; + case ',': + fputc(c, Stream); + fputs(EL, Stream); + + for (int i = 0; i < M; i++) + fputc('\t', Stream); + + B = false; + break; + default: + fputc(c, Stream); + } // endswitch c + +return false; +} // end of WriteChr + +/* -------------------------- Class JOBJECT -------------------------- */ + +/***********************************************************************/ +/* Add a new pair to an Object. */ +/***********************************************************************/ +PJPR JOBJECT::AddPair(PGLOBAL g, PSZ key) +{ + PJPR jpp = new(g) JPAIR(key); + + if (Last) + Last->Next = jpp; + else + First = jpp; + + Last = jpp; + Size++; + return jpp; +} // end of AddPair + +/***********************************************************************/ +/* Get the value corresponding to the given key. */ +/***********************************************************************/ +PJVAL JOBJECT::GetValue(const char* key) +{ + for (PJPR jp = First; jp; jp = jp->Next) + if (!strcmp(jp->Key, key)) + return jp->Val; + + return NULL; +} // end of GetValue; + +/***********************************************************************/ +/* Return the text corresponding to all keys (XML like). */ +/***********************************************************************/ +PSZ JOBJECT::GetText(PGLOBAL g) +{ + char *p, *text = (char*)PlugSubAlloc(g, NULL, 0); + bool b = true; + + if (!First) + return NULL; + else for (PJPR jp = First; jp; jp = jp->Next) { + if (!(p = jp->Val->GetString())) + p = "???"; + + if (b) { + strcpy(text, p); + b = false; + } else + strcat(strcat(text, " "), p); + + } // endfor jp + + PlugSubAlloc(g, NULL, strlen(text) + 1); + return text; +} // end of GetValue; + +/***********************************************************************/ +/* Set or add a value corresponding to the given key. */ +/***********************************************************************/ +void JOBJECT::SetValue(PGLOBAL g, PJVAL jvp, PSZ key) +{ + PJPR jp; + + for (jp = First; jp; jp = jp->Next) + if (!strcmp(jp->Key, key)) { + jp->Val = jvp; + break; + } // endif key + + if (!jp) { + jp = AddPair(g, key); + jp->Val = jvp; + } // endif jp + +} // end of SetValue + +/* -------------------------- Class JARRAY --------------------------- */ + +/***********************************************************************/ +/* Make the array of values from the values list. */ +/***********************************************************************/ +void JARRAY::InitArray(PGLOBAL g) +{ + int i; + PJVAL jvp; + + for (Size = 0, jvp = First; jvp; jvp = jvp->Next) + if (!jvp->Del) + Size++; + + if (!Size) { + return; + } else if (Size > Alloc) { + // No need to realloc after deleting values + Mvals = (PJVAL*)PlugSubAlloc(g, NULL, Size * sizeof(PJVAL)); + Alloc = Size; + } // endif Size + + for (i = 0, jvp = First; jvp; jvp = jvp->Next) + if (!jvp->Del) + Mvals[i++] = jvp; + +} // end of InitArray + +/***********************************************************************/ +/* Get the Nth value of an Array. */ +/***********************************************************************/ +PJVAL JARRAY::GetValue(int i) +{ + if (Mvals && i >= 0 && i < Size) + return Mvals[i]; + else + return NULL; +} // end of GetValue + +/***********************************************************************/ +/* Add a Value to the Arrays Value list. */ +/***********************************************************************/ +PJVAL JARRAY::AddValue(PGLOBAL g, PJVAL jvp) +{ + if (!jvp) + jvp = new(g) JVALUE; + + if (Last) + Last->Next = jvp; + else + First = jvp; + + Last = jvp; + return jvp; +} // end of AddValue + +/***********************************************************************/ +/* Add a Value to the Arrays Value list. */ +/***********************************************************************/ +bool JARRAY::SetValue(PGLOBAL g, PJVAL jvp, int n) +{ + int i = 0; + PJVAL jp, *jpp = &First; + + for (i = 0, jp = First; i < n; i++, jp = *(jpp = &jp->Next)) + if (!jp) + *jpp = jp = new(g) JVALUE; + + *jpp = jvp; + jvp->Next = (jp ? jp->Next : NULL); + return false; +} // end of SetValue + +/***********************************************************************/ +/* Delete a Value from the Arrays Value list. */ +/***********************************************************************/ +bool JARRAY::DeleteValue(int n) +{ + PJVAL jvp = GetValue(n); + + if (jvp) { + jvp->Del = true; + return false; + } else + return true; + +} // end of DeleteValue + +/* -------------------------- Class JVALUE- -------------------------- */ + +/***********************************************************************/ +/* Constructor for a Value with a given string or numeric value. */ +/***********************************************************************/ +JVALUE::JVALUE(PGLOBAL g, PVAL valp) : JSON() +{ + Jsp = NULL; + Value = AllocateValue(g, valp); + Next = NULL; + Del = false; +} // end of JVALUE constructor + +/***********************************************************************/ +/* Returns the type of the Value's value. */ +/***********************************************************************/ +JTYP JVALUE::GetValType(void) +{ + if (Jsp) + return Jsp->GetType(); + else if (Value) + return (JTYP)Value->GetType(); + else + return (JTYP)TYPE_VOID; + +} // end of GetValType + +/***********************************************************************/ +/* Return the Value's Object value. */ +/***********************************************************************/ +PJOB JVALUE::GetObject(void) +{ + if (Jsp && Jsp->GetType() == TYPE_JOB) + return (PJOB)Jsp; + + return NULL; +} // end of GetObject + +/***********************************************************************/ +/* Return the Value's Array value. */ +/***********************************************************************/ +PJAR JVALUE::GetArray(void) +{ + if (Jsp && Jsp->GetType() == TYPE_JAR) + return (PJAR)Jsp; + + return NULL; +} // end of GetArray + +/***********************************************************************/ +/* Return the Value's Integer value. */ +/***********************************************************************/ +int JVALUE::GetInteger(void) +{ + return (Value) ? Value->GetIntValue() : 0; +} // end of GetInteger + +/***********************************************************************/ +/* Return the Value's Double value. */ +/***********************************************************************/ +double JVALUE::GetFloat(void) +{ + return (Value) ? Value->GetFloatValue() : 0.0; +} // end of GetFloat + +/***********************************************************************/ +/* Return the Value's String value. */ +/***********************************************************************/ +PSZ JVALUE::GetString(void) +{ + char buf[32]; + return (Value) ? Value->GetCharString(buf) : NULL; +} // end of GetString + +/***********************************************************************/ +/* Set the Value's value as the given integer. */ +/***********************************************************************/ +void JVALUE::SetInteger(PGLOBAL g, int n) +{ + Value = AllocateValue(g, &n, TYPE_INT); +} // end of AddInteger + +/***********************************************************************/ +/* Set the Value's value as the given DOUBLE. */ +/***********************************************************************/ +void JVALUE::SetFloat(PGLOBAL g, double f) +{ + Value = AllocateValue(g, &f, TYPE_DOUBLE, 6); +} // end of AddFloat + +/***********************************************************************/ +/* Set the Value's value as the given string. */ +/***********************************************************************/ +void JVALUE::SetString(PGLOBAL g, PSZ s) +{ + Value = AllocateValue(g, s, TYPE_STRING); +} // end of AddFloat + diff --git a/storage/connect/json.h b/storage/connect/json.h index 11e15c3acd4..e56803f63c9 100644 --- a/storage/connect/json.h +++ b/storage/connect/json.h @@ -18,7 +18,8 @@ enum JTYP {TYPE_STRG = 1, TYPE_BOOL = 4, TYPE_INTG = 7, TYPE_JSON = 12, - TYPE_JAR, TYPE_JOB, + TYPE_JAR, + TYPE_JOB, TYPE_JVAL}; class JOUT; @@ -156,6 +157,9 @@ class JSON : public BLOCK { virtual void SetValue(PGLOBAL g, PJVAL jvp, PSZ key) {X} virtual void SetValue(PVAL valp) {X} virtual void SetValue(PJSON jsp) {X} + virtual void SetString(PGLOBAL g, PSZ s) {X} + virtual void SetInteger(PGLOBAL g, int n) {X} + virtual void SetFloat(PGLOBAL g, double f) {X} virtual bool DeleteValue(int i) {X return true;} protected: @@ -171,6 +175,8 @@ class JOBJECT : public JSON { public: JOBJECT(void) : JSON() {First = Last = NULL;} + using JSON::GetValue; + using JSON::SetValue; virtual void Clear(void) {First = Last = NULL; Size = 0;} virtual JTYP GetType(void) {return TYPE_JOB;} virtual PJPR AddPair(PGLOBAL g, PSZ key); @@ -192,6 +198,8 @@ class JARRAY : public JSON { public: JARRAY(void) : JSON() {Alloc = 0; First = Last = NULL; Mvals = NULL;} + using JSON::GetValue; + using JSON::SetValue; virtual void Clear(void) {First = Last = NULL; Size = 0;} virtual JTYP GetType(void) {return TYPE_JAR;} virtual PJAR GetArray(void) {return this;} @@ -223,6 +231,8 @@ class JVALUE : public JSON { {Jsp = jsp; Value = NULL; Next = NULL; Del = false;} JVALUE(PGLOBAL g, PVAL valp); + using JSON::GetValue; + using JSON::SetValue; virtual void Clear(void) {Jsp = NULL; Value = NULL; Next = NULL; Del = false; Size = 0;} virtual JTYP GetType(void) {return TYPE_JVAL;} @@ -236,6 +246,9 @@ class JVALUE : public JSON { virtual PSZ GetString(void); virtual void SetValue(PVAL valp) {Value = valp;} virtual void SetValue(PJSON jsp) {Jsp = jsp;} + virtual void SetString(PGLOBAL g, PSZ s); + virtual void SetInteger(PGLOBAL g, int n); + virtual void SetFloat(PGLOBAL g, double f); protected: PJSON Jsp; // To the json value diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp new file mode 100644 index 00000000000..b100f377295 --- /dev/null +++ b/storage/connect/jsonudf.cpp @@ -0,0 +1,582 @@ +/************* jsonudf C++ Program Source Code File (.CPP) *************/ +/* PROGRAM NAME: jsonudf Version 1.0 */ +/* (C) Copyright to the author Olivier BERTRAND 2015 */ +/* This program are the JSON User Defined Functions . */ +/***********************************************************************/ + +/***********************************************************************/ +/* Include relevant sections of the MariaDB header file. */ +/***********************************************************************/ +#include +#include +#include +#include + +#include "global.h" +#include "plgdbsem.h" +#include "json.h" + +#define MEMFIX 512 + +uint GetJsonGrpSize(void); + +extern "C" { +DllExport my_bool Json_Value_init(UDF_INIT*, UDF_ARGS*, char*); +DllExport char *Json_Value(UDF_INIT*, UDF_ARGS*, char*, + unsigned long*, char *, char *); +DllExport void Json_Value_deinit(UDF_INIT*); +DllExport my_bool Json_Array_init(UDF_INIT*, UDF_ARGS*, char*); +DllExport char *Json_Array(UDF_INIT*, UDF_ARGS*, char*, + unsigned long*, char *, char *); +DllExport void Json_Array_deinit(UDF_INIT*); +DllExport my_bool Json_Array_Add_init(UDF_INIT*, UDF_ARGS*, char*); +DllExport char *Json_Array_Add(UDF_INIT*, UDF_ARGS*, char*, + unsigned long*, char *, char *); +DllExport void Json_Array_Add_deinit(UDF_INIT*); +DllExport my_bool Json_Object_init(UDF_INIT*, UDF_ARGS*, char*); +DllExport char *Json_Object(UDF_INIT*, UDF_ARGS*, char*, + unsigned long*, char *, char *); +DllExport void Json_Object_deinit(UDF_INIT*); +DllExport my_bool Json_Array_Grp_init(UDF_INIT*, UDF_ARGS*, char*); +DllExport void Json_Array_Grp_add(UDF_INIT *, UDF_ARGS *, char *, char *); +DllExport char *Json_Array_Grp(UDF_INIT*, UDF_ARGS*, char*, + unsigned long*, char *, char *); +DllExport void Json_Array_Grp_clear(UDF_INIT *, char *, char *); +DllExport void Json_Array_Grp_deinit(UDF_INIT*); +DllExport my_bool Json_Object_Grp_init(UDF_INIT*, UDF_ARGS*, char*); +DllExport void Json_Object_Grp_add(UDF_INIT *, UDF_ARGS *, char *, char *); +DllExport char *Json_Object_Grp(UDF_INIT*, UDF_ARGS*, char*, + unsigned long*, char *, char *); +DllExport void Json_Object_Grp_clear(UDF_INIT *, char *, char *); +DllExport void Json_Object_Grp_deinit(UDF_INIT*); +} // extern "C" + +/***********************************************************************/ +/* Allocate and initialise the memory area. */ +/***********************************************************************/ +static my_bool JsonInit(UDF_INIT *initid, char *message, + unsigned long reslen, unsigned long memlen) +{ + PGLOBAL g = PlugInit(NULL, memlen); + + if (!g) { + strcpy(message, "Allocation error"); + return true; + } else if (g->Sarea_Size == 0) { + strcpy(message, g->Message); + PlugExit(g); + return true; + } else + initid->ptr = (char*)g; + + initid->maybe_null = false; + initid->max_length = reslen; + return false; +} // end of Json_Object_init + +/***********************************************************************/ +/* Returns true if the argument is a JSON string. */ +/***********************************************************************/ +static my_bool IsJson(UDF_ARGS *args, int i) +{ + return (args->arg_type[i] == STRING_RESULT && + !strnicmp(args->attributes[i], "Json_", 5)); +} // end of IsJson + +/***********************************************************************/ +/* Calculate the reslen and memlen needed by a function. */ +/***********************************************************************/ +static my_bool CalcLen(UDF_ARGS *args, my_bool obj, + unsigned long& reslen, unsigned long& memlen) +{ + unsigned long i, k; + reslen = args->arg_count + 2; + + // Calculate the result max length + for (i = 0; i < args->arg_count; i++) { + if (obj) { + if (!(k = args->attribute_lengths[i])) + k = strlen(args->attributes[i]); + + reslen += (k + 3); // For quotes and : + } // endif obj + + switch (args->arg_type[i]) { + case STRING_RESULT: + if (IsJson(args, i)) + reslen += args->lengths[i]; + else + reslen += (args->lengths[i] + 1) * 2; // Pessimistic ! + + break; + case INT_RESULT: + reslen += 20; + break; + case REAL_RESULT: + reslen += 31; + break; + case DECIMAL_RESULT: + reslen += (args->lengths[i] + 7); // 6 decimals + break; + case TIME_RESULT: + case ROW_RESULT: + case IMPOSSIBLE_RESULT: + default: + // What should we do here ? + break; + } // endswitch arg_type + + } // endfor i + + // Calculate the amount of memory needed + memlen = MEMFIX + sizeof(JOUTSTR) + reslen; + + for (i = 0; i < args->arg_count; i++) { + memlen += (args->lengths[i] + sizeof(JVALUE)); + + if (obj) { + if (!(k = args->attribute_lengths[i])) + k = strlen(args->attributes[i]); + + memlen += (k + sizeof(JOBJECT) + sizeof(JPAIR)); + } else + memlen += sizeof(JARRAY); + + switch (args->arg_type[i]) { + case STRING_RESULT: + if (IsJson(args, i)) + memlen += args->lengths[i] * 5; // Estimate parse memory + + memlen += sizeof(TYPVAL); + break; + case INT_RESULT: + memlen += sizeof(TYPVAL); + break; + case REAL_RESULT: + case DECIMAL_RESULT: + memlen += sizeof(TYPVAL); + break; + case TIME_RESULT: + case ROW_RESULT: + case IMPOSSIBLE_RESULT: + default: + // What should we do here ? + break; + } // endswitch arg_type + + } // endfor i + + return false; +} // end of CalcLen + +/***********************************************************************/ +/* Make a zero terminated string from the passed argument. */ +/***********************************************************************/ +static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i) +{ + if (args->args[i]) { + int n = args->lengths[i]; + PSZ s = (PSZ)PlugSubAlloc(g, NULL, n + 1); + + memcpy(s, args->args[i], n); + s[n] = 0; + return s; + } else + return NULL; + +} // end of MakePSZ + +/***********************************************************************/ +/* Make a valid key from the passed argument. */ +/***********************************************************************/ +static PSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) +{ + int n = args->attribute_lengths[i]; + bool b; // true if attribute is zero terminated + PSZ p, s = args->attributes[i]; + + if (s && *s && (n || *s == '\'')) { + if ((b = (!n || !s[n]))) + n = strlen(s); + + if (n > 5 && IsJson(args, i)) { + s += 5; + n -= 5; + } else if (*s == '\'' && s[n-1] == '\'') { + s++; + n -= 2; + b = false; + } // endif *s + + if (n < 1) + return "Key"; + + if (!b) { + p = (PSZ)PlugSubAlloc(g, NULL, n + 1); + memcpy(p, s, n); + p[n] = 0; + s = p; + } // endif b + + } // endif s + + return s; +} // end of MakeKey + +/***********************************************************************/ +/* Make a JSON value from the passed argument. */ +/***********************************************************************/ +static PJVAL MakeValue(PGLOBAL g, UDF_ARGS *args, int i) +{ + char *sap = args->args[i]; + PJSON jsp; + PJVAL jvp = new(g) JVALUE; + + if (sap) switch (args->arg_type[i]) { + case STRING_RESULT: + if (args->lengths[i]) { + if (IsJson(args, i)) { + if (!(jsp = ParseJson(g, sap, args->lengths[i], 0))) + push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, + g->Message); + + if (jsp && jsp->GetType() == TYPE_JVAL) + jvp = (PJVAL)jsp; + else + jvp->SetValue(jsp); + + } else + jvp->SetString(g, MakePSZ(g, args, i)); + + } // endif str + + break; + case INT_RESULT: + jvp->SetInteger(g, *(int*)sap); + break; + case REAL_RESULT: + jvp->SetFloat(g, *(double*)sap); + break; + case DECIMAL_RESULT: + jvp->SetFloat(g, atof(MakePSZ(g, args, i))); + break; + case TIME_RESULT: + case ROW_RESULT: + case IMPOSSIBLE_RESULT: + default: + break; + } // endswitch arg_type + + return jvp; +} // end of MakeValue + +/***********************************************************************/ +/* Make a Json value containing the parameter. */ +/***********************************************************************/ +my_bool Json_Value_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen; + + if (args->arg_count > 1) { + strcpy(message, "Json_Value cannot accept more than 1 argument"); + return true; + } else + CalcLen(args, false, reslen, memlen); + + return JsonInit(initid, message, reslen, memlen); +} // end of Json_Value_init + +char *Json_Value(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str; + PJVAL jvp; + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + jvp = MakeValue(g, args, 0); + + if (!(str = Serialize(g, jvp, NULL, 0))) + str = strcpy(result, g->Message); + + *res_length = strlen(str); + return str; +} // end of Json_Value + +void Json_Value_deinit(UDF_INIT* initid) +{ + PlugExit((PGLOBAL)initid->ptr); +} // end of Json_Value_deinit + +/***********************************************************************/ +/* Make a Json array containing all the parameters. */ +/***********************************************************************/ +my_bool Json_Array_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen; + + CalcLen(args, false, reslen, memlen); + return JsonInit(initid, message, reslen, memlen); +} // end of Json_Array_init + +char *Json_Array(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str; + uint i; + PJAR arp; + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + arp = new(g) JARRAY; + + for (i = 0; i < args->arg_count; i++) + arp->AddValue(g, MakeValue(g, args, i)); + + arp->InitArray(g); + + if (!(str = Serialize(g, arp, NULL, 0))) + str = strcpy(result, g->Message); + + *res_length = strlen(str); + return str; +} // end of Json_Array + +void Json_Array_deinit(UDF_INIT* initid) +{ + PlugExit((PGLOBAL)initid->ptr); +} // end of Json_Array_deinit + +/***********************************************************************/ +/* Add values to a Json array. */ +/***********************************************************************/ +my_bool Json_Array_Add_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen; + + if (args->arg_count < 2) { + strcpy(message, "Json_Value_Add must have at least 2 arguments"); + return true; + } else if (!IsJson(args, 0)) { + strcpy(message, "Json_Value_Add first argument must be a json array"); + return true; + } else + CalcLen(args, false, reslen, memlen); + + return JsonInit(initid, message, reslen, memlen); +} // end of Json_Array_Add_init + +char *Json_Array_Add(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str; + PJVAL jvp; + PJAR arp; + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + jvp = MakeValue(g, args, 0); + + if (jvp->GetValType() != TYPE_JAR) { + arp = new(g) JARRAY; + arp->AddValue(g, jvp); + } else + arp = jvp->GetArray(); + + for (uint i = 1; i < args->arg_count; i++) + arp->AddValue(g, MakeValue(g, args, i)); + + arp->InitArray(g); + + if (!(str = Serialize(g, arp, NULL, 0))) + str = strcpy(result, g->Message); + + *res_length = strlen(str); + return str; +} // end of Json_Array_Add + +void Json_Array_Add_deinit(UDF_INIT* initid) +{ + PlugExit((PGLOBAL)initid->ptr); +} // end of Json_Array_Add_deinit + +/***********************************************************************/ +/* Make a Json Oject containing all the parameters. */ +/***********************************************************************/ +my_bool Json_Object_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen; + + CalcLen(args, true, reslen, memlen); + return JsonInit(initid, message, reslen, memlen); +} // end of Json_Object_init + +char *Json_Object(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str; + uint i; + PJOB objp; + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + objp = new(g) JOBJECT; + + for (i = 0; i < args->arg_count; i++) + objp->SetValue(g, MakeValue(g, args, i), MakeKey(g, args, i)); + + if (!(str = Serialize(g, objp, NULL, 0))) + str = strcpy(result, g->Message); + + *res_length = strlen(str); + return str; +} // end of Json_Object + +void Json_Object_deinit(UDF_INIT* initid) +{ + PlugExit((PGLOBAL)initid->ptr); +} // end of Json_Object_deinit + +/***********************************************************************/ +/* Make a Json array from values comming from rows. */ +/***********************************************************************/ +my_bool Json_Array_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen, n = GetJsonGrpSize(); + + if (args->arg_count != 1) { + strcpy(message, "Json_Array_Grp can only accept 1 argument"); + return true; + } else + CalcLen(args, false, reslen, memlen); + + reslen *= n; + memlen += ((memlen - MEMFIX) * (n - 1)); + + if (JsonInit(initid, message, reslen, memlen)) + return true; + + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + g->Activityp = (PACTIVITY)new(g) JARRAY; + g->N = (int)n; + return false; +} // end of Json_Array_Grp_init + +void Json_Array_Grp_add(UDF_INIT *initid, UDF_ARGS *args, + char *is_null, char *error) +{ + PGLOBAL g = (PGLOBAL)initid->ptr; + PJAR arp = (PJAR)g->Activityp; + + if (g->N-- > 0) + arp->AddValue(g, MakeValue(g, args, 0)); + +} // end of Json_Array_Grp_add + +char *Json_Array_Grp(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str; + PGLOBAL g = (PGLOBAL)initid->ptr; + PJAR arp = (PJAR)g->Activityp; + + if (g->N < 0) + push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, + "Result truncated to json_grp_size values"); + + arp->InitArray(g); + + if (!(str = Serialize(g, arp, NULL, 0))) + str = strcpy(result, g->Message); + + *res_length = strlen(str); + return str; +} // end of Json_Array_Grp + +void Json_Array_Grp_clear(UDF_INIT *initid, char *is_null, char *error) +{ + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + g->Activityp = (PACTIVITY)new(g) JARRAY; + g->N = GetJsonGrpSize(); +} // end of Json_Array_Grp_clear + +void Json_Array_Grp_deinit(UDF_INIT* initid) +{ + PlugExit((PGLOBAL)initid->ptr); +} // end of Json_Array_Grp_deinit + +/***********************************************************************/ +/* Make a Json object from values comming from rows. */ +/***********************************************************************/ +my_bool Json_Object_Grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen, n = GetJsonGrpSize(); + + if (args->arg_count != 2) { + strcpy(message, "Json_Array_Grp can only accept 2 argument"); + return true; + } else + CalcLen(args, true, reslen, memlen); + + reslen *= n; + memlen += ((memlen - MEMFIX) * (n - 1)); + + if (JsonInit(initid, message, reslen, memlen)) + return true; + + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + g->Activityp = (PACTIVITY)new(g) JOBJECT; + g->N = (int)n; + return false; +} // end of Json_Object_Grp_init + +void Json_Object_Grp_add(UDF_INIT *initid, UDF_ARGS *args, + char *is_null, char *error) +{ + PGLOBAL g = (PGLOBAL)initid->ptr; + PJOB objp = (PJOB)g->Activityp; + + if (g->N-- > 0) + objp->SetValue(g, MakeValue(g, args, 0), MakePSZ(g, args, 1)); + +} // end of Json_Object_Grp_add + +char *Json_Object_Grp(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *error) +{ + char *str; + PGLOBAL g = (PGLOBAL)initid->ptr; + PJOB objp = (PJOB)g->Activityp; + + if (g->N < 0) + push_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, 0, + "Result truncated to json_grp_size values"); + + if (!(str = Serialize(g, objp, NULL, 0))) + str = strcpy(result, g->Message); + + *res_length = strlen(str); + return str; +} // end of Json_Object_Grp + +void Json_Object_Grp_clear(UDF_INIT *initid, char *is_null, char *error) +{ + PGLOBAL g = (PGLOBAL)initid->ptr; + + PlugSubSet(g, g->Sarea, g->Sarea_Size); + g->Activityp = (PACTIVITY)new(g) JOBJECT; + g->N = GetJsonGrpSize(); +} // end of Json_Object_Grp_clear + +void Json_Object_Grp_deinit(UDF_INIT* initid) +{ + PlugExit((PGLOBAL)initid->ptr); +} // end of Json_Object_Grp_deinit + + diff --git a/storage/connect/myconn.cpp b/storage/connect/myconn.cpp index 2f3d75b52fa..47d781d9ff6 100644 --- a/storage/connect/myconn.cpp +++ b/storage/connect/myconn.cpp @@ -51,7 +51,8 @@ #define DLL_EXPORT // Items are exported from this DLL #include "myconn.h" -extern "C" int zconv; +//extern "C" int zconv; +int GetConvSize(void); extern MYSQL_PLUGIN_IMPORT uint mysqld_port; extern MYSQL_PLUGIN_IMPORT char *mysqld_unix_port; @@ -265,7 +266,7 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db, return NULL; } else if (type == TYPE_STRING) { if (v == 'X') { - len = zconv; + len = GetConvSize(); sprintf(g->Message, "Column %s converted to varchar(%d)", colname, len); PushWarning(g, thd); diff --git a/storage/connect/mysql-test/connect/r/json.result b/storage/connect/mysql-test/connect/r/json.result index 094bb669d18..e832685c855 100644 --- a/storage/connect/mysql-test/connect/r/json.result +++ b/storage/connect/mysql-test/connect/r/json.result @@ -89,8 +89,8 @@ ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher L UPDATE t1 SET AuthorFN = 'Philippe' WHERE AuthorLN = 'Knab'; SELECT * FROM t1 WHERE ISBN = '9782212090819'; ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher Location Year -9782212090819 fr applications Jean-Christophe Bernadac Construire une application XML Eyrolles Paris 1999 -9782212090819 fr applications Philippe Knab Construire une application XML Eyrolles Paris 1999 +9782212090819 fr applications Philippe Bernadac Construire une application XML Eyrolles Paris 1999 +9782212090819 fr applications François Knab Construire une application XML Eyrolles Paris 1999 # # To add an author a new table must be created # @@ -104,8 +104,8 @@ William J. Pardi INSERT INTO t2 VALUES('Charles','Dickens'); SELECT * FROM t1; ISBN Language Subject AuthorFN AuthorLN Title Translation Translator Publisher Location Year -9782212090819 fr applications Jean-Christophe Bernadac Construire une application XML Eyrolles Paris 1999 -9782212090819 fr applications Philippe Knab Construire une application XML Eyrolles Paris 1999 +9782212090819 fr applications Philippe Bernadac Construire une application XML Eyrolles Paris 1999 +9782212090819 fr applications François Knab Construire une application XML Eyrolles Paris 1999 9782840825685 fr applications William J. Pardi XML en Action adapté de l'anglais par James Guerin Microsoft Press Paris 1999 9782840825685 fr applications Charles Dickens XML en Action adapté de l'anglais par James Guerin Microsoft Press Paris 1999 DROP TABLE t1; @@ -127,11 +127,11 @@ line "SUBJECT": "applications", "AUTHOR": [ { - "FIRSTNAME": "Jean-Christophe", + "FIRSTNAME": "Philippe", "LASTNAME": "Bernadac" }, { - "FIRSTNAME": "Philippe", + "FIRSTNAME": "François", "LASTNAME": "Knab" } ], @@ -192,7 +192,7 @@ Janet 4 Car 17.00 Janet 5 Beer+Car+Beer+Food 57.00 DROP TABLE t1; # -# Cannot be fully expanded +# Now it can be fully expanded # CREATE TABLE t1 ( WHO CHAR(12), @@ -201,7 +201,31 @@ WHAT CHAR(32) FIELD_FORMAT='WEEK:[X]:EXPENSE:[X]:WHAT', AMOUNT DOUBLE(8,2) FIELD_FORMAT='WEEK:[X]:EXPENSE:[X]:AMOUNT') ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='expense.jsn'; SELECT * FROM t1; -ERROR HY000: Got error 174 'Cannot expand more than one array' from CONNECT +WHO WEEK WHAT AMOUNT +Joe 3 Beer 18.00 +Joe 3 Food 12.00 +Joe 3 Food 19.00 +Joe 3 Car 20.00 +Joe 4 Beer 19.00 +Joe 4 Beer 16.00 +Joe 4 Food 17.00 +Joe 4 Food 17.00 +Joe 4 Beer 14.00 +Joe 5 Beer 14.00 +Joe 5 Food 12.00 +Beth 3 Beer 16.00 +Beth 4 Food 17.00 +Beth 4 Beer 15.00 +Beth 5 Food 12.00 +Beth 5 Beer 20.00 +Janet 3 Car 19.00 +Janet 3 Food 18.00 +Janet 3 Beer 18.00 +Janet 4 Car 17.00 +Janet 5 Beer 14.00 +Janet 5 Car 12.00 +Janet 5 Beer 19.00 +Janet 5 Food 12.00 DROP TABLE t1; # # Expand expense in 3 one week tables diff --git a/storage/connect/mysql-test/connect/t/json.test b/storage/connect/mysql-test/connect/t/json.test index a7e630ed0cf..91cb6308557 100644 --- a/storage/connect/mysql-test/connect/t/json.test +++ b/storage/connect/mysql-test/connect/t/json.test @@ -128,7 +128,7 @@ SELECT * FROM t1; DROP TABLE t1; --echo # ---echo # Cannot be fully expanded +--echo # Now it can be fully expanded --echo # CREATE TABLE t1 ( WHO CHAR(12), @@ -136,7 +136,7 @@ WEEK INT(2) FIELD_FORMAT='WEEK:[X]:NUMBER', WHAT CHAR(32) FIELD_FORMAT='WEEK:[X]:EXPENSE:[X]:WHAT', AMOUNT DOUBLE(8,2) FIELD_FORMAT='WEEK:[X]:EXPENSE:[X]:AMOUNT') ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='expense.jsn'; ---error ER_GET_ERRMSG +#--error ER_GET_ERRMSG SELECT * FROM t1; DROP TABLE t1; diff --git a/storage/connect/myutil.cpp b/storage/connect/myutil.cpp index 0d9a1e2fe16..fe504bbe422 100644 --- a/storage/connect/myutil.cpp +++ b/storage/connect/myutil.cpp @@ -26,14 +26,16 @@ #include "myutil.h" #define DLL_EXPORT // Items are exported from this DLL -extern "C" int xconv; +//extern "C" int xconv; +TYPCONV GetTypeConv(void); /************************************************************************/ /* Convert from MySQL type name to PlugDB type number */ /************************************************************************/ int MYSQLtoPLG(char *typname, char *var) { - int type; + int type; + TYPCONV xconv = GetTypeConv(); if (!stricmp(typname, "int") || !stricmp(typname, "mediumint") || !stricmp(typname, "integer")) @@ -57,13 +59,13 @@ int MYSQLtoPLG(char *typname, char *var) type = TYPE_TINY; else if (!stricmp(typname, "text") && var) { switch (xconv) { - case 1: + case TPC_YES: type = TYPE_STRING; *var = 'X'; break; - case 2: + case TPC_SKIP: *var = 'K'; - default: + default: // TPC_NO type = TYPE_ERROR; } // endswitch xconv @@ -88,7 +90,7 @@ int MYSQLtoPLG(char *typname, char *var) } else if (type == TYPE_STRING && !stricmp(typname, "varchar")) // This is to make the difference between CHAR and VARCHAR *var = 'V'; - else if (type == TYPE_ERROR && xconv == 2) + else if (type == TYPE_ERROR && xconv == TPC_SKIP) *var = 'K'; else *var = 0; @@ -174,7 +176,7 @@ const char *PLGtoMYSQLtype(int type, bool dbf, char v) /************************************************************************/ int MYSQLtoPLG(int mytype, char *var) { - int type; + int type, xconv = GetTypeConv(); switch (mytype) { case MYSQL_TYPE_SHORT: @@ -221,7 +223,7 @@ int MYSQLtoPLG(int mytype, char *var) case MYSQL_TYPE_LONG_BLOB: if (var) { switch (xconv) { - case 1: + case TPC_YES: if (*var != 'B') { // This is a TEXT column type = TYPE_STRING; @@ -230,9 +232,9 @@ int MYSQLtoPLG(int mytype, char *var) type = TYPE_ERROR; break; - case 2: + case TPC_SKIP: *var = 'K'; // Skip - default: + default: // TPC_NO type = TYPE_ERROR; } // endswitch xconv diff --git a/storage/connect/odbccat.h b/storage/connect/odbccat.h index 8642d915211..1b5febadd3a 100644 --- a/storage/connect/odbccat.h +++ b/storage/connect/odbccat.h @@ -2,6 +2,14 @@ #define DEFAULT_LOGIN_TIMEOUT -1 // means do not set #define DEFAULT_QUERY_TIMEOUT -1 // means do not set +typedef struct odbc_parms { + char *User; // User connect info + char *Pwd; // Password connect info + int Cto; // Connect timeout + int Qto; // Query timeout + bool UseCnc; // Use SQLConnect (!SQLDriverConnect) + } ODBCPARM, *POPARM; + /***********************************************************************/ /* ODBC catalog function prototypes. */ /***********************************************************************/ @@ -10,8 +18,8 @@ char *ODBCCheckConnection(PGLOBAL g, char *dsn, int cop); #endif // PROMPT_OK PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info); PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, - char *colpat, int maxres, int cto, int qto, bool info); -PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, int cto, int qto); + char *colpat, int maxres, bool info, POPARM sop); +PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop); PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, - int maxres, int cto, int qto, bool info); + int maxres, bool info, POPARM sop); PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info); diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index 3e616ec8f04..fec14820ef6 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -37,8 +37,8 @@ #include "xobject.h" //#include "kindex.h" #include "xtable.h" -#include "tabodbc.h" #include "odbccat.h" +#include "tabodbc.h" #include "plgcnx.h" // For DB types #include "resource.h" #include "valblk.h" @@ -53,6 +53,8 @@ extern "C" HINSTANCE s_hModule; // Saved module handle #endif // WIN32 +int GetConvSize(); + /***********************************************************************/ /* Some macro's (should be defined elsewhere to be more accessible) */ /***********************************************************************/ @@ -122,7 +124,7 @@ int TranslateSQLType(int stp, int prec, int& len, char& v) case SQL_LONGVARCHAR: // (-1) v = 'V'; type = TYPE_STRING; - len = MY_MIN(abs(len), 256); + len = MY_MIN(abs(len), GetConvSize()); break; case SQL_NUMERIC: // 2 case SQL_DECIMAL: // 3 @@ -291,7 +293,7 @@ static void ResetNullValues(CATPARM *cap) /* of an ODBC table that will be retrieved by GetData commands. */ /***********************************************************************/ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, - char *colpat, int maxres, int cto, int qto, bool info) + char *colpat, int maxres, bool info, POPARM sop) { int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, @@ -310,10 +312,8 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, /************************************************************************/ if (!info) { ocp = new(g) ODBConn(g, NULL); - ocp->SetLoginTimeout((DWORD)cto); - ocp->SetQueryTimeout((DWORD)qto); - if (ocp->Open(dsn, 10) < 1) // openReadOnly + noODBCdialog + if (ocp->Open(dsn, sop, 10) < 1) // openReadOnly + noODBCdialog return NULL; if (table && !strchr(table, '%')) { @@ -342,7 +342,7 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, } // endif ocp if (trace) - htrc("ODBCColumns: max=%d len=%d,%d,%d\n", + htrc("ODBCColumns: max=%d len=%d,%d,%d,%d\n", maxres, length[0], length[1], length[2], length[3]); /************************************************************************/ @@ -388,12 +388,13 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table, /* ODBCSrcCols: constructs the result blocks containing the */ /* description of all the columns of a Srcdef option. */ /**************************************************************************/ -PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, int cto, int qto) +PQRYRES ODBCSrcCols(PGLOBAL g, char *dsn, char *src, POPARM sop) { ODBConn *ocp = new(g) ODBConn(g, NULL); - ocp->SetLoginTimeout((DWORD)cto); - ocp->SetQueryTimeout((DWORD)qto); + if (ocp->Open(dsn, sop, 10) < 1) // openReadOnly + noOdbcDialog + return NULL; + return ocp->GetMetaData(g, dsn, src); } // end of ODBCSrcCols @@ -574,7 +575,7 @@ PQRYRES ODBCDataSources(PGLOBAL g, int maxres, bool info) /* an ODBC database that will be retrieved by GetData commands. */ /**************************************************************************/ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, - int maxres, int cto, int qto, bool info) + int maxres, bool info, POPARM sop) { int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING}; @@ -594,10 +595,8 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat, /* Open the connection with the ODBC data source. */ /**********************************************************************/ ocp = new(g) ODBConn(g, NULL); - ocp->SetLoginTimeout((DWORD)cto); - ocp->SetQueryTimeout((DWORD)qto); - if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly + if (ocp->Open(dsn, sop, 2) < 1) // 2 is openReadOnly return NULL; if (!maxres) @@ -925,11 +924,14 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp) m_Catver = (tdbp) ? tdbp->Catver : 0; m_Rows = 0; m_Connect = NULL; + m_User = NULL; + m_Pwd = NULL; m_Updatable = true; m_Transact = false; m_Scrollable = (tdbp) ? tdbp->Scrollable : false; m_First = true; m_Full = false; + m_UseCnc = false; m_IDQuoteChar[0] = '"'; m_IDQuoteChar[1] = 0; //*m_ErrMsg = '\0'; @@ -1061,7 +1063,7 @@ void ODBConn::OnSetOptions(HSTMT hstmt) /***********************************************************************/ /* Open: connect to a data source. */ /***********************************************************************/ -int ODBConn::Open(PSZ ConnectString, DWORD options) +int ODBConn::Open(PSZ ConnectString, POPARM sop, DWORD options) { PGLOBAL& g = m_G; //ASSERT_VALID(this); @@ -1070,6 +1072,11 @@ int ODBConn::Open(PSZ ConnectString, DWORD options) m_Updatable = !(options & openReadOnly); m_Connect = ConnectString; + m_User = sop->User; + m_Pwd = sop->Pwd; + m_LoginTimeout = sop->Cto; + m_QueryTimeout = sop->Qto; + m_UseCnc = sop->UseCnc; // Allocate the HDBC and make connection try { @@ -1078,10 +1085,14 @@ int ODBConn::Open(PSZ ConnectString, DWORD options) AllocConnect(options); /*ver = GetStringInfo(SQL_ODBC_VER);*/ - if (Connect(options)) { - strcpy(g->Message, MSG(CONNECT_CANCEL)); - return 0; - } // endif + if (!m_UseCnc) { + if (DriverConnect(options)) { + strcpy(g->Message, MSG(CONNECT_CANCEL)); + return 0; + } // endif + + } else // Connect using SQLConnect + Connect(); /*ver = GetStringInfo(SQL_DRIVER_ODBC_VER);*/ // Verify support for required functionality and cache info @@ -1163,10 +1174,27 @@ void ODBConn::AllocConnect(DWORD Options) return; } // end of AllocConnect +/***********************************************************************/ +/* Connect to data source using SQLConnect. */ +/***********************************************************************/ +void ODBConn::Connect(void) + { + SQLRETURN rc; + SQLSMALLINT ul = (m_User ? SQL_NTS : 0); + SQLSMALLINT pl = (m_Pwd ? SQL_NTS : 0); + + rc = SQLConnect(m_hdbc, (SQLCHAR*)m_Connect, SQL_NTS, + (SQLCHAR*)m_User, ul, (SQLCHAR*)m_Pwd, pl); + + if (!Check(rc)) + ThrowDBX(rc, "SQLConnect"); + + } // end of Connect + /***********************************************************************/ /* Connect to data source using SQLDriverConnect. */ /***********************************************************************/ -bool ODBConn::Connect(DWORD Options) +bool ODBConn::DriverConnect(DWORD Options) { RETCODE rc; SWORD nResult; @@ -1213,7 +1241,7 @@ bool ODBConn::Connect(DWORD Options) // All done return false; - } // end of Connect + } // end of DriverConnect void ODBConn::VerifyConnect() { @@ -1712,6 +1740,8 @@ bool ODBConn::BindParam(ODBCCOL *colp) strcpy(m_G->Message, x->GetErrorMessage(0)); colsize = colp->GetPrecision(); sqlt = GetSQLType(buftype); + dec = IsTypeChar(buftype) ? 0 : colp->GetScale(); + nul = SQL_NULLABLE_UNKNOWN; } // end try/catch buf = colp->GetBuffer(0); @@ -1865,9 +1895,6 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src) RETCODE rc; HSTMT hstmt; - if (Open(dsn, 10) < 1) // openReadOnly + noOdbcDialog - return NULL; - try { rc = SQLAllocStmt(m_hdbc, &hstmt); diff --git a/storage/connect/odbconn.h b/storage/connect/odbconn.h index dfdb9fe7f56..b7c5e0c942d 100644 --- a/storage/connect/odbconn.h +++ b/storage/connect/odbconn.h @@ -119,7 +119,7 @@ class ODBConn : public BLOCK { noOdbcDialog = 0x0008, // Don't display ODBC Connect dialog forceOdbcDialog = 0x0010}; // Always display ODBC connect dialog - int Open(PSZ ConnectString, DWORD Options = 0); + int Open(PSZ ConnectString, POPARM sop, DWORD Options = 0); int Rewind(char *sql, ODBCCOL *tocols); void Close(void); PQRYRES AllocateResult(PGLOBAL g); @@ -135,8 +135,10 @@ class ODBConn : public BLOCK { public: // Operations - void SetLoginTimeout(DWORD sec) {m_LoginTimeout = sec;} - void SetQueryTimeout(DWORD sec) {m_QueryTimeout = sec;} +//void SetLoginTimeout(DWORD sec) {m_LoginTimeout = sec;} +//void SetQueryTimeout(DWORD sec) {m_QueryTimeout = sec;} +//void SetUserName(PSZ user) {m_User = user;} +//void SetUserPwd(PSZ pwd) {m_Pwd = pwd;} int GetResultSize(char *sql, ODBCCOL *colp); int ExecDirectSQL(char *sql, ODBCCOL *tocols); int Fetch(void); @@ -155,7 +157,7 @@ class ODBConn : public BLOCK { // Implementation public: -// virtual ~ODBConn(); +//virtual ~ODBConn(); // ODBC operations protected: @@ -163,7 +165,8 @@ class ODBConn : public BLOCK { void ThrowDBX(RETCODE rc, PSZ msg, HSTMT hstmt = SQL_NULL_HSTMT); void ThrowDBX(PSZ msg); void AllocConnect(DWORD dwOptions); - bool Connect(DWORD Options); + void Connect(void); + bool DriverConnect(DWORD Options); void VerifyConnect(void); void GetConnectInfo(void); void Free(void); @@ -185,11 +188,14 @@ class ODBConn : public BLOCK { DWORD m_RowsetSize; char m_IDQuoteChar[2]; PSZ m_Connect; + PSZ m_User; + PSZ m_Pwd; int m_Catver; int m_Rows; bool m_Updatable; bool m_Transact; bool m_Scrollable; + bool m_UseCnc; bool m_First; bool m_Full; }; // end of ODBConn class definition diff --git a/storage/connect/plgdbutl.cpp b/storage/connect/plgdbutl.cpp index d8009bcc71f..d5429e8a344 100644 --- a/storage/connect/plgdbutl.cpp +++ b/storage/connect/plgdbutl.cpp @@ -311,7 +311,7 @@ PQRYRES PlgAllocResult(PGLOBAL g, int ncol, int maxres, int ids, else crp->Kdata = NULL; - if (g->Trace) + if (trace) htrc("Column(%d) %s type=%d len=%d value=%p\n", crp->Ncol, crp->Name, crp->Type, crp->Length, crp->Kdata); diff --git a/storage/connect/plugutil.c b/storage/connect/plugutil.c index c77975e5e30..18b48b8eccc 100644 --- a/storage/connect/plugutil.c +++ b/storage/connect/plugutil.c @@ -144,12 +144,12 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize) return NULL; } else { g->Sarea_Size = worksize; - g->Trace = 0; g->Createas = 0; g->Alchecked = 0; g->Mrr = 0; g->Activityp = g->ActivityStart = NULL; g->Xchk = NULL; + g->N = 0; strcpy(g->Message, ""); /*******************************************************************/ diff --git a/storage/connect/tabdos.h b/storage/connect/tabdos.h index 156d46b9791..b7150294e9b 100644 --- a/storage/connect/tabdos.h +++ b/storage/connect/tabdos.h @@ -222,6 +222,7 @@ class DllExport DOSCOL : public COLBLK { virtual PVBLK GetDval(void) {return Dval;} // Methods + using COLBLK::Print; virtual bool VarSize(void); virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); virtual void ReadColumn(PGLOBAL g); diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index a3c56965794..f99b0d2ef1d 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -1,5 +1,5 @@ /************* tabjson C++ Program Source Code File (.CPP) *************/ -/* PROGRAM NAME: tabxjson Version 1.0 */ +/* PROGRAM NAME: tabjson Version 1.0 */ /* (C) Copyright to the author Olivier BERTRAND 2014 - 2015 */ /* This program are the JSON class DB execution routines. */ /***********************************************************************/ @@ -119,12 +119,12 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp) Fpos = -1; Spos = N = 0; Limit = tdp->Limit; - Pretty = tdp->Pretty; - Strict = tdp->Strict; - NextSame = false; - Comma = false; + NextSame = 0; SameRow = 0; Xval = -1; + Pretty = tdp->Pretty; + Strict = tdp->Strict; + Comma = false; } // end of TDBJSN standard constructor TDBJSN::TDBJSN(TDBJSN *tdbp) : TDBDOS(NULL, tdbp) @@ -137,12 +137,12 @@ TDBJSN::TDBJSN(TDBJSN *tdbp) : TDBDOS(NULL, tdbp) Spos = tdbp->Spos; N = tdbp->N; Limit = tdbp->Limit; - Pretty = tdbp->Pretty; - Strict = tdbp->Strict; NextSame = tdbp->NextSame; - Comma = tdbp->Comma; SameRow = tdbp->SameRow; Xval = tdbp->Xval; + Pretty = tdbp->Pretty; + Strict = tdbp->Strict; + Comma = tdbp->Comma; } // end of TDBJSN copy constructor // Used for update @@ -221,14 +221,9 @@ bool TDBJSN::OpenDB(PGLOBAL g) /*******************************************************************/ /* Table already open replace it at its beginning. */ /*******************************************************************/ - for (PJCOL cp = (PJCOL)Columns; cp; cp = (PJCOL)cp->GetNext()) { - cp->Nx = 0; - cp->Arp = NULL; - } // endfor cp - Fpos= -1; Spos = 0; - NextSame = false; + NextSame = 0; SameRow = 0; } else { /*******************************************************************/ @@ -292,7 +287,8 @@ int TDBJSN::ReadDB(PGLOBAL g) N++; if (NextSame) { - SameRow++; + SameRow = NextSame; + NextSame = 0; return RC_OK; } else if ((rc = TDBDOS::ReadDB(g)) == RC_OK) if (!IsRead() && ((rc = ReadBuffer(g)) != RC_OK)) { @@ -333,21 +329,20 @@ int TDBJSN::ReadDB(PGLOBAL g) } // end of PrepareWriting -/* ----------------------------- JSNCOL ------------------------------- */ +/* ---------------------------- JSONCOL ------------------------------ */ /***********************************************************************/ -/* JSNCOL public constructor. */ +/* JSONCOL public constructor. */ /***********************************************************************/ JSONCOL::JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) : DOSCOL(g, cdp, tdbp, cprec, i, "DOS") { Tjp = (TDBJSN *)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp); - Arp = NULL; Jpath = cdp->GetFmt(); MulVal = NULL; Nodes = NULL; - Nod = Nx =0; - Ival = -1; + Nod = 0; + Xnod = -1; Xpd = false; Parsed = false; } // end of JSONCOL constructor @@ -359,13 +354,11 @@ JSONCOL::JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) JSONCOL::JSONCOL(JSONCOL *col1, PTDB tdbp) : DOSCOL(col1, tdbp) { Tjp = col1->Tjp; - Arp = col1->Arp; Jpath = col1->Jpath; MulVal = col1->MulVal; Nodes = col1->Nodes; Nod = col1->Nod; - Ival = col1->Ival; - Nx = col1->Nx; + Xnod = col1->Xnod; Xpd = col1->Xpd; Parsed = col1->Parsed; } // end of JSONCOL copy constructor @@ -387,17 +380,16 @@ bool JSONCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) } // end of SetBuffer /***********************************************************************/ -/* Analyse array processing options. */ +/* Check whether this object is expanded. */ /***********************************************************************/ bool JSONCOL::CheckExpand(PGLOBAL g, int i, PSZ nm, bool b) { - if (Tjp->Xcol && nm && !strcmp(nm, Tjp->Xcol) && - (Tjp->Xval < 0 || Tjp->Xval == i)) { + if ((Tjp->Xcol && nm && !strcmp(nm, Tjp->Xcol) && + (Tjp->Xval < 0 || Tjp->Xval == i)) || Xpd) { Xpd = true; // Expandable object - Nodes[i].Op = OP_XX; - Tjp->Xval = i; + Nodes[i].Op = OP_EXP; } else if (b) { - strcpy(g->Message, "Cannot expand more than one array"); + strcpy(g->Message, "Cannot expand more than one branch"); return true; } // endif Xcol @@ -434,7 +426,7 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) // Default specifications if (CheckExpand(g, i, nm, false)) return true; - else if (jnp->Op != OP_XX) + else if (jnp->Op != OP_EXP) if (!Value->IsTypeNum()) { jnp->CncVal = AllocateValue(g, (void*)", ", TYPE_STRING); jnp->Op = OP_CNC; @@ -456,13 +448,13 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) case '*': jnp->Op = OP_MULT; break; case '>': jnp->Op = OP_MAX; break; case '<': jnp->Op = OP_MIN; break; - case '#': jnp->Op = OP_NUM; break; case '!': jnp->Op = OP_SEP; break; // Average + case '#': jnp->Op = OP_NUM; break; case 'x': case 'X': // Expand this array if (!Tjp->Xcol && nm) { Xpd = true; - jnp->Op = OP_XX; + jnp->Op = OP_EXP; Tjp->Xval = i; Tjp->Xcol = nm; } else if (CheckExpand(g, i, nm, true)) @@ -490,6 +482,38 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) return true; } // endif's + // For calculated arrays, a local Value must be used + switch (jnp->Op) { + case OP_NUM: + jnp->Valp = AllocateValue(g, TYPE_INT); + break; + case OP_ADD: + case OP_MULT: + case OP_SEP: + if (!IsTypeChar(Buf_Type)) + jnp->Valp = AllocateValue(g, Buf_Type, 0, GetPrecision()); + else + jnp->Valp = AllocateValue(g, TYPE_DOUBLE); + + break; + case OP_MIN: + case OP_MAX: + jnp->Valp = AllocateValue(g, Buf_Type, Long, GetPrecision()); + break; + case OP_CNC: + if (IsTypeChar(Buf_Type)) + jnp->Valp = AllocateValue(g, TYPE_STRING, Long, GetPrecision()); + else + jnp->Valp = AllocateValue(g, TYPE_STRING, 512); + + break; + default: + break; + } // endswitch Op + + if (jnp->Valp) + MulVal = AllocateValue(g, jnp->Valp); + return false; } // end of SetArrayOptions @@ -533,6 +557,9 @@ bool JSONCOL::ParseJpath(PGLOBAL g) if (SetArrayOptions(g, p, i, Nodes[i-1].Key)) return true; + } else if (*p == '*') { + // Return JSON + Nodes[i].Op = OP_XX; } else { Nodes[i].Key = p; Nodes[i].Op = OP_EXIST; @@ -545,60 +572,262 @@ bool JSONCOL::ParseJpath(PGLOBAL g) return false; } // end of ParseJpath +/***********************************************************************/ +/* MakeJson: Serialize the json item and set value to it. */ +/***********************************************************************/ +PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp) + { + if (Value->IsTypeNum()) { + strcpy(g->Message, "Cannot make Json for a numeric column"); + Value->Reset(); + } else + Value->SetValue_psz(Serialize(g, jsp, NULL, 0)); + + return Value; + } // end of MakeJson + /***********************************************************************/ /* SetValue: Set a value from a JVALUE contains. */ /***********************************************************************/ void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n) { if (val) { - if (Nodes[n].Op == OP_NUM) - vp->SetValue(1); - else { - again: - switch (val->GetValType()) { - case TYPE_STRG: - case TYPE_INTG: - case TYPE_DBL: - vp->SetValue_pval(val->GetValue()); + switch (val->GetValType()) { + case TYPE_STRG: + case TYPE_INTG: + case TYPE_DBL: + vp->SetValue_pval(val->GetValue()); + break; + case TYPE_BOOL: + if (vp->IsTypeNum()) + vp->SetValue(val->GetInteger() ? 1 : 0); + else + vp->SetValue_psz((PSZ)(val->GetInteger() ? "true" : "false")); + + break; + case TYPE_JAR: + SetJsonValue(g, vp, val->GetArray()->GetValue(0), n); + break; + case TYPE_JOB: +// if (!vp->IsTypeNum() || !Strict) { + vp->SetValue_psz(val->GetObject()->GetText(g)); break; - case TYPE_BOOL: - if (vp->IsTypeNum()) - vp->SetValue(val->GetInteger() ? 1 : 0); - else - vp->SetValue_psz((PSZ)(val->GetInteger() ? "true" : "false")); +// } // endif Type - break; - case TYPE_JAR: - val = val->GetArray()->GetValue(0); - goto again; - case TYPE_JOB: - if (!vp->IsTypeNum()) { - vp->SetValue_psz(val->GetObject()->GetText(g)); - break; - } // endif Type - - default: - vp->Reset(); - } // endswitch Type - - } // endelse + default: + vp->Reset(); + } // endswitch Type } else vp->Reset(); } // end of SetJsonValue +/***********************************************************************/ +/* ReadColumn: */ +/***********************************************************************/ +void JSONCOL::ReadColumn(PGLOBAL g) + { + if (!Tjp->SameRow || Xnod >= Tjp->SameRow) + Value->SetValue_pval(GetColumnValue(g, Tjp->Row, 0)); + + } // end of ReadColumn + +/***********************************************************************/ +/* GetColumnValue: */ +/***********************************************************************/ +PVAL JSONCOL::GetColumnValue(PGLOBAL g, PJSON row, int i) + { + int n = Nod - 1; + bool expd = false; + PJAR arp; + PJVAL val = NULL; + + for (; i < Nod && row; i++) { + if (Nodes[i].Op == OP_NUM) { + Value->SetValue(row->GetType() == TYPE_JAR ? row->size() : 1); + return(Value); + } else if (Nodes[i].Op == OP_XX) { + return MakeJson(g, row); + } else switch (row->GetType()) { + case TYPE_JOB: + if (!Nodes[i].Key) { + // Expected Array was not there + if (i < Nod-1) + continue; + else + val = new(g) JVALUE(row); + + } else + val = ((PJOB)row)->GetValue(Nodes[i].Key); + + break; + case TYPE_JAR: + arp = (PJAR)row; + + if (!Nodes[i].Key) { + if (Nodes[i].Op != OP_NULL) { + if (Nodes[i].Rank) { + val = arp->GetValue(Nodes[i].Rank - 1); + } else if (Nodes[i].Op == OP_EXP) { + return ExpandArray(g, arp, i); + } else + return CalculateArray(g, arp, i); + + } else + val = NULL; + + } else if (i < Nod-1) { + strcpy(g->Message, "Unexpected array"); + val = NULL; // Not an expected array + } else + val = arp->GetValue(0); + + break; + case TYPE_JVAL: + val = (PJVAL)row; + break; + default: + sprintf(g->Message, "Invalid row JSON type %d", row->GetType()); + val = NULL; + } // endswitch Type + + if (i < Nod-1) + row = (val) ? val->GetJson() : NULL; + + } // endfor i + + SetJsonValue(g, Value, val, n); + return Value; + } // end of GetColumnValue + +/***********************************************************************/ +/* ExpandArray: */ +/***********************************************************************/ +PVAL JSONCOL::ExpandArray(PGLOBAL g, PJAR arp, int n) + { + int ars; + PJVAL jvp; + JVALUE jval; + + ars = MY_MIN(Tjp->Limit, arp->size()); + + if (!(jvp = arp->GetValue(Nodes[n].Nx))) { + strcpy(g->Message, "Logical error expanding array"); + longjmp(g->jumper[g->jump_level], 666); + } // endif jvp + + if (n < Nod - 1 && jvp->GetJson()) { + jval.SetValue(GetColumnValue(g, jvp->GetJson(), n + 1)); + jvp = &jval; + } // endif n + + if (n >= Tjp->NextSame) { + if (++Nodes[n].Nx == ars) { + Nodes[n].Nx = 0; + Xnod = 0; + } else + Xnod = n; + + Tjp->NextSame = Xnod; + } // endif NextSame + + SetJsonValue(g, Value, jvp, n); + return Value; + } // end of ExpandArray + +/***********************************************************************/ +/* CalculateArray: */ +/***********************************************************************/ +PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) + { + int i, ars, nv = 0, nextsame = Tjp->NextSame; + bool err; + OPVAL op = Nodes[n].Op; + PVAL val[2], vp = Nodes[n].Valp; + PJVAL jvrp, jvp; + JVALUE jval; + + vp->Reset(); + ars = MY_MIN(Tjp->Limit, arp->size()); + + for (i = 0; i < ars; i++) { + jvrp = arp->GetValue(i); + + do { + if (n < Nod - 1 && jvrp->GetJson()) { + Tjp->NextSame = nextsame; + jval.SetValue(GetColumnValue(g, jvrp->GetJson(), n + 1)); + jvp = &jval; + } else + jvp = jvrp; + + if (!nv++) { + SetJsonValue(g, vp, jvp, n); + continue; + } else + SetJsonValue(g, MulVal, jvp, n); + + if (!MulVal->IsZero()) { + switch (op) { + case OP_CNC: + if (Nodes[n].CncVal) { + val[0] = Nodes[n].CncVal; + err = vp->Compute(g, val, 1, op); + } // endif CncVal + + val[0] = MulVal; + err = vp->Compute(g, val, 1, op); + break; +// case OP_NUM: + case OP_SEP: + val[0] = Nodes[n].Valp; + val[1] = MulVal; + err = vp->Compute(g, val, 2, OP_ADD); + break; + default: + val[0] = Nodes[n].Valp; + val[1] = MulVal; + err = vp->Compute(g, val, 2, op); + } // endswitch Op + + if (err) + vp->Reset(); + + } // endif Zero + + } while (Tjp->NextSame > nextsame); + + } // endfor i + + if (op == OP_SEP) { + // Calculate average + MulVal->SetValue(nv); + val[0] = vp; + val[1] = MulVal; + + if (vp->Compute(g, val, 2, OP_DIV)) + vp->Reset(); + + } // endif Op + + Tjp->NextSame = nextsame; + return vp; + } // end of CalculateArray + /***********************************************************************/ /* GetRow: Get the object containing this column. */ /***********************************************************************/ -PJSON JSONCOL::GetRow(PGLOBAL g, int mode) +PJSON JSONCOL::GetRow(PGLOBAL g) { PJVAL val; PJAR arp; PJSON nwr, row = Tjp->Row; for (int i = 0; i < Nod-1 && row; i++) { - switch (row->GetType()) { + if (Nodes[i+1].Op == OP_XX) + break; + else switch (row->GetType()) { case TYPE_JOB: if (!Nodes[i].Key) // Expected Array was not there @@ -609,21 +838,13 @@ PJSON JSONCOL::GetRow(PGLOBAL g, int mode) case TYPE_JAR: if (!Nodes[i].Key) { if (Nodes[i].Op != OP_NULL) { - Ival = i; arp = (PJAR)row; - if (mode < 2) // First pass - Arp = arp; + if (Nodes[i].Rank) + val = arp->GetValue(Nodes[i].Rank - 1); + else + val = arp->GetValue(Nodes[i].Nx); - if (Nodes[i].Op != OP_XX) { - if (Nodes[i].Rank) - val = arp->GetValue(Nodes[i].Rank - 1); - else - val = arp->GetValue(arp == Arp ? Nx : 0); - - } else - val = arp->GetValue(Tjp->SameRow); - } else val = NULL; @@ -643,15 +864,16 @@ PJSON JSONCOL::GetRow(PGLOBAL g, int mode) if (val) { row = val->GetJson(); - } else if (mode == 1) { // mode write + } else { // Construct missing objects for (i++; row && i < Nod; i++) { - if (!Nodes[i].Key) { + if (Nodes[i].Op == OP_XX) + break; + else if (!Nodes[i].Key) // Construct intermediate array nwr = new(g) JARRAY; - } else { + else nwr = new(g) JOBJECT; - } // endif Nodes if (row->GetType() == TYPE_JOB) { ((PJOB)row)->SetValue(g, new(g) JVALUE(nwr), Nodes[i-1].Key); @@ -667,139 +889,13 @@ PJSON JSONCOL::GetRow(PGLOBAL g, int mode) } // endfor i break; - } else - row = NULL; + } // endelse } // endfor i return row; } // end of GetRow -/***********************************************************************/ -/* ReadColumn: */ -/***********************************************************************/ -void JSONCOL::ReadColumn(PGLOBAL g) - { - int mode = 0, n = Nod - 1; - PJSON row; - PJVAL val = NULL; - - evenmore: - row = GetRow(g, mode); - - more: - if (row) switch (row->GetType()) { - case TYPE_JOB: - if (Nodes[n].Key) - val = row->GetValue(Nodes[n].Key); - else - val = new(g) JVALUE(row); - - break; - case TYPE_JAR: - // Multiple column ? - if (Nodes[n].Op != OP_NULL) { - Arp = (PJAR)row; - val = Arp->GetValue(Nodes[n].Rank > 0 ? - Nodes[n].Rank - 1 : - Nodes[n].Op == OP_XX ? Tjp->SameRow : Nx); - Ival = n; - } else - val = NULL; - - break; - case TYPE_JVAL: - val = (PJVAL)row; - break; - default: - sprintf(g->Message, "Wrong return value type %d", row->GetType()); - Value->Reset(); - return; - } // endswitch Type - - if (!Nx /*|| (Xpd)*/) - SetJsonValue(g, Value, val, n); - - if (Arp) { - // Multiple column - int ars = (Nodes[Ival].Rank > 0) ? 1 : MY_MIN(Tjp->Limit, Arp->size()); - - if (Nodes[Ival].Op == OP_XX) { - if (ars > Tjp->SameRow + 1) - Tjp->NextSame = true; // More to come - else { - Tjp->NextSame = false; - Arp = NULL; - } // endelse - - } else { - if (Nx && val) { - SetJsonValue(g, MulVal, val, Ival); - - if (!MulVal->IsZero()) { - PVAL val[2]; - bool err; - - switch (Nodes[Ival].Op) { - case OP_CNC: - if (Nodes[Ival].CncVal) { - val[0] = Nodes[Ival].CncVal; - err = Value->Compute(g, val, 1, Nodes[Ival].Op); - } // endif CncVal - - val[0] = MulVal; - err = Value->Compute(g, val, 1, Nodes[Ival].Op); - break; - case OP_NUM: - case OP_SEP: - val[0] = Value; - val[1] = MulVal; - err = Value->Compute(g, val, 2, OP_ADD); - break; - default: - val[0] = Value; - val[1] = MulVal; - err = Value->Compute(g, val, 2, Nodes[Ival].Op); - } // endswitch Op - - if (err) - Value->Reset(); - - } // endif Zero - - } // endif Nx - - if (ars > ++Nx) { - if (Ival != n) { - mode = 2; - goto evenmore; - } else - goto more; - - } else { - if (Nodes[Ival].Op == OP_SEP) { - // Calculate average - PVAL val[2]; - - MulVal->SetValue(ars); - val[0] = Value; - val[1] = MulVal; - - if (Value->Compute(g, val, 2, OP_DIV)) - Value->Reset(); - - } // endif Op - - Arp = NULL; - Nx = 0; - } // endif ars - - } // endif Op - - } // endif Arp - - } // end of ReadColumn - /***********************************************************************/ /* WriteColumn: */ /***********************************************************************/ @@ -817,10 +913,11 @@ void JSONCOL::WriteColumn(PGLOBAL g) if (Value->IsNull() && Tjp->Mode == MODE_INSERT) return; + char *s; PJOB objp = NULL; PJAR arp = NULL; PJVAL jvp = NULL; - PJSON row = GetRow(g, 1); + PJSON jsp, row = GetRow(g); JTYP type = row->GetType(); switch (row->GetType()) { @@ -832,6 +929,32 @@ void JSONCOL::WriteColumn(PGLOBAL g) if (row) switch (Buf_Type) { case TYPE_STRING: + if (Nodes[Nod-1].Op == OP_XX) { + s = Value->GetCharValue(); + + if (!(jsp = ParseJson(g, s, (int)strlen(s), 0))) { + strcpy(g->Message, s); + longjmp(g->jumper[g->jump_level], 666); + } // endif jsp + + if (arp) { + if (Nod > 1 && Nodes[Nod-2].Rank) + arp->SetValue(g, new(g) JVALUE(jsp), Nodes[Nod-2].Rank-1); + else + arp->AddValue(g, new(g) JVALUE(jsp)); + + arp->InitArray(g); + } else if (objp) { + if (Nod > 1 && Nodes[Nod-2].Key) + objp->SetValue(g, new(g) JVALUE(jsp), Nodes[Nod-2].Key); + + } else if (jvp) + jvp->SetValue(jsp); + + break; + } // endif Op + + // Passthru case TYPE_DATE: case TYPE_INT: case TYPE_DOUBLE: @@ -1175,11 +1298,6 @@ bool TDBJSON::OpenDB(PGLOBAL g) /*******************************************************************/ /* Table already open replace it at its beginning. */ /*******************************************************************/ - for (PJCOL cp = (PJCOL)Columns; cp; cp = (PJCOL)cp->GetNext()) { - cp->Nx = 0; - cp->Arp = NULL; - } // endfor cp - Fpos= -1; Spos = 0; NextSame = false; @@ -1217,7 +1335,8 @@ int TDBJSON::ReadDB(PGLOBAL g) N++; if (NextSame) { - SameRow++; + SameRow = NextSame; + NextSame = false; rc = RC_OK; } else if (++Fpos < (signed)Doc->size()) { Row = Doc->GetValue(Fpos); @@ -1257,9 +1376,10 @@ int TDBJSON::WriteDB(PGLOBAL g) return RC_FX; } else { // if (Jmode == MODE_VALUE) - if (Mode == MODE_INSERT) + if (Mode == MODE_INSERT) { Doc->AddValue(g, (PJVAL)Row); - else if (Doc->SetValue(g, (PJVAL)Row, Fpos)) + Row = new(g) JVALUE; + } else if (Doc->SetValue(g, (PJVAL)Row, Fpos)) return RC_FX; } // endif Jmode diff --git a/storage/connect/tabjson.h b/storage/connect/tabjson.h index 68f79a1526a..f46a59c5498 100644 --- a/storage/connect/tabjson.h +++ b/storage/connect/tabjson.h @@ -16,8 +16,6 @@ typedef class JSONDEF *PJDEF; typedef class TDBJSON *PJTDB; typedef class JSONCOL *PJCOL; -class TDBJSN; - /***********************************************************************/ /* The JSON tree node. Can be an Object or an Array. */ /***********************************************************************/ @@ -25,7 +23,9 @@ typedef struct _jnode { PSZ Key; // The key used for object OPVAL Op; // Operator used for this node PVAL CncVal; // To cont value used for OP_CNC + PVAL Valp; // The internal array VALUE int Rank; // The rank in array + int Nx; // Same row number } JNODE, *PJNODE; /***********************************************************************/ @@ -77,7 +77,7 @@ class TDBJSN : public TDBDOS { virtual PTDB CopyOne(PTABS t); virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL colp); - virtual int RowNumber(PGLOBAL g, BOOL b = FALSE) + virtual int RowNumber(PGLOBAL g, bool b = FALSE) {return (b) ? N : Fpos + 1;} // Database routines @@ -98,11 +98,11 @@ class TDBJSN : public TDBDOS { int N; // The current Rownum int Limit; // Limit of multiple values int Pretty; // Depends on file structure - bool Strict; // Strict syntax checking - bool NextSame; // Same next row - bool Comma; // Row has final comma + int NextSame; // Same next row int SameRow; // Same row nb int Xval; // Index of expandable array + bool Strict; // Strict syntax checking + bool Comma; // Row has final comma }; // end of class TDBJSN /* -------------------------- JSONCOL class -------------------------- */ @@ -130,8 +130,12 @@ class JSONCOL : public DOSCOL { protected: bool CheckExpand(PGLOBAL g, int i, PSZ nm, bool b); bool SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm); - PJSON GetRow(PGLOBAL g, int mode); + PVAL GetColumnValue(PGLOBAL g, PJSON row, int i); + PVAL ExpandArray(PGLOBAL g, PJAR arp, int n); + PVAL CalculateArray(PGLOBAL g, PJAR arp, int n); + PVAL MakeJson(PGLOBAL g, PJSON jsp); void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n); + PJSON GetRow(PGLOBAL g); // Default constructor not to be used JSONCOL(void) {} @@ -139,12 +143,10 @@ class JSONCOL : public DOSCOL { // Members TDBJSN *Tjp; // To the JSN table block PVAL MulVal; // To value used by multiple column - PJAR Arp; // The intermediate array char *Jpath; // The json path - JNODE *Nodes ; // The intermediate objects + JNODE *Nodes; // The intermediate objects int Nod; // The number of intermediate objects - int Ival; // Index of multiple values - int Nx; // The last read sub-row + int Xnod; // Index of multiple values bool Xpd; // True for expandable column bool Parsed; // True when parsed }; // end of class JSONCOL diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index 54627ba43fd..33a4dd67d38 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -1141,19 +1141,16 @@ int TDBMYSQL::WriteDB(PGLOBAL g) int rc; uint len = Query->GetLength(); char buf[64]; - bool b, oom = false; + bool oom = false; // Make the Insert command value list for (PCOL colp = Columns; colp; colp = colp->GetNext()) { if (!colp->GetValue()->IsNull()) { - if ((b = colp->GetResultType() == TYPE_STRING || - colp->GetResultType() == TYPE_DATE)) - oom |= Query->Append('\''); - - oom |= Query->Append(colp->GetValue()->GetCharString(buf)); - - if (b) - oom |= Query->Append('\''); + if (colp->GetResultType() == TYPE_STRING || + colp->GetResultType() == TYPE_DATE) + oom |= Query->Append_quoted(colp->GetValue()->GetCharString(buf)); + else + oom |= Query->Append(colp->GetValue()->GetCharString(buf)); } else oom |= Query->Append("NULL"); diff --git a/storage/connect/taboccur.cpp b/storage/connect/taboccur.cpp index 86f0bd20d47..f34d5f9bb11 100644 --- a/storage/connect/taboccur.cpp +++ b/storage/connect/taboccur.cpp @@ -355,7 +355,7 @@ bool TDBOCCUR::MakeColumnList(PGLOBAL g) for (colp = Columns; colp; colp = colp->GetNext()) if (colp->GetAmType() == TYPE_AM_PRX) - if (((PPRXCOL)colp)->Init(g)) + if (((PPRXCOL)colp)->Init(g, NULL)) return true; Col = (PCOL*)PlugSubAlloc(g, NULL, Mult * sizeof(PCOL)); diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index 2b771bcbead..bf76a124b70 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -66,8 +66,8 @@ #include "plgdbsem.h" #include "mycat.h" #include "xtable.h" -#include "tabodbc.h" #include "odbccat.h" +#include "tabodbc.h" #include "tabmul.h" #include "reldef.h" #include "tabcol.h" @@ -93,9 +93,10 @@ bool ExactInfo(void); /***********************************************************************/ ODBCDEF::ODBCDEF(void) { - Connect= Tabname= Tabschema= Tabcat= Srcdef= Qchar= Qrystr= Sep= NULL; + Connect = Tabname = Tabschema = Username = Password = NULL; + Tabcat = Srcdef = Qchar = Qrystr = Sep = NULL; Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = 0; - Scrollable = Memory = Xsrc = false; + Scrollable = Memory = Xsrc = UseCnc = false; } // end of ODBCDEF constructor /***********************************************************************/ @@ -117,6 +118,8 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Tabschema = GetStringCatInfo(g, "Schema", Tabschema); Tabcat = GetStringCatInfo(g, "Qualifier", NULL); Tabcat = GetStringCatInfo(g, "Catalog", Tabcat); + Username = GetStringCatInfo(g, "User", NULL); + Password = GetStringCatInfo(g, "Password", NULL); if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL))) Read_Only = true; @@ -133,6 +136,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Cto= GetIntCatInfo("ConnectTimeout", DEFAULT_LOGIN_TIMEOUT); Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT); Scrollable = GetBoolCatInfo("Scrollable", false); + UseCnc = GetBoolCatInfo("UseDSN", false); Memory = GetBoolCatInfo("Memory", false); Pseudo = 2; // FILID is Ok but not ROWID return false; @@ -190,34 +194,40 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBASE(tdp) Connect = tdp->Connect; TableName = tdp->Tabname; Schema = tdp->Tabschema; + Ops.User = tdp->Username; + Ops.Pwd = tdp->Password; Catalog = tdp->Tabcat; Srcdef = tdp->Srcdef; Qrystr = tdp->Qrystr; Sep = tdp->GetSep(); Options = tdp->Options; - Cto = tdp->Cto; - Qto = tdp->Qto; + Ops.Cto = tdp->Cto; + Ops.Qto = tdp->Qto; Quoted = MY_MAX(0, tdp->GetQuoted()); Rows = tdp->GetElemt(); Catver = tdp->Catver; Memory = (tdp->Memory) ? 1 : 0; Scrollable = tdp->Scrollable; + Ops.UseCnc = tdp->UseCnc; } else { Connect = NULL; TableName = NULL; Schema = NULL; + Ops.User = NULL; + Ops.Pwd = NULL; Catalog = NULL; Srcdef = NULL; Qrystr = NULL; Sep = 0; Options = 0; - Cto = DEFAULT_LOGIN_TIMEOUT; - Qto = DEFAULT_QUERY_TIMEOUT; + Ops.Cto = DEFAULT_LOGIN_TIMEOUT; + Ops.Qto = DEFAULT_QUERY_TIMEOUT; Quoted = 0; Rows = 0; Catver = 0; Memory = 0; Scrollable = false; + Ops.UseCnc = false; } // endif tdp Quote = NULL; @@ -242,6 +252,7 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp) Connect = tdbp->Connect; TableName = tdbp->TableName; Schema = tdbp->Schema; + Ops = tdbp->Ops; Catalog = tdbp->Catalog; Srcdef = tdbp->Srcdef; Qrystr = tdbp->Qrystr; @@ -254,8 +265,6 @@ TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBASE(tdbp) MulConn = tdbp->MulConn; DBQ = tdbp->DBQ; Options = tdbp->Options; - Cto = tdbp->Cto; - Qto = tdbp->Qto; Quoted = tdbp->Quoted; Rows = tdbp->Rows; Fpos = tdbp->Fpos; @@ -370,7 +379,7 @@ int TDBODBC::Decode(char *txt, char *buf, size_t n) /***********************************************************************/ char *TDBODBC::MakeSQL(PGLOBAL g, bool cnt) { - char *colist, *tabname, *sql, buf[64]; + char *colist, *tabname, *sql, buf[NAM_LEN * 3]; LPCSTR schmp = NULL, catp = NULL; int len, ncol = 0; bool first = true; @@ -474,6 +483,9 @@ char *TDBODBC::MakeSQL(PGLOBAL g, bool cnt) if (To_CondFil) strcat(strcat(sql, " WHERE "), To_CondFil->Body); + + if (trace) + htrc("sql: '%s'\n", sql); return sql; } // end of MakeSQL @@ -483,7 +495,7 @@ char *TDBODBC::MakeSQL(PGLOBAL g, bool cnt) /***********************************************************************/ char *TDBODBC::MakeInsert(PGLOBAL g) { - char *stmt, *colist, *valist; + char *stmt, *colist, *valist, buf[NAM_LEN * 3]; // char *tk = "`"; int len = 0; bool b = FALSE; @@ -510,10 +522,13 @@ char *TDBODBC::MakeInsert(PGLOBAL g) } else b = true; + // Column name can be in UTF-8 encoding + Decode(colp->GetName(), buf, sizeof(buf)); + if (Quote) - strcat(strcat(strcat(colist, Quote), colp->GetName()), Quote); + strcat(strcat(strcat(colist, Quote), buf), Quote); else - strcat(colist, colp->GetName()); + strcat(colist, buf); strcat(valist, "?"); // Parameter marker } // endfor colp @@ -558,8 +573,7 @@ bool TDBODBC::BindParameters(PGLOBAL g) /***********************************************************************/ char *TDBODBC::MakeCommand(PGLOBAL g) { - char *p, name[68], *qc = Ocp->GetQuoteChar(); - char *stmt = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 64); + char *p, *stmt, name[68], *body = NULL, *qc = Ocp->GetQuoteChar(); char *qrystr = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 1); bool qtd = Quoted > 0; int i = 0, k = 0; @@ -570,6 +584,15 @@ char *TDBODBC::MakeCommand(PGLOBAL g) qrystr[i] = (Qrystr[i] == '`') ? *qc : tolower(Qrystr[i]); } while (Qrystr[i++]); + if (To_CondFil && (p = strstr(qrystr, " where "))) { + p[7] = 0; // Remove where clause + Qrystr[(p - qrystr) + 7] = 0; + body = To_CondFil->Body; + stmt = (char*)PlugSubAlloc(g, NULL, strlen(qrystr) + + strlen(body) + 64); + } else + stmt = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 64); + // Check whether the table name is equal to a keyword // If so, it must be quoted in the original query strlwr(strcat(strcat(strcpy(name, " "), Name), " ")); @@ -597,6 +620,9 @@ char *TDBODBC::MakeCommand(PGLOBAL g) stmt[i++] = (Qrystr[k] == '`') ? *qc : Qrystr[k]; } while (Qrystr[k++]); + if (body) + strcat(stmt, body); + } else { sprintf(g->Message, "Cannot use this %s command", (Mode == MODE_UPDATE) ? "UPDATE" : "DELETE"); @@ -698,10 +724,7 @@ int TDBODBC::Cardinality(PGLOBAL g) char qry[96], tbn[64]; ODBConn *ocp = new(g) ODBConn(g, this); - ocp->SetLoginTimeout((DWORD)Cto); - ocp->SetQueryTimeout((DWORD)Qto); - - if (ocp->Open(Connect, Options) < 1) + if (ocp->Open(Connect, &Ops, Options) < 1) return -1; // Table name can be encoded in UTF-8 @@ -762,9 +785,9 @@ int TDBODBC::GetProgMax(PGLOBAL g) /***********************************************************************/ bool TDBODBC::OpenDB(PGLOBAL g) { - bool rc = false; + bool rc = true; - if (g->Trace) + if (trace) htrc("ODBC OpenDB: tdbp=%p tdb=R%d use=%dmode=%d\n", this, Tdb_No, Use, Mode); @@ -802,14 +825,12 @@ bool TDBODBC::OpenDB(PGLOBAL g) /* and if so to allocate just a new result set. But this only for */ /* drivers allowing concurency in getting results ??? */ /*********************************************************************/ - if (!Ocp) { + if (!Ocp) Ocp = new(g) ODBConn(g, this); - Ocp->SetLoginTimeout((DWORD)Cto); - Ocp->SetQueryTimeout((DWORD)Qto); - } else if (Ocp->IsOpen()) + else if (Ocp->IsOpen()) Ocp->Close(); - if (Ocp->Open(Connect, Options) < 1) + if (Ocp->Open(Connect, &Ops, Options) < 1) return true; else if (Quoted) Quote = Ocp->GetQuoteChar(); @@ -839,12 +860,12 @@ bool TDBODBC::OpenDB(PGLOBAL g) } // endif Query - } else if (Mode == MODE_UPDATE || Mode == MODE_DELETE) - Query = MakeCommand(g); - else + } else if (Mode == MODE_UPDATE || Mode == MODE_DELETE) { + rc = false; // wait for CheckCond before calling MakeCommand(g); + } else sprintf(g->Message, "Invalid mode %d", Mode); - if (!Query || rc) { + if (rc) { Ocp->Close(); return true; } // endif rc @@ -876,6 +897,9 @@ int TDBODBC::ReadDB(PGLOBAL g) GetTdb_No(), Mode, To_Key_Col, To_Link, To_Kindex); if (Mode == MODE_UPDATE || Mode == MODE_DELETE) { + if (!Query && !(Query = MakeCommand(g))) + return RC_FX; + // Send the UPDATE/DELETE command to the remote table if (!Ocp->ExecSQLcommand(Query)) { sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); @@ -945,6 +969,9 @@ int TDBODBC::WriteDB(PGLOBAL g) int TDBODBC::DeleteDB(PGLOBAL g, int irc) { if (irc == RC_FX) { + if (!Query && !(Query = MakeCommand(g))) + return RC_FX; + // Send the DELETE (all) command to the remote table if (!Ocp->ExecSQLcommand(Query)) { sprintf(g->Message, "%s: %d affected rows", TableName, AftRows); @@ -1158,12 +1185,12 @@ void ODBCCOL::ReadColumn(PGLOBAL g) } // endif Buf_Type - if (g->Trace) { + if (trace) { char buf[64]; htrc("ODBC Column %s: rows=%d buf=%p type=%d value=%s\n", Name, tdbp->Rows, Bufp, Buf_Type, Value->GetCharString(buf)); - } // endif Trace + } // endif trace put: if (tdbp->Memory != 2) @@ -1397,7 +1424,7 @@ bool TDBXDBC::OpenDB(PGLOBAL g) { bool rc = false; - if (g->Trace) + if (trace) htrc("ODBC OpenDB: tdbp=%p tdb=R%d use=%dmode=%d\n", this, Tdb_No, Use, Mode); @@ -1415,12 +1442,10 @@ bool TDBXDBC::OpenDB(PGLOBAL g) /*********************************************************************/ if (!Ocp) { Ocp = new(g) ODBConn(g, this); - Ocp->SetLoginTimeout((DWORD)Cto); - Ocp->SetQueryTimeout((DWORD)Qto); } else if (Ocp->IsOpen()) Ocp->Close(); - if (Ocp->Open(Connect, Options) < 1) + if (Ocp->Open(Connect, &Ops, Options) < 1) return true; Use = USE_OPEN; // Do it now in case we are recursively called @@ -1554,8 +1579,11 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) Dsn = tdp->GetConnect(); Schema = tdp->GetTabschema(); Tab = tdp->GetTabname(); - Cto = tdp->Cto; - Qto = tdp->Qto; + Ops.User = tdp->Username; + Ops.Pwd = tdp->Password; + Ops.Cto = tdp->Cto; + Ops.Qto = tdp->Qto; + Ops.UseCnc = tdp->UseCnc; } // end of TDBOTB constructor /***********************************************************************/ @@ -1563,7 +1591,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) /***********************************************************************/ PQRYRES TDBOTB::GetResult(PGLOBAL g) { - return ODBCTables(g, Dsn, Schema, Tab, Maxres, Cto, Qto, false); + return ODBCTables(g, Dsn, Schema, Tab, Maxres, false, &Ops); } // end of GetResult /* ---------------------------TDBOCL class --------------------------- */ @@ -1573,7 +1601,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g) /***********************************************************************/ PQRYRES TDBOCL::GetResult(PGLOBAL g) { - return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, Cto, Qto, false); + return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, false, &Ops); } // end of GetResult /* ------------------------ End of Tabodbc --------------------------- */ diff --git a/storage/connect/tabodbc.h b/storage/connect/tabodbc.h index d8644c8b6de..eb20eb6efde 100644 --- a/storage/connect/tabodbc.h +++ b/storage/connect/tabodbc.h @@ -50,6 +50,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */ PSZ Connect; /* ODBC connection string */ PSZ Tabname; /* External table name */ PSZ Tabschema; /* External table schema */ + PSZ Username; /* User connect name */ + PSZ Password; /* Password connect info */ PSZ Tabcat; /* External table catalog */ PSZ Srcdef; /* The source table SQL definition */ PSZ Qchar; /* Identifier quoting character */ @@ -65,6 +67,7 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */ bool Scrollable; /* Use scrollable cursor */ bool Memory; /* Put result set in memory */ bool Xsrc; /* Execution type */ + bool UseCnc; /* Use SQLConnect (!SQLDriverConnect) */ }; // end of ODBCDEF #if !defined(NODBC) @@ -124,9 +127,12 @@ class TDBODBC : public TDBASE { // Members ODBConn *Ocp; // Points to an ODBC connection class ODBCCOL *Cnp; // Points to count(*) column + ODBCPARM Ops; // Additional parameters char *Connect; // Points to connection string char *TableName; // Points to ODBC table name char *Schema; // Points to ODBC table Schema + char *User; // User connect info + char *Pwd; // Password connect info char *Catalog; // Points to ODBC table Catalog char *Srcdef; // The source table SQL definition char *Query; // Points to SQL statement @@ -151,6 +157,7 @@ class TDBODBC : public TDBASE { int Nparm; // The number of statement parameters int Memory; // 0: No 1: Alloc 2: Put 3: Get bool Scrollable; // Use scrollable cursor + bool UseCnc; // Use SQLConnect (!SQLDriverConnect) PQRYRES Qrp; // Points to storage result }; // end of class TDBODBC @@ -316,8 +323,7 @@ class TDBOTB : public TDBDRV { char *Dsn; // Points to connection string char *Schema; // Points to schema name or NULL char *Tab; // Points to ODBC table name or pattern - int Cto; // Connect timeout - int Qto; // Query timeout + ODBCPARM Ops; // Additional parameters }; // end of class TDBOTB /***********************************************************************/ diff --git a/storage/connect/tabpivot.cpp b/storage/connect/tabpivot.cpp index 94e9d7187f0..2b0c43dac9f 100644 --- a/storage/connect/tabpivot.cpp +++ b/storage/connect/tabpivot.cpp @@ -558,7 +558,7 @@ bool TDBPIVOT::MakePivotColumns(PGLOBAL g) // Check and initialize the subtable columns for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (cp->GetAmType() == TYPE_AM_SRC) { - if (((PSRCCOL)cp)->Init(g)) + if (((PSRCCOL)cp)->Init(g, NULL)) return TRUE; } else if (cp->GetAmType() == TYPE_AM_FNC) @@ -874,9 +874,9 @@ SRCCOL::SRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int n) /***********************************************************************/ /* Initialize the column as pointing to the source column. */ /***********************************************************************/ -bool SRCCOL::Init(PGLOBAL g) +bool SRCCOL::Init(PGLOBAL g, PTDBASE tp) { - if (PRXCOL::Init(g)) + if (PRXCOL::Init(g, tp)) return true; AddStatus(BUF_READ); // All is done here diff --git a/storage/connect/tabpivot.h b/storage/connect/tabpivot.h index 25d139e895f..c397af05234 100644 --- a/storage/connect/tabpivot.h +++ b/storage/connect/tabpivot.h @@ -180,9 +180,10 @@ class SRCCOL : public PRXCOL { virtual int GetAmType(void) {return TYPE_AM_SRC;} // Methods + using PRXCOL::Init; virtual void Reset(void) {} void SetColumn(void); - bool Init(PGLOBAL g); + virtual bool Init(PGLOBAL g, PTDBASE tp); bool CompareLast(void); protected: diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index 22ec3849b6f..a33d6caa83a 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -266,7 +266,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) // Real initialization will be done later. for (colp = Columns; colp; colp = colp->GetNext()) if (!colp->IsSpecial()) - if (((PPRXCOL)colp)->Init(g) && !Accept) + if (((PPRXCOL)colp)->Init(g, NULL) && !Accept) return TRUE; if (Tablist) @@ -352,7 +352,9 @@ bool TDBTBL::TestFil(PGLOBAL g, PCFIL filp, PTABLE tabp) /***********************************************************************/ int TDBTBL::Cardinality(PGLOBAL g) { - if (Cardinal < 0) { + if (!g) + return 0; // Cannot make the table list + else if (Cardinal < 0) { int tsz; if (!Tablist && InitTableList(g)) @@ -468,7 +470,7 @@ bool TDBTBL::OpenDB(PGLOBAL g) for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (cp->GetAmType() == TYPE_AM_TABID) cp->COLBLK::Reset(); - else if (((PPRXCOL)cp)->Init(g) && !Accept) + else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return TRUE; if (trace) @@ -523,7 +525,7 @@ int TDBTBL::ReadDB(PGLOBAL g) if (cp->GetAmType() == TYPE_AM_TABID || cp->GetAmType() == TYPE_AM_SRVID) cp->COLBLK::Reset(); - else if (((PPRXCOL)cp)->Init(g) && !Accept) + else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return RC_FX; if (trace) @@ -716,7 +718,7 @@ bool TDBTBM::OpenDB(PGLOBAL g) for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (cp->GetAmType() == TYPE_AM_TABID) cp->COLBLK::Reset(); - else if (((PPRXCOL)cp)->Init(g) && !Accept) + else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return TRUE; if (trace) @@ -807,7 +809,7 @@ int TDBTBM::ReadNextRemote(PGLOBAL g) for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (cp->GetAmType() == TYPE_AM_TABID) cp->COLBLK::Reset(); - else if (((PPRXCOL)cp)->Init(g) && !Accept) + else if (((PPRXCOL)cp)->Init(g, NULL) && !Accept) return RC_FX; if (trace) diff --git a/storage/connect/tabutil.cpp b/storage/connect/tabutil.cpp index d469594916f..c1c112633fd 100644 --- a/storage/connect/tabutil.cpp +++ b/storage/connect/tabutil.cpp @@ -54,7 +54,8 @@ #include "tabutil.h" #include "ha_connect.h" -extern "C" int zconv; +//extern "C" int zconv; +int GetConvSize(void); /************************************************************************/ /* Used by MYSQL tables to get MySQL parameters from the calling proxy */ @@ -132,6 +133,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db, char *fld, *colname, *chset, *fmt, v; int i, n, ncol = sizeof(buftyp) / sizeof(int); int prec, len, type, scale; + int zconv = GetConvSize(); bool mysql; TABLE_SHARE *s = NULL; Field* *field; @@ -668,6 +670,22 @@ PRXCOL::PRXCOL(PRXCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp) Colnum = col1->Colnum; } // end of PRXCOL copy constructor +/***********************************************************************/ +/* Convert an UTF-8 name to latin characters. */ +/***********************************************************************/ +char *PRXCOL::Decode(PGLOBAL g, const char *cnm) + { + char *buf= (char*)PlugSubAlloc(g, NULL, strlen(cnm) + 1); + uint dummy_errors; + uint32 len= copy_and_convert(buf, strlen(cnm) + 1, + &my_charset_latin1, + cnm, strlen(cnm), + &my_charset_utf8_general_ci, + &dummy_errors); + buf[len]= '\0'; + return buf; + } // end of Decode + /***********************************************************************/ /* PRXCOL initialization routine. */ /* Look for the matching column in the object table. */ @@ -683,6 +701,9 @@ bool PRXCOL::Init(PGLOBAL g, PTDBASE tp) if (Colp) { MODE mode = To_Tdb->GetMode(); + // Needed for MYSQL subtables + ((XCOLBLK*)Colp)->Name = Decode(g, Colp->GetName()); + // May not have been done elsewhere Colp->InitValue(g); To_Val = Colp->GetValue(); diff --git a/storage/connect/tabutil.h b/storage/connect/tabutil.h index 606e532d526..c5935d72184 100644 --- a/storage/connect/tabutil.h +++ b/storage/connect/tabutil.h @@ -108,15 +108,18 @@ class DllExport PRXCOL : public COLBLK { virtual int GetAmType(void) {return TYPE_AM_PRX;} // Methods + using COLBLK::Init; virtual void Reset(void); virtual bool IsSpecial(void) {return Pseudo;} virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) {return false;} virtual void ReadColumn(PGLOBAL g); virtual void WriteColumn(PGLOBAL g); - virtual bool Init(PGLOBAL g, PTDBASE tp = NULL); + virtual bool Init(PGLOBAL g, PTDBASE tp); protected: + char *Decode(PGLOBAL g, const char *cnm); + // Default constructor not to be used PRXCOL(void) {} @@ -144,4 +147,8 @@ class TDBTBC : public TDBCAT { PSZ Tab; // Table name }; // end of class TDBMCL +class XCOLBLK : public COLBLK { + friend class PRXCOL; +}; // end of class XCOLBLK + #endif // TABUTIL diff --git a/storage/connect/tabxcl.cpp b/storage/connect/tabxcl.cpp index 57f0e1e03b9..0de01927c5a 100644 --- a/storage/connect/tabxcl.cpp +++ b/storage/connect/tabxcl.cpp @@ -183,7 +183,7 @@ bool TDBXCL::OpenDB(PGLOBAL g) /*********************************************************************/ for (PCOL cp = Columns; cp; cp = cp->GetNext()) if (!cp->IsSpecial()) - if (((PPRXCOL)cp)->Init(g)) + if (((PPRXCOL)cp)->Init(g, NULL)) return TRUE; /*********************************************************************/ diff --git a/storage/connect/tabxcl.h b/storage/connect/tabxcl.h index 7e11600c090..ed15a67b629 100644 --- a/storage/connect/tabxcl.h +++ b/storage/connect/tabxcl.h @@ -88,6 +88,7 @@ class XCLCOL : public PRXCOL { XCLCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i); // Methods + using PRXCOL::Init; virtual void Reset(void) {} // Evaluated only by TDBXCL virtual void ReadColumn(PGLOBAL g); virtual bool Init(PGLOBAL g, PTDBASE tp = NULL); diff --git a/storage/connect/valblk.h b/storage/connect/valblk.h index 654db0b57b7..5a98257f98f 100644 --- a/storage/connect/valblk.h +++ b/storage/connect/valblk.h @@ -163,6 +163,7 @@ class TYPBLK : public VALBLK { virtual void Reset(int n) {Typp[n] = 0;} // Methods + using VALBLK::SetValue; virtual void SetValue(PSZ sp, int n); virtual void SetValue(char *sp, uint len, int n); virtual void SetValue(short sval, int n) @@ -233,6 +234,7 @@ class CHRBLK : public VALBLK { virtual bool IsCi(void) {return Ci;} // Methods + using VALBLK::SetValue; virtual void SetValue(PSZ sp, int n); virtual void SetValue(char *sp, uint len, int n); virtual void SetValue(PVAL valp, int n); @@ -286,6 +288,7 @@ class STRBLK : public VALBLK { virtual void Reset(int n) {Strp[n] = NULL;} // Methods + using VALBLK::SetValue; virtual void SetValue(PSZ sp, int n); virtual void SetValue(char *sp, uint len, int n); virtual void SetValue(PVAL valp, int n); @@ -322,6 +325,7 @@ class DATBLK : public TYPBLK { virtual char *GetCharString(char *p, int n); // Methods + using TYPBLK::SetValue; virtual void SetValue(PSZ sp, int n); protected: @@ -345,6 +349,8 @@ class PTRBLK : public STRBLK { // Implementation // Methods + using STRBLK::SetValue; + using STRBLK::CompVal; virtual void SetValue(PSZ p, int n) {Strp[n] = p;} virtual int CompVal(int i1, int i2); diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index 1cc40473433..e012e12d00b 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -436,6 +436,9 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) bool un = (uns < 0) ? false : (uns > 0) ? true : valp->IsUnsigned(); PVAL vp; + if (!valp) + return NULL; + if (newtype == TYPE_VOID) // Means allocate a value of the same type newtype = valp->GetType(); @@ -443,8 +446,8 @@ PVAL AllocateValue(PGLOBAL g, PVAL valp, int newtype, int uns) case TYPE_STRING: p = (PSZ)PlugSubAlloc(g, NULL, 1 + valp->GetValLen()); - if ((sp = valp->GetCharString(p)) != p) - strcpy (p, sp); + if ((sp = valp->GetCharString(p)) != p && sp) + strcpy(p, sp); vp = new(g) TYPVAL(g, p, valp->GetValLen(), valp->GetValPrec()); break; @@ -1216,12 +1219,12 @@ TYPVAL::TYPVAL(PSZ s) : VALUE(TYPE_STRING) TYPVAL::TYPVAL(PGLOBAL g, PSZ s, int n, int c) : VALUE(TYPE_STRING) { - Len = (g) ? n : strlen(s); + Len = (g) ? n : (s) ? strlen(s) : 0; if (!s) { if (g) { if ((Strp = (char *)PlgDBSubAlloc(g, NULL, Len + 1))) - Strp[Len] = '\0'; + memset(Strp, 0, Len + 1); else Len = 0; diff --git a/storage/connect/xindex.h b/storage/connect/xindex.h index c702baeec83..6e40e9b160e 100644 --- a/storage/connect/xindex.h +++ b/storage/connect/xindex.h @@ -391,6 +391,7 @@ class DllExport XHUGE : public XLOAD { XHUGE(void) : XLOAD() {} // Methods + using XLOAD::Close; virtual bool Open(PGLOBAL g, char *filename, int id, MODE mode); virtual bool Seek(PGLOBAL g, int low, int high, int origin); virtual bool Read(PGLOBAL g, void *buf, int n, int size); diff --git a/storage/connect/xobject.cpp b/storage/connect/xobject.cpp index 4ddd4f5b30f..817acb561fe 100644 --- a/storage/connect/xobject.cpp +++ b/storage/connect/xobject.cpp @@ -346,6 +346,31 @@ bool STRING::Append(char c) return false; } // end of Append +/***********************************************************************/ +/* Append a quoted PSZ to a STRING. */ +/***********************************************************************/ +bool STRING::Append_quoted(PSZ s) +{ + bool b = Append('\''); + + if (s) for (char *p = s; !b && *p; p++) + switch (*p) { + case '\'': + case '\\': + case '\t': + case '\n': + case '\r': + case '\b': + case '\f': b |= Append('\\'); + // passthru + default: + b |= Append(*p); + break; + } // endswitch *p + + return (b |= Append('\'')); +} // end of Append_quoted + /***********************************************************************/ /* Resize to given length but only when last suballocated. */ /* New size should be greater than string length. */ diff --git a/storage/connect/xobject.h b/storage/connect/xobject.h index bb7b0150ed8..3660ee86918 100644 --- a/storage/connect/xobject.h +++ b/storage/connect/xobject.h @@ -138,6 +138,7 @@ class DllExport STRING : public BLOCK { bool Append(STRING &str); bool Append(char c); bool Resize(uint n); + bool Append_quoted(PSZ s); inline void Trim(void) {(void)Resize(Length + 1);} inline void Chop(void) {if (Length) Strp[--Length] = 0;} inline void RepLast(char c) {if (Length) Strp[Length-1] = c;} diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index 79b533481b7..00b90120f6c 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -3055,6 +3055,12 @@ func_start: /* 2. Allocate a new page to the index */ new_block = btr_page_alloc(cursor->index, hint_page_no, direction, btr_page_get_level(page, mtr), mtr, mtr); + + /* Play safe, if new page is not allocated */ + if (!new_block) { + return(rec); + } + new_page = buf_block_get_frame(new_block); new_page_zip = buf_block_get_page_zip(new_block); btr_page_create(new_block, new_page_zip, cursor->index, diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 2defcb89eb0..c8dd4fae0a9 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -2368,15 +2368,15 @@ btr_cur_pess_upd_restore_supremum( Check if the total length of the modified blob for the row is within 10% of the total redo log size. This constraint on the blob length is to avoid overwriting the redo logs beyond the last checkpoint lsn. -@return DB_SUCCESS or DB_TOO_BIG_RECORD. */ +@return DB_SUCCESS or DB_TOO_BIG_FOR_REDO. */ static dberr_t btr_check_blob_limit(const big_rec_t* big_rec_vec) { const ib_uint64_t redo_size = srv_n_log_files * srv_log_file_size * UNIV_PAGE_SIZE; - const ulint redo_10p = redo_size / 10; - ulint total_blob_len = 0; + const ib_uint64_t redo_10p = redo_size / 10; + ib_uint64_t total_blob_len = 0; dberr_t err = DB_SUCCESS; /* Calculate the total number of bytes for blob data */ @@ -2386,11 +2386,11 @@ btr_check_blob_limit(const big_rec_t* big_rec_vec) if (total_blob_len > redo_10p) { ib_logf(IB_LOG_LEVEL_ERROR, "The total blob data" - " length (" ULINTPF ") is greater than" + " length (" UINT64PF ") is greater than" " 10%% of the total redo log size (" UINT64PF "). Please increase total redo log size.", total_blob_len, redo_size); - err = DB_TOO_BIG_RECORD; + err = DB_TOO_BIG_FOR_REDO; } return(err); @@ -4453,7 +4453,7 @@ Stores the fields in big_rec_vec to the tablespace and puts pointers to them in rec. The extern flags in rec will have to be set beforehand. The fields are stored on pages allocated from leaf node file segment of the index tree. -@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */ +@return DB_SUCCESS or DB_OUT_OF_FILE_SPACE or DB_TOO_BIG_FOR_REDO */ UNIV_INTERN dberr_t btr_store_big_rec_extern_fields( diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index ecefde7fd42..36f2ca21249 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -2427,10 +2427,10 @@ too_big: dict_mem_index_free(new_index); dict_mem_index_free(index); return(DB_TOO_BIG_RECORD); - } else { - + } else if (current_thd != NULL) { + /* Avoid the warning to be printed + during recovery. */ ib_warn_row_too_big(table); - } } diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 58781fce1d4..f0ea15d9513 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -319,6 +319,9 @@ dict_mem_table_col_rename_low( ut_ad(from_len <= NAME_LEN); ut_ad(to_len <= NAME_LEN); + char from[NAME_LEN]; + strncpy(from, s, NAME_LEN); + if (from_len == to_len) { /* The easy case: simply replace the column name in table->col_names. */ @@ -386,14 +389,53 @@ dict_mem_table_col_rename_low( foreign = *it; - for (unsigned f = 0; f < foreign->n_fields; f++) { - /* These can point straight to - table->col_names, because the foreign key - constraints will be freed at the same time - when the table object is freed. */ - foreign->foreign_col_names[f] - = dict_index_get_nth_field( - foreign->foreign_index, f)->name; + if (foreign->foreign_index == NULL) { + /* We may go here when we set foreign_key_checks to 0, + and then try to rename a column and modify the + corresponding foreign key constraint. The index + would have been dropped, we have to find an equivalent + one */ + for (unsigned f = 0; f < foreign->n_fields; f++) { + if (strcmp(foreign->foreign_col_names[f], from) + == 0) { + + char** rc = const_cast( + foreign->foreign_col_names + + f); + + if (to_len <= strlen(*rc)) { + memcpy(*rc, to, to_len + 1); + } else { + *rc = static_cast( + mem_heap_dup( + foreign->heap, + to, + to_len + 1)); + } + } + } + + dict_index_t* new_index = dict_foreign_find_index( + foreign->foreign_table, NULL, + foreign->foreign_col_names, + foreign->n_fields, NULL, true, false); + /* There must be an equivalent index in this case. */ + ut_ad(new_index != NULL); + + foreign->foreign_index = new_index; + + } else { + + for (unsigned f = 0; f < foreign->n_fields; f++) { + /* These can point straight to + table->col_names, because the foreign key + constraints will be freed at the same time + when the table object is freed. */ + foreign->foreign_col_names[f] + = dict_index_get_nth_field( + foreign->foreign_index, + f)->name; + } } } @@ -403,6 +445,8 @@ dict_mem_table_col_rename_low( foreign = *it; + ut_ad(foreign->referenced_index != NULL); + for (unsigned f = 0; f < foreign->n_fields; f++) { /* foreign->referenced_col_names[] need to be copies, because the constraint may become diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 4175abdf895..506ba320853 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -4957,6 +4957,9 @@ retry: success = TRUE; } + DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", + success = FALSE; errno = 28; os_has_said_disk_full = TRUE;); + mutex_enter(&fil_system->mutex); if (success) { node->size += n_pages; @@ -4998,6 +5001,11 @@ retry: offset, page_size * n_pages, NULL, NULL); #endif /* UNIV_HOTBACKUP */ + + + DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", + success = FALSE; errno = 28; os_has_said_disk_full = TRUE;); + if (success) { os_has_said_disk_full = FALSE; } else { diff --git a/storage/innobase/fts/fts0ast.cc b/storage/innobase/fts/fts0ast.cc index dd48ffee14d..030b972440f 100644 --- a/storage/innobase/fts/fts0ast.cc +++ b/storage/innobase/fts/fts0ast.cc @@ -694,3 +694,51 @@ fts_ast_string_print( printf("\n"); } + +#ifdef UNIV_DEBUG +const char* +fts_ast_oper_name_get(fts_ast_oper_t oper) +{ + switch(oper) { + case FTS_NONE: + return("FTS_NONE"); + case FTS_IGNORE: + return("FTS_IGNORE"); + case FTS_EXIST: + return("FTS_EXIST"); + case FTS_NEGATE: + return("FTS_NEGATE"); + case FTS_INCR_RATING: + return("FTS_INCR_RATING"); + case FTS_DECR_RATING: + return("FTS_DECR_RATING"); + case FTS_DISTANCE: + return("FTS_DISTANCE"); + case FTS_IGNORE_SKIP: + return("FTS_IGNORE_SKIP"); + case FTS_EXIST_SKIP: + return("FTS_EXIST_SKIP"); + } + ut_ad(0); +} + +const char* +fts_ast_node_type_get(fts_ast_type_t type) +{ + switch (type) { + case FTS_AST_OPER: + return("FTS_AST_OPER"); + case FTS_AST_NUMB: + return("FTS_AST_NUMB"); + case FTS_AST_TERM: + return("FTS_AST_TERM"); + case FTS_AST_TEXT: + return("FTS_AST_TEXT"); + case FTS_AST_LIST: + return("FTS_AST_LIST"); + case FTS_AST_SUBEXP_LIST: + return("FTS_AST_SUBEXP_LIST"); + } + ut_ad(0); +} +#endif /* UNIV_DEBUG */ diff --git a/storage/innobase/fts/fts0opt.cc b/storage/innobase/fts/fts0opt.cc index 2e2bd061d07..5891b53a6e2 100644 --- a/storage/innobase/fts/fts0opt.cc +++ b/storage/innobase/fts/fts0opt.cc @@ -2577,8 +2577,6 @@ fts_optimize_add_table( return; } - ut_ad(table->cached && table->fts != NULL); - /* Make sure table with FTS index cannot be evicted */ if (table->can_be_evicted) { dict_table_move_from_lru_to_non_lru(table); diff --git a/storage/innobase/fts/fts0que.cc b/storage/innobase/fts/fts0que.cc index 8f4813e4b3f..9f03cd6a451 100644 --- a/storage/innobase/fts/fts0que.cc +++ b/storage/innobase/fts/fts0que.cc @@ -1534,7 +1534,8 @@ fts_merge_doc_ids( { const ib_rbt_node_t* node; - ut_a(!rbt_empty(doc_ids)); + DBUG_ENTER("fts_merge_doc_ids"); + ut_a(!query->intersection); /* To process FTS_EXIST operation (intersection), we need @@ -1559,7 +1560,7 @@ fts_merge_doc_ids( query, ranking->doc_id, ranking->rank); if (query->error != DB_SUCCESS) { - return(query->error); + DBUG_RETURN(query->error); } /* Merge words. Don't need to take operator into account. */ @@ -1578,7 +1579,7 @@ fts_merge_doc_ids( query->intersection = NULL; } - return(DB_SUCCESS); + DBUG_RETURN(DB_SUCCESS); } /*****************************************************************//** @@ -2839,11 +2840,11 @@ fts_query_visitor( fts_query_t* query = static_cast(arg); ut_a(node); + DBUG_ENTER("fts_query_visitor"); + DBUG_PRINT("fts", ("nodetype: %s", fts_ast_node_type_get(node->type))); token.f_n_char = 0; - query->oper = oper; - query->cur_node = node; switch (node->type) { @@ -2905,7 +2906,7 @@ fts_query_visitor( query->multi_exist = true; } - return(query->error); + DBUG_RETURN(query->error); } /*****************************************************************//** @@ -2929,6 +2930,8 @@ fts_ast_visit_sub_exp( bool will_be_ignored = false; bool multi_exist; + DBUG_ENTER("fts_ast_visit_sub_exp"); + ut_a(node->type == FTS_AST_SUBEXP_LIST); cur_oper = query->oper; @@ -2957,14 +2960,14 @@ fts_ast_visit_sub_exp( /* Merge the sub-expression result with the parent result set. */ subexpr_doc_ids = query->doc_ids; query->doc_ids = parent_doc_ids; - if (error == DB_SUCCESS && !rbt_empty(subexpr_doc_ids)) { + if (error == DB_SUCCESS) { error = fts_merge_doc_ids(query, subexpr_doc_ids); } /* Free current result set. Result already merged into parent. */ fts_query_free_doc_ids(query, subexpr_doc_ids); - return(error); + DBUG_RETURN(error); } #if 0 @@ -3440,8 +3443,10 @@ fts_retrieve_ranking( ib_rbt_bound_t parent; fts_ranking_t new_ranking; + DBUG_ENTER("fts_retrieve_ranking"); + if (!result || !result->rankings_by_id) { - return(0); + DBUG_RETURN(0); } new_ranking.doc_id = doc_id; @@ -3452,10 +3457,10 @@ fts_retrieve_ranking( ranking = rbt_value(fts_ranking_t, parent.last); - return(ranking->rank); + DBUG_RETURN(ranking->rank); } - return(0); + DBUG_RETURN(0); } /*****************************************************************//** @@ -3472,6 +3477,8 @@ fts_query_prepare_result( const ib_rbt_node_t* node; bool result_is_null = false; + DBUG_ENTER("fts_query_prepare_result"); + if (result == NULL) { result = static_cast(ut_malloc(sizeof(*result))); @@ -3520,7 +3527,7 @@ fts_query_prepare_result( if (query->total_size > fts_result_cache_limit) { query->error = DB_FTS_EXCEED_RESULT_CACHE_LIMIT; fts_query_free_result(result); - return(NULL); + DBUG_RETURN(NULL); } } @@ -3543,7 +3550,7 @@ fts_query_prepare_result( ranking->rank * word_freq->idf * word_freq->idf); } - return(result); + DBUG_RETURN(result); } ut_a(rbt_size(query->doc_ids) > 0); @@ -3570,7 +3577,7 @@ fts_query_prepare_result( if (query->total_size > fts_result_cache_limit) { query->error = DB_FTS_EXCEED_RESULT_CACHE_LIMIT; fts_query_free_result(result); - return(NULL); + DBUG_RETURN(NULL); } } } @@ -3582,7 +3589,7 @@ fts_query_prepare_result( query->doc_ids = NULL; } - return(result); + DBUG_RETURN(result); } /*****************************************************************//** @@ -3594,6 +3601,8 @@ fts_query_get_result( fts_query_t* query, /*!< in: query instance */ fts_result_t* result) /*!< in: result */ { + DBUG_ENTER("fts_query_get_result"); + if (rbt_size(query->doc_ids) > 0 || query->flags == FTS_OPT_RANKING) { /* Copy the doc ids to the result. */ result = fts_query_prepare_result(query, result); @@ -3603,7 +3612,7 @@ fts_query_get_result( memset(result, 0, sizeof(*result)); } - return(result); + DBUG_RETURN(result); } /*****************************************************************//** @@ -3681,6 +3690,7 @@ fts_query_parse( int error; fts_ast_state_t state; bool mode = query->boolean_mode; + DBUG_ENTER("fts_query_parse"); memset(&state, 0x0, sizeof(state)); @@ -3699,7 +3709,7 @@ fts_query_parse( query->root = state.root; } - return(state.root); + DBUG_RETURN(state.root); } /*******************************************************************//** diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index b55d13c7d8b..3b0b825f3af 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1587,6 +1587,15 @@ convert_error_code_to_mysql( return(HA_ERR_TO_BIG_ROW); } + + case DB_TOO_BIG_FOR_REDO: + my_printf_error(ER_TOO_BIG_ROWSIZE, "%s" , MYF(0), + "The size of BLOB/TEXT data inserted" + " in one transaction is greater than" + " 10% of redo log size. Increase the" + " redo log size using innodb_log_file_size."); + return(HA_ERR_TO_BIG_ROW); + case DB_TOO_BIG_INDEX_COL: my_error(ER_INDEX_COLUMN_TOO_LONG, MYF(0), DICT_MAX_FIELD_LEN_BY_FORMAT_FLAG(flags)); @@ -14995,10 +15004,8 @@ ha_innobase::cmp_ref( len1 = innobase_read_from_2_little_endian(ref1); len2 = innobase_read_from_2_little_endian(ref2); - ref1 += 2; - ref2 += 2; result = ((Field_blob*) field)->cmp( - ref1, len1, ref2, len2); + ref1 + 2, len1, ref2 + 2, len2); } else { result = field->key_cmp(ref1, ref2); } diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index e24e82ca472..c5210565171 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -4439,11 +4439,15 @@ err_exit: rename_foreign: trx->op_info = "renaming column in SYS_FOREIGN_COLS"; + std::list fk_evict; + bool foreign_modified; + for (dict_foreign_set::const_iterator it = user_table->foreign_set.begin(); it != user_table->foreign_set.end(); ++it) { dict_foreign_t* foreign = *it; + foreign_modified = false; for (unsigned i = 0; i < foreign->n_fields; i++) { if (strcmp(foreign->foreign_col_names[i], from)) { @@ -4471,6 +4475,11 @@ rename_foreign: if (error != DB_SUCCESS) { goto err_exit; } + foreign_modified = true; + } + + if (foreign_modified) { + fk_evict.push_back(foreign); } } @@ -4479,7 +4488,9 @@ rename_foreign: it != user_table->referenced_set.end(); ++it) { + foreign_modified = false; dict_foreign_t* foreign = *it; + for (unsigned i = 0; i < foreign->n_fields; i++) { if (strcmp(foreign->referenced_col_names[i], from)) { continue; @@ -4506,7 +4517,17 @@ rename_foreign: if (error != DB_SUCCESS) { goto err_exit; } + foreign_modified = true; } + + if (foreign_modified) { + fk_evict.push_back(foreign); + } + } + + if (new_clustered) { + std::for_each(fk_evict.begin(), fk_evict.end(), + dict_foreign_remove_from_cache); } trx->op_info = ""; diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index e4e7ecce53a..5fd0fdcb10a 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -3893,7 +3893,7 @@ check_watch: { buf_page_t* bpage; buf_pool_t* buf_pool = buf_pool_get(space, page_no); - bpage = buf_page_hash_get(buf_pool, space, page_no); + bpage = buf_page_get_also_watch(buf_pool, space, page_no); if (UNIV_LIKELY_NULL(bpage)) { /* A buffer pool watch has been set or the diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 3097015999c..4b2556524fa 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1268,7 +1268,7 @@ page_hash lock is acquired in the specified lock mode. Otherwise, mode value is ignored. It is up to the caller to release the lock. If the block is found and the lock is NULL then the page_hash lock is released by this function. -@return block, NULL if not found */ +@return block, NULL if not found, or watch sentinel (if watch is true) */ UNIV_INLINE buf_page_t* buf_page_hash_get_locked( @@ -1284,9 +1284,11 @@ buf_page_hash_get_locked( found. NULL otherwise. If NULL is passed then the hash_lock is released by this function */ - ulint lock_mode); /*!< in: RW_LOCK_EX or + ulint lock_mode, /*!< in: RW_LOCK_EX or RW_LOCK_SHARED. Ignored if lock == NULL */ + bool watch = false); /*!< in: if true, return watch + sentinel also. */ /******************************************************************//** Returns the control block of a file page, NULL if not found. If the block is found and lock is not NULL then the appropriate @@ -1326,6 +1328,8 @@ buf_page_hash_get_low() function. buf_page_hash_get_locked(b, s, o, l, RW_LOCK_EX) #define buf_page_hash_get(b, s, o) \ buf_page_hash_get_locked(b, s, o, NULL, 0) +#define buf_page_get_also_watch(b, s, o) \ + buf_page_hash_get_locked(b, s, o, NULL, 0, true) #define buf_block_hash_get_s_locked(b, s, o, l) \ buf_block_hash_get_locked(b, s, o, l, RW_LOCK_SHARED) diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index 6e419674f98..56616c6deeb 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -1172,7 +1172,7 @@ page_hash lock is acquired in the specified lock mode. Otherwise, mode value is ignored. It is up to the caller to release the lock. If the block is found and the lock is NULL then the page_hash lock is released by this function. -@return block, NULL if not found */ +@return block, NULL if not found, or watch sentinel (if watch is true) */ UNIV_INLINE buf_page_t* buf_page_hash_get_locked( @@ -1188,9 +1188,11 @@ buf_page_hash_get_locked( found. NULL otherwise. If NULL is passed then the hash_lock is released by this function */ - ulint lock_mode) /*!< in: RW_LOCK_EX or + ulint lock_mode, /*!< in: RW_LOCK_EX or RW_LOCK_SHARED. Ignored if lock == NULL */ + bool watch) /*!< in: if true, return watch + sentinel also. */ { buf_page_t* bpage = NULL; ulint fold; @@ -1221,7 +1223,9 @@ buf_page_hash_get_locked( bpage = buf_page_hash_get_low(buf_pool, space, offset, fold); if (!bpage || buf_pool_watch_is_sentinel(buf_pool, bpage)) { - bpage = NULL; + if (!watch) { + bpage = NULL; + } goto unlock_and_exit; } diff --git a/storage/innobase/include/db0err.h b/storage/innobase/include/db0err.h index 71916cb33f2..1e87ce3fdb8 100644 --- a/storage/innobase/include/db0err.h +++ b/storage/innobase/include/db0err.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -130,7 +130,8 @@ enum dberr_t { DB_TEMP_FILE_WRITE_FAILURE, /*!< Temp file write failure */ DB_FTS_TOO_MANY_WORDS_IN_PHRASE, /*< Too many words in a phrase */ - + DB_TOO_BIG_FOR_REDO, /* Record length greater than 10% + of redo log */ /* The following are partial failure codes */ DB_FAIL = 1000, DB_OVERFLOW, diff --git a/storage/innobase/include/fts0ast.h b/storage/innobase/include/fts0ast.h index 50ee587e282..b2380f78b39 100644 --- a/storage/innobase/include/fts0ast.h +++ b/storage/innobase/include/fts0ast.h @@ -329,4 +329,11 @@ struct fts_ast_state_t { tokenization */ }; +#ifdef UNIV_DEBUG +const char* +fts_ast_oper_name_get(fts_ast_oper_t oper); +const char* +fts_ast_node_type_get(fts_ast_type_t type); +#endif /* UNIV_DEBUG */ + #endif /* INNOBASE_FSTS0AST_H */ diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h index 563a01f747d..5ecaa33fb96 100644 --- a/storage/innobase/include/ha_prototypes.h +++ b/storage/innobase/include/ha_prototypes.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2006, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2006, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/storage/innobase/include/lock0priv.h b/storage/innobase/include/lock0priv.h index 9f7ab9f76b6..16423e6a282 100644 --- a/storage/innobase/include/lock0priv.h +++ b/storage/innobase/include/lock0priv.h @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 2007, 2011, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2015, MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -72,6 +73,12 @@ struct lock_t { hash_node_t hash; /*!< hash chain node for a record lock */ dict_index_t* index; /*!< index for a record lock */ + + /* Statistics for how long lock has been held and time + how long this lock had to be waited before it was granted */ + time_t requested_time; /*!< Lock request time */ + ulint wait_time; /*!< Time waited this lock or 0 */ + union { lock_table_t tab_lock;/*!< table lock */ lock_rec_t rec_lock;/*!< record lock */ diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h index 74d3c6bbc7c..e9fec827c1f 100644 --- a/storage/innobase/include/os0file.h +++ b/storage/innobase/include/os0file.h @@ -1,6 +1,6 @@ /*********************************************************************** -Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Percona Inc. Portions of this file contain modifications contributed and copyrighted diff --git a/storage/innobase/include/row0merge.h b/storage/innobase/include/row0merge.h index 390c0ce038b..2b9e9f7711c 100644 --- a/storage/innobase/include/row0merge.h +++ b/storage/innobase/include/row0merge.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2005, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2005, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/storage/innobase/include/trx0roll.h b/storage/innobase/include/trx0roll.h index 9d020a10725..d5ab83d7767 100644 --- a/storage/innobase/include/trx0roll.h +++ b/storage/innobase/include/trx0roll.h @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -32,6 +32,8 @@ Created 3/26/1996 Heikki Tuuri #include "mtr0mtr.h" #include "trx0sys.h" +extern bool trx_rollback_or_clean_is_active; + /*******************************************************************//** Determines if this transaction is rolling back an incomplete transaction in crash recovery. diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 7c92445b796..dd26e420aa2 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -1009,6 +1009,19 @@ struct trx_t{ /*------------------------------*/ char detailed_error[256]; /*!< detailed error message for last error, or empty. */ + /* Lock wait statistics */ + ulint n_rec_lock_waits; + /*!< Number of record lock waits, + might not be exactly correct. */ + ulint n_table_lock_waits; + /*!< Number of table lock waits, + might not be exactly correct. */ + ulint total_rec_lock_wait_time; + /*!< Total rec lock wait time up + to this moment. */ + ulint total_table_lock_wait_time; + /*!< Total table lock wait time + up to this moment. */ #ifdef WITH_WSREP os_event_t wsrep_event; /* event waited for in srv_conc_slot */ #endif /* WITH_WSREP */ diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index acfee420352..3c96c93cfa5 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -44,7 +44,7 @@ Created 1/20/1994 Heikki Tuuri #define INNODB_VERSION_MAJOR 5 #define INNODB_VERSION_MINOR 6 -#define INNODB_VERSION_BUGFIX 22 +#define INNODB_VERSION_BUGFIX 23 /* The following is the InnoDB version as shown in SELECT plugin_version FROM information_schema.plugins; diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 914b7f42f10..66033530a72 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2014, 2015, MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -2044,6 +2045,9 @@ lock_rec_create( /* Set the bit corresponding to rec */ lock_rec_set_nth_bit(lock, heap_no); + lock->requested_time = ut_time(); + lock->wait_time = 0; + index->table->n_rec_locks++; ut_ad(index->table->n_ref_count > 0 || !index->table->can_be_evicted); @@ -2276,6 +2280,8 @@ lock_rec_enqueue_waiting( MONITOR_INC(MONITOR_LOCKREC_WAIT); + trx->n_rec_lock_waits++; + return(DB_LOCK_WAIT); } @@ -2308,7 +2314,8 @@ lock_rec_add_to_queue( ut_ad(lock_mutex_own()); ut_ad(caller_owns_trx_mutex == trx_mutex_own(trx)); - ut_ad(dict_index_is_clust(index) || !dict_index_is_online_ddl(index)); + ut_ad(dict_index_is_clust(index) + || dict_index_get_online_status(index) != ONLINE_INDEX_CREATION); #ifdef UNIV_DEBUG switch (type_mode & LOCK_MODE_MASK) { case LOCK_X: @@ -2749,6 +2756,17 @@ lock_grant( } } + /* Cumulate total lock wait time for statistics */ + if (lock_get_type_low(lock) & LOCK_TABLE) { + lock->trx->total_table_lock_wait_time += + (ulint)difftime(ut_time(), lock->trx->lock.wait_started); + } else { + lock->trx->total_rec_lock_wait_time += + (ulint)difftime(ut_time(), lock->trx->lock.wait_started); + } + + lock->wait_time = (ulint)difftime(ut_time(), lock->requested_time); + trx_mutex_exit(lock->trx); } @@ -4540,6 +4558,8 @@ lock_table_create( lock->type_mode = type_mode | LOCK_TABLE; lock->trx = trx; + lock->requested_time = ut_time(); + lock->wait_time = 0; lock->un_member.tab_lock.table = table; @@ -4845,6 +4865,7 @@ lock_table_enqueue_waiting( trx->lock.wait_started = ut_time(); trx->lock.was_chosen_as_deadlock_victim = FALSE; + trx->n_table_lock_waits++; ut_a(que_thr_stop(thr)); @@ -5552,6 +5573,10 @@ lock_table_print( fputs(" waiting", file); } + fprintf(file, " lock hold time %lu wait time before grant %lu ", + (ulint)difftime(ut_time(), lock->requested_time), + lock->wait_time); + putc('\n', file); } @@ -5583,7 +5608,14 @@ lock_rec_print( fprintf(file, "RECORD LOCKS space id %lu page no %lu n bits %lu ", (ulong) space, (ulong) page_no, (ulong) lock_rec_get_n_bits(lock)); + dict_index_name_print(file, lock->trx, lock->index); + + /* Print number of table locks */ + fprintf(file, " trx table locks %lu total table locks %lu ", + ib_vector_size(lock->trx->lock.table_locks), + UT_LIST_GET_LEN(lock->index->table->locks)); + fprintf(file, " trx id " TRX_ID_FMT, lock->trx->id); if (lock_get_mode(lock) == LOCK_S) { @@ -5612,6 +5644,10 @@ lock_rec_print( mtr_start(&mtr); + fprintf(file, " lock hold time %lu wait time before grant %lu ", + (ulint)difftime(ut_time(), lock->requested_time), + lock->wait_time); + putc('\n', file); block = buf_page_try_get(space, page_no, &mtr); @@ -5870,6 +5906,14 @@ loop: trx->read_view->up_limit_id); } + /* Total trx lock waits and times */ + fprintf(file, "Trx #rec lock waits %lu #table lock waits %lu\n", + trx->n_rec_lock_waits, trx->n_table_lock_waits); + fprintf(file, "Trx total rec lock wait time %lu SEC\n", + trx->total_rec_lock_wait_time); + fprintf(file, "Trx total table lock wait time %lu SEC\n", + trx->total_table_lock_wait_time); + if (trx->lock.que_state == TRX_QUE_LOCK_WAIT) { fprintf(file, diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index d849b1a6329..1850e798ed3 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Google Inc. Portions of this file contain modifications contributed and copyrighted by @@ -48,7 +48,7 @@ Created 12/9/1995 Heikki Tuuri #include "srv0start.h" #include "trx0sys.h" #include "trx0trx.h" -#include "ha_prototypes.h" +#include "trx0roll.h" #include "srv0mon.h" /* @@ -3212,6 +3212,12 @@ logs_empty_and_mark_files_at_shutdown(void) ib_logf(IB_LOG_LEVEL_INFO, "Starting shutdown..."); + while (srv_fast_shutdown == 0 && trx_rollback_or_clean_is_active) { + /* we should wait until rollback after recovery end + for slow shutdown */ + os_thread_sleep(100000); + } + /* Wait until the master thread and all other operations are idle: our algorithm only works if the server is idle at shutdown */ diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc index 4fe9620ccaa..aa6c81483d7 100644 --- a/storage/innobase/log/log0recv.cc +++ b/storage/innobase/log/log0recv.cc @@ -3486,6 +3486,7 @@ recv_recovery_rollback_active(void) /* Rollback the uncommitted transactions which have no user session */ + trx_rollback_or_clean_is_active = true; os_thread_create(trx_rollback_or_clean_all_recovered, 0, 0); } } diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 81590545abc..ee18fae54c7 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -1,6 +1,6 @@ /*********************************************************************** -Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2009, Percona Inc. Portions of this file contain modifications contributed and copyrighted @@ -2671,13 +2671,18 @@ try_again: ret = os_file_pread(file, buf, n, offset); if ((ulint) ret == n) { - return(TRUE); + } else if (ret == -1) { + ib_logf(IB_LOG_LEVEL_ERROR, + "Error in system call pread(). The operating" + " system error number is %lu.",(ulint) errno); + } else { + /* Partial read occured */ + ib_logf(IB_LOG_LEVEL_ERROR, + "Tried to read " ULINTPF " bytes at offset " + UINT64PF ". Was only able to read %ld.", + n, offset, (lint) ret); } - - ib_logf(IB_LOG_LEVEL_ERROR, - "Tried to read " ULINTPF " bytes at offset " UINT64PF ". " - "Was only able to read %ld.", n, offset, (lint) ret); #endif /* __WIN__ */ #ifdef __WIN__ error_handling: @@ -2797,8 +2802,17 @@ try_again: ret = os_file_pread(file, buf, n, offset); if ((ulint) ret == n) { - return(TRUE); + } else if (ret == -1) { + ib_logf(IB_LOG_LEVEL_ERROR, + "Error in system call pread(). The operating" + " system error number is %lu.",(ulint) errno); + } else { + /* Partial read occured */ + ib_logf(IB_LOG_LEVEL_ERROR, + "Tried to read " ULINTPF " bytes at offset " + UINT64PF ". Was only able to read %ld.", + n, offset, (lint) ret); } #endif /* __WIN__ */ #ifdef __WIN__ @@ -3018,18 +3032,26 @@ retry: if (!os_has_said_disk_full) { ut_print_timestamp(stderr); - fprintf(stderr, - " InnoDB: Error: Write to file %s failed" - " at offset " UINT64PF ".\n" - "InnoDB: %lu bytes should have been written," - " only %ld were written.\n" - "InnoDB: Operating system error number %lu.\n" - "InnoDB: Check that your OS and file system" - " support files of this size.\n" - "InnoDB: Check also that the disk is not full" - " or a disk quota exceeded.\n", - name, offset, n, (lint) ret, - (ulint) errno); + if(ret == -1) { + ib_logf(IB_LOG_LEVEL_ERROR, + "Failure of system call pwrite(). Operating" + " system error number is %lu.", + (ulint) errno); + } else { + fprintf(stderr, + " InnoDB: Error: Write to file %s failed" + " at offset " UINT64PF ".\n" + "InnoDB: %lu bytes should have been written," + " only %ld were written.\n" + "InnoDB: Operating system error number %lu.\n" + "InnoDB: Check that your OS and file system" + " support files of this size.\n" + "InnoDB: Check also that the disk is not full" + " or a disk quota exceeded.\n", + name, offset, n, (lint) ret, + (ulint) errno); + } + if (strerror(errno) != NULL) { fprintf(stderr, "InnoDB: Error number %d means '%s'.\n", @@ -4606,7 +4628,7 @@ os_aio_func( mode = mode & (~OS_AIO_SIMULATED_WAKE_LATER); DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", - mode = OS_AIO_SYNC;); + mode = OS_AIO_SYNC; os_has_said_disk_full = TRUE;); if (mode == OS_AIO_SYNC #ifdef WIN_ASYNC_IO @@ -4636,14 +4658,10 @@ os_aio_func( ut_a(type == OS_FILE_WRITE); ret = os_file_write_func(name, file, buf, offset, n); - } - DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", - os_has_said_disk_full = FALSE;); - DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", - ret = 0;); - DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", - errno = 28;); + DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", + os_has_said_disk_full = TRUE; ret = 0; errno = 28;); + } return ret; } @@ -5464,19 +5482,17 @@ consecutive_loop: ret = os_file_write( aio_slot->name, aio_slot->file, combined_buf, aio_slot->offset, total_len); + + DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", + os_has_said_disk_full = TRUE; + ret = 0; + errno = 28;); } else { ret = os_file_read( aio_slot->file, combined_buf, aio_slot->offset, total_len); } - if (aio_slot->type == OS_FILE_WRITE) { - DBUG_EXECUTE_IF("ib_os_aio_func_io_failure_28", - os_has_said_disk_full = FALSE; - ret = 0; - errno = 28;); - } - srv_set_io_thread_op_info(global_segment, "file i/o done"); if (aio_slot->type == OS_FILE_READ && n_consecutive > 1) { diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index b11a9f0d85a..621a14d27c2 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2010, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2010, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index e9d8bd50d6a..1c8b65a5696 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2005, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2005, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 2717d39b4c0..fb632d1347e 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2000, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2000, 2015, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -610,6 +610,7 @@ handle_new_error: case DB_DUPLICATE_KEY: case DB_FOREIGN_DUPLICATE_KEY: case DB_TOO_BIG_RECORD: + case DB_TOO_BIG_FOR_REDO: case DB_UNDO_RECORD_TOO_BIG: case DB_ROW_IS_REFERENCED: case DB_NO_REFERENCED_ROW: @@ -4373,7 +4374,7 @@ row_drop_table_for_mysql( case DB_OUT_OF_FILE_SPACE: err = DB_MUST_GET_MORE_FILE_SPACE; - + trx->error_state = err; row_mysql_handle_errors(&err, trx, NULL, NULL); /* raise error */ diff --git a/storage/innobase/row/row0quiesce.cc b/storage/innobase/row/row0quiesce.cc index 1d67d5a9717..ecd6f47947b 100644 --- a/storage/innobase/row/row0quiesce.cc +++ b/storage/innobase/row/row0quiesce.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2012, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2012, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -680,7 +680,6 @@ row_quiesce_set_state( switch (state) { case QUIESCE_START: - ut_a(table->quiesce == QUIESCE_NONE); break; case QUIESCE_COMPLETE: diff --git a/storage/innobase/srv/srv0mon.cc b/storage/innobase/srv/srv0mon.cc index f29621bc90a..a0dd32c203f 100644 --- a/storage/innobase/srv/srv0mon.cc +++ b/storage/innobase/srv/srv0mon.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2010, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2010, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. This program is free software; you can redistribute it and/or modify it under @@ -925,7 +925,8 @@ static monitor_info_t innodb_counter_info[] = {"adaptive_hash_searches_btree", "adaptive_hash_index", "Number of searches using B-tree on an index search", - MONITOR_NONE, + static_cast( + MONITOR_EXISTING | MONITOR_DEFAULT_ON), MONITOR_DEFAULT_START, MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE}, {"adaptive_hash_pages_added", "adaptive_hash_index", diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index c754544b136..2ec4f9d5714 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, 2009 Google Inc. Copyright (c) 2009, Percona Inc. Copyright (c) 2013, 2014, SkySQL Ab. All Rights Reserved. @@ -2686,7 +2686,9 @@ srv_do_purge( *n_total_purged += n_pages_purged; - } while (!srv_purge_should_exit(n_pages_purged) && n_pages_purged > 0); + } while (!srv_purge_should_exit(n_pages_purged) + && n_pages_purged > 0 + && purge_sys->state == PURGE_STATE_RUN); return(rseg_history_len); } diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index 3484c1f818d..27ef082b93e 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -53,6 +53,9 @@ Created 3/26/1996 Heikki Tuuri rollback */ #define TRX_ROLL_TRUNC_THRESHOLD 1 +/** true if trx_rollback_or_clean_all_recovered() thread is active */ +bool trx_rollback_or_clean_is_active; + /** In crash recovery, the current trx to be rolled back; NULL otherwise */ static const trx_t* trx_roll_crash_recv_trx = NULL; @@ -815,6 +818,8 @@ DECLARE_THREAD(trx_rollback_or_clean_all_recovered)( trx_rollback_or_clean_recovered(TRUE); + trx_rollback_or_clean_is_active = false; + /* We count the number of threads in os_thread_exit(). A created thread should always use that to exit and not use return() to exit. */ diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc index b273b5a117e..68446cc85ef 100644 --- a/storage/innobase/ut/ut0ut.cc +++ b/storage/innobase/ut/ut0ut.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2012, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -822,6 +822,8 @@ ut_strerr( return("Temp file write failure"); case DB_FTS_TOO_MANY_WORDS_IN_PHRASE: return("Too many words in a FTS phrase or proximity search"); + case DB_TOO_BIG_FOR_REDO: + return("BLOB record length is greater than 10%% of redo log"); /* do not add default: in order to produce a warning if new code is added to the enum but not added here */ diff --git a/storage/mroonga/CMakeLists.txt b/storage/mroonga/CMakeLists.txt index faad871fa95..4c5156ba96d 100644 --- a/storage/mroonga/CMakeLists.txt +++ b/storage/mroonga/CMakeLists.txt @@ -1,6 +1,6 @@ # -*- indent-tabs-mode: nil -*- # -# Copyright(C) 2012-2014 Kouhei Sutou +# Copyright(C) 2012-2015 Kouhei Sutou # Copyright(C) 2013 Kentoku SHIBA # # This library is free software; you can redistribute it and/or @@ -46,6 +46,11 @@ if(MRN_BUNDLED) endif() endif() +IF(HAVE_WVLA) + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-vla") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-vla") +ENDIF() + set(MRN_BUNDLED_GROONGA_RELATIVE_DIR "vendor/groonga") set(MRN_BUNDLED_GROONGA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${MRN_BUNDLED_GROONGA_RELATIVE_DIR}") @@ -75,6 +80,28 @@ file(READ ${MRN_SOURCE_DIR}/version_in_hex MRN_VERSION_IN_HEX) file(READ ${MRN_SOURCE_DIR}/plugin_version MRN_PLUGIN_VERSION) if(MRN_GROONGA_BUNDLED) + option(MRN_GROONGA_EMBED + "Embed libgroonga" + ON) + if(MRN_GROONGA_EMBED) + set(GRN_EMBED ON) + endif() + + set(MRN_BUNDLED_GROONGA_NORMALIZER_MYSQL_DIR + "${MRN_BUNDLED_GROONGA_DIR}/vendor/plugins/groonga-normalizer-mysql") + option(MRN_GROONGA_NORMALIZER_MYSQL_EMBED + "Embed groonga-normalizer-mysql Groonga plugin" + ON) + if(EXISTS ${MRN_BUNDLED_GROONGA_NORMALIZER_MYSQL_DIR}) + set(GROONGA_NORMALIZER_MYSQL_FOUND ON) + else() + set(GROONGA_NORMALIZER_MYSQL_FOUND OFF) + set(MRN_GROONGA_NORMALIZER_MYSQL_EMBED OFF) + endif() + if(MRN_GROONGA_NORMALIZER_MYSQL_EMBED) + set(GROONGA_NORMALIZER_MYSQL_EMBED ON) + endif() + add_subdirectory("${MRN_BUNDLED_GROONGA_RELATIVE_DIR}") else() file(READ ${MRN_SOURCE_DIR}/required_groonga_version REQUIRED_GROONGA_VERSION) @@ -98,15 +125,21 @@ set(MRN_C_COMPILE_FLAGS "") set(MRN_CXX_COMPILE_FLAGS "") macro(mrn_check_cflag flag) - check_c_compiler_flag(${flag} "HAVE_C_${flag}") - if(HAVE_C_${flag}) + string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag}) + string(TOUPPER "${temporary_variable_name}" temporary_variable_name) + set(temporary_variable_name "CFLAG${temporary_variable_name}") + check_c_compiler_flag(${flag} ${temporary_variable_name}) + if(${temporary_variable_name}) set(MRN_C_COMPILE_FLAGS "${MRN_C_COMPILE_FLAGS} ${flag}") endif() endmacro() macro(mrn_check_cxxflag flag) - check_cxx_compiler_flag(${flag} "HAVE_CXX_${flag}") - if(HAVE_CXX_${flag}) + string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag}) + string(TOUPPER "${temporary_variable_name}" temporary_variable_name) + set(temporary_variable_name "CXXFLAG${temporary_variable_name}") + check_cxx_compiler_flag(${flag} ${temporary_variable_name}) + if(${temporary_variable_name}) set(MRN_CXX_COMPILE_FLAGS "${MRN_CXX_COMPILE_FLAGS} ${flag}") endif() endmacro() @@ -122,7 +155,7 @@ else() set(MRN_RELATIVE_DIR_PREFIX "") endif() -read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/sources.am MROONGA_SOURCES) +read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/sources.am MRN_SOURCES) read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/lib/libmrn_no_mysql_sources.am LIBMRN_NO_MYSQL_SOURCES) string(REGEX REPLACE "([^;]+)" "${MRN_RELATIVE_DIR_PREFIX}lib/\\1" @@ -157,11 +190,18 @@ else() set(MYSQL_REGEX_INCLUDE_DIR "${MYSQL_SOURCE_DIR}/regex") endif() +if(EXISTS "${MYSQL_SOURCE_DIR}/extra/rapidjson") + set(MYSQL_RAPIDJSON_INCLUDE_DIR "${MYSQL_SOURCE_DIR}/extra/rapidjson/include") +else() + set(MYSQL_RAPIDJSON_INCLUDE_DIR) +endif() + set(MYSQL_INCLUDE_DIRS "${MYSQL_BUILD_DIR}/include" "${MYSQL_SOURCE_DIR}/sql" "${MYSQL_SOURCE_DIR}/include" "${MYSQL_REGEX_INCLUDE_DIR}" + "${MYSQL_RAPIDJSON_INCLUDE_DIR}" "${MYSQL_SOURCE_DIR}") if(MRN_BUNDLED) @@ -190,6 +230,12 @@ else() set_mysql_config_value("--version" MYSQL_VERSION) endif() +if(${MYSQL_VERSION} VERSION_LESS "5.5.0") + message(FATAL_ERROR + "Mroonga doesn't support MySQL < 5.5.0: <${MYSQL_VERSION}>") + return() +endif() + if(${MYSQL_VERSION} VERSION_GREATER "10.0.0" AND ${MYSQL_VERSION} VERSION_LESS "10.0.9") message(FATAL_ERROR @@ -201,10 +247,14 @@ if(MRN_GROONGA_BUNDLED) set(GROONGA_INCLUDE_DIRS "${MRN_BUNDLED_GROONGA_DIR}/include") set(GROONGA_LIBRARY_DIRS "${MRN_BUNDLED_GROONGA_DIR}/lib") set(GROONGA_LIBRARIES "libgroonga") - if(EXISTS "${MRN_BUNDLED_GROONGA_DIR}/vendor/plugins/groonga-normalizer-mysql") - set(GROONGA_NORMALIZER_MYSQL_FOUND TRUE) - else() - set(GROONGA_NORMALIZER_MYSQL_FOUND FALSE) + + set(MRN_LIBRARY_DIRS ${GROONGA_LIBRARY_DIRS}) + set(MRN_LIBRARIES ${GROONGA_LIBRARIES}) + if(MRN_GROONGA_NORMALIZER_MYSQL_EMBED) + set(MRN_LIBRARY_DIRS + ${MRN_LIBRARY_DIRS} + "${MRN_BUNDLED_GROONGA_NORMALIZER_MYSQL_DIR}/normalizers") + set(MRN_LIBRARIES ${MRN_LIBRARIES} mysql_normalizer) endif() else() include(FindPkgConfig) @@ -213,12 +263,6 @@ else() "groonga-normalizer-mysql >= ${REQUIRED_GROONGA_NORMALIZER_MYSQL_VERSION}") endif() -if(GROONGA_NORMALIZER_MYSQL_FOUND AND MRN_GROONGA_BUNDLED) - read_file_list(${MRN_BUNDLED_GROONGA_DIR}/vendor/plugins/groonga-normalizer-mysql/normalizers/mysql_sources.am MRN_GRN_NORMALIZER_MYSQL_SOURCES) - string(REGEX REPLACE "([^;]+)" "${MRN_BUNDLED_GROONGA_DIR}/vendor/plugins/groonga-normalizer-mysql/normalizers/\\1" - MRN_GRN_NORMALIZER_MYSQL_SOURCES "${MRN_GRN_NORMALIZER_MYSQL_SOURCES}") -endif() - include_directories( "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}" @@ -235,28 +279,22 @@ else() "${MYSQL_SERVICES_LIB_DIR}") endif() link_directories( - ${GROONGA_LIBRARY_DIRS} + ${MRN_LIBRARY_DIRS} ${MYSQL_LIBRARY_DIRS}) +set(MRN_ALL_SOURCES + ${MRN_SOURCES} + ${MRN_UDF_SOURCES} + ${LIBMRN_NO_MYSQL_SOURCES} + ${LIBMRN_NEED_MYSQL_SOURCES}) + if(MRN_BUNDLED) - if(GROONGA_NORMALIZER_MYSQL_FOUND AND MRN_GROONGA_BUNDLED) - mysql_add_plugin(mroonga - "${MROONGA_SOURCES};${MRN_UDF_SOURCES};${MRN_GRN_NORMALIZER_MYSQL_SOURCES};${LIBMRN_NEED_MYSQL_SOURCES};${LIBMRN_NO_MYSQL_SOURCES}" - STORAGE_ENGINE MODULE_ONLY - LINK_LIBRARIES ${GROONGA_LIBRARIES}) - else() - mysql_add_plugin(mroonga - "${MROONGA_SOURCES};${MRN_UDF_SOURCES};${LIBMRN_NEED_MYSQL_SOURCES};${LIBMRN_NO_MYSQL_SOURCES}" - STORAGE_ENGINE MODULE_ONLY - LINK_LIBRARIES ${GROONGA_LIBRARIES}) - endif() - else() + mysql_add_plugin(mroonga + ${MRN_ALL_SOURCES} + STORAGE_ENGINE MODULE_ONLY + LINK_LIBRARIES ${MRN_LIBRARIES}) else() - add_library(mroonga MODULE - ${MROONGA_SOURCES} - ${MRN_UDF_SOURCES} - ${LIBMRN_NO_MYSQL_SOURCES} - ${LIBMRN_NEED_MYSQL_SOURCES}) + add_library(mroonga MODULE ${MRN_ALL_SOURCES}) set(MYSQL_LIBRARIES "mysqlservices") target_link_libraries(mroonga ${GROONGA_LIBRARIES} ${MYSQL_LIBRARIES}) @@ -303,14 +341,14 @@ else() mrn_check_cxxflag("-fno-rtti") mrn_check_cxxflag("-felide-constructors") endif() - set_source_files_properties(${MROONGA_SOURCES} PROPERTIES + set_source_files_properties(${MRN_SOURCES} PROPERTIES COMPILE_FLAGS "${MYSQL_CFLAGS} ${MRN_CXX_COMPILE_FLAGS}") set_source_files_properties(${LIBMRN_NEED_MYSQL_SOURCES} PROPERTIES COMPILE_FLAGS "${MYSQL_CFLAGS} ${MRN_CXX_COMPILE_FLAGS}") set_source_files_properties(${MRN_UDF_SOURCES} PROPERTIES - COMPILE_FLAGS "${MRN_C_COMPILE_FLAGS}") + COMPILE_FLAGS "${MRN_CXX_COMPILE_FLAGS}") set_source_files_properties(${LIBMRN_NO_MYSQL_SOURCES} PROPERTIES - COMPILE_FLAGS "${MRN_C_COMPILE_FLAGS}") + COMPILE_FLAGS "${MRN_CXX_COMPILE_FLAGS}") set_property(TARGET mroonga APPEND PROPERTY COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN") set_target_properties(mroonga PROPERTIES @@ -321,19 +359,20 @@ else() endif() if(GROONGA_NORMALIZER_MYSQL_FOUND) - set(WITH_GROONGA_NORMALIZER_MYSQL 1) - ADD_DEFINITIONS(-DWITH_GROONGA_NORMALIZER_MYSQL=1) - if(MRN_GROONGA_BUNDLED) - ADD_DEFINITIONS(-DGROONGA_NORMALIZER_MYSQL_PLUGIN_IS_BUNDLED_STATIC=1) + set_property(TARGET mroonga APPEND PROPERTY + COMPILE_DEFINITIONS "WITH_GROONGA_NORMALIZER_MYSQL=1") + if(MRN_GROONGA_NORMALIZER_MYSQL_EMBED) + set_property(TARGET mroonga APPEND PROPERTY + COMPILE_DEFINITIONS "MRN_GROONGA_NORMALIZER_MYSQL_EMBED") else() - set(GROONGA_NORMALIZER_MYSQL_PLUGIN_NAME \"normalizers/mysql\") set_property(TARGET mroonga APPEND PROPERTY COMPILE_DEFINITIONS "GROONGA_NORMALIZER_MYSQL_PLUGIN_NAME=\"normalizers/mysql\"") endif() endif() set(MRN_DEFAULT_PARSER "TokenBigram" CACHE STRING "The default fulltext parser") -ADD_DEFINITIONS(-DMRN_PARSER_DEFAULT="${MRN_DEFAULT_PARSER}") +set_property(TARGET mroonga APPEND PROPERTY + COMPILE_DEFINITIONS "MRN_PARSER_DEFAULT=\"${MRN_DEFAULT_PARSER}\"") configure_file( "${PROJECT_SOURCE_DIR}/mrn_version.h.in" diff --git a/storage/mroonga/Makefile.am b/storage/mroonga/Makefile.am index 32fc88ad061..733347eb2c2 100644 --- a/storage/mroonga/Makefile.am +++ b/storage/mroonga/Makefile.am @@ -67,8 +67,6 @@ update-latest-release: misc misc/update-latest-release.rb \ $(PACKAGE) $(OLD_RELEASE) $(OLD_RELEASE_DATE) \ $(VERSION) $(NEW_RELEASE_DATE) \ - packages/rpm/fedora/mysql-mroonga.spec.in \ - packages/rpm/fedora/mariadb-mroonga.spec.in \ packages/rpm/centos/mariadb-mroonga.spec.in \ packages/rpm/centos/mysql55-mroonga.spec.in \ packages/rpm/centos/mysql56-community-mroonga.spec.in \ diff --git a/storage/mroonga/appveyor.yml b/storage/mroonga/appveyor.yml new file mode 100644 index 00000000000..a048d7d02e1 --- /dev/null +++ b/storage/mroonga/appveyor.yml @@ -0,0 +1,51 @@ +version: "{build}" +clone_depth: 10 +install: + - cd .. + - choco install curl 7zip.commandline + - curl -O http://mirror.jmu.edu/pub/mariadb/mariadb-10.0.16/source/mariadb-10.0.16.tar.gz + - 7z x mariadb-10.0.16.tar.gz + - 7z x mariadb-10.0.16.tar > nul + - cd mariadb-10.0.16 + - rmdir /S /Q storage\mroonga\ + - move ..\mroonga storage\mroonga + - git clone --quiet --depth 1 https://github.com/groonga/groonga.git ..\groonga + - rmdir /S /Q ..\groonga\test\ + - mkdir storage\mroonga\vendor + - move ..\groonga storage\mroonga\vendor\groonga + - git clone --quiet --depth 1 https://github.com/groonga/groonga-normalizer-mysql.git storage\mroonga\vendor\groonga\vendor\plugins\groonga-normalizer-mysql +build_script: + - "echo # > win\\packaging\\CMakeLists.txt" + - cmake . -G "Visual Studio 12 Win64" + -DCMAKE_BUILD_TYPE=Debug + -DWITHOUT_ARCHIVE=ON + -DWITHOUT_BLACKHOLE=ON + -DWITHOUT_CASSANDRA=ON + -DWITHOUT_CONNECT=ON + -DWITHOUT_CSV=ON + -DWITHOUT_EXAMPLE=ON + -DWITHOUT_FEDERATED=ON + -DWITHOUT_FEDERATEDX=ON + -DWITHOUT_HEAP=ON + -DWITHOUT_INNOBASE=ON + -DWITHOUT_MYISAM=ON + -DWITHOUT_MYISAMMRG=ON + -DWITHOUT_OQGRAPH=ON + -DWITHOUT_PERFSCHEMA=OFF + -DWITHOUT_SEQUENCE=ON + -DWITHOUT_SPHINX=ON + -DWITHOUT_SPIDER=ON + -DWITHOUT_TEST_SQL_DISCOVERY=ON + -DWITHOUT_TOKUDB=ON + -DWITHOUT_XTRADB=ON + -DWITH_UNIT_TESTS=OFF + - cmake --build . --config Debug + +notifications: + - provider: Email + to: + - groonga-mysql-commit@lists.sourceforge.jp + - kou@clear-code.com + on_build_status_changed: true + +test: off diff --git a/storage/mroonga/configure.ac b/storage/mroonga/configure.ac index 48312a44c8c..6d8fa0fe31d 100644 --- a/storage/mroonga/configure.ac +++ b/storage/mroonga/configure.ac @@ -174,6 +174,10 @@ AC_DEFUN([CONFIG_OPTION_MYSQL],[ MYSQL_INCLUDES="$MYSQL_INCLUDES -I$ac_mysql_build_dir/include" MYSQL_INCLUDES="$MYSQL_INCLUDES -I$ac_mysql_source_dir/sql" MYSQL_INCLUDES="$MYSQL_INCLUDES -I$ac_mysql_source_dir/include" + if test -d "$ac_mysql_source_dir/extra/rapidjson"; then + mysql_rapidjson_include_dir="$ac_mysql_source_dir/extra/rapidjson/include" + MYSQL_INCLUDES="$MYSQL_INCLUDES -I$mysql_rapidjson_include_dir" + fi if test -d "$ac_mysql_source_dir/pcre"; then mysql_regex_include_dir="$ac_mysql_source_dir/pcre" else @@ -461,7 +465,6 @@ AC_CONFIG_FILES([ packages/Makefile packages/rpm/Makefile packages/rpm/centos/Makefile - packages/rpm/fedora/Makefile packages/yum/Makefile packages/apt/Makefile packages/source/Makefile @@ -486,8 +489,6 @@ AC_OUTPUT([ packages/rpm/centos/mysql55-mroonga.spec packages/rpm/centos/mysql56-community-mroonga.spec packages/rpm/centos/mariadb-mroonga.spec - packages/rpm/fedora/mysql-mroonga.spec - packages/rpm/fedora/mariadb-mroonga.spec packages/yum/env.sh data/install.sql ]) diff --git a/storage/mroonga/ha_mroonga.cpp b/storage/mroonga/ha_mroonga.cpp index 8b9a08b59dc..dbc2f0ca6e3 100644 --- a/storage/mroonga/ha_mroonga.cpp +++ b/storage/mroonga/ha_mroonga.cpp @@ -2,7 +2,7 @@ /* Copyright(C) 2010 Tetsuro IKEDA Copyright(C) 2010-2013 Kentoku SHIBA - Copyright(C) 2011-2014 Kouhei Sutou + Copyright(C) 2011-2015 Kouhei Sutou Copyright(C) 2013 Kenji Maruyama This library is free software; you can redistribute it and/or @@ -116,23 +116,14 @@ } \ } while (0) #else -# if MYSQL_VERSION_ID >= 50500 -# ifdef DBUG_OFF -# ifndef _WIN32 -extern mysql_mutex_t LOCK_open; -# endif -# endif -static mysql_mutex_t *mrn_LOCK_open; -# define mrn_open_mutex_lock(share) mysql_mutex_lock(mrn_LOCK_open) -# define mrn_open_mutex_unlock(share) mysql_mutex_unlock(mrn_LOCK_open) -# else +# ifdef DBUG_OFF # ifndef _WIN32 -extern pthread_mutex_t LOCK_open; +extern mysql_mutex_t LOCK_open; # endif -static pthread_mutex_t *mrn_LOCK_open; -# define mrn_open_mutex_lock(share) -# define mrn_open_mutex_unlock(share) # endif +static mysql_mutex_t *mrn_LOCK_open; +# define mrn_open_mutex_lock(share) mysql_mutex_lock(mrn_LOCK_open) +# define mrn_open_mutex_unlock(share) mysql_mutex_unlock(mrn_LOCK_open) #endif #if MYSQL_VERSION_ID >= 50600 @@ -169,15 +160,6 @@ static pthread_mutex_t *mrn_LOCK_open; # define MRN_ABORT_ON_WARNING(thd) thd->abort_on_warning #endif -#ifdef WIN32 -# ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE - PSI_mutex_key *mrn_table_share_lock_share; -# endif -# ifdef MRN_TABLE_SHARE_HAVE_LOCK_HA_DATA - PSI_mutex_key *mrn_table_share_lock_ha_data; -# endif -#endif - #if MYSQL_VERSION_ID >= 100007 && defined(MRN_MARIADB_P) # define MRN_THD_GET_AUTOINC(thd, off, inc) thd_get_autoinc(thd, off, inc) # define MRN_GET_ERR_MSG(code) my_get_err_msg(code) @@ -208,19 +190,58 @@ int grn_atoi(const char *nptr, const char *end, const char **rest); uint grn_atoui(const char *nptr, const char *end, const char **rest); /* global variables */ -static pthread_mutex_t mrn_log_mutex; handlerton *mrn_hton_ptr; HASH mrn_open_tables; -pthread_mutex_t mrn_open_tables_mutex; +mysql_mutex_t mrn_open_tables_mutex; HASH mrn_long_term_share; -pthread_mutex_t mrn_long_term_share_mutex; +mysql_mutex_t mrn_long_term_share_mutex; +HASH mrn_allocated_thds; +mysql_mutex_t mrn_allocated_thds_mutex; /* internal variables */ static grn_ctx mrn_ctx; +static mysql_mutex_t mrn_log_mutex; static grn_obj *mrn_db; static grn_ctx mrn_db_manager_ctx; +static mysql_mutex_t mrn_db_manager_mutex; mrn::DatabaseManager *mrn_db_manager = NULL; +#ifdef HAVE_PSI_INTERFACE +PSI_mutex_key mrn_allocated_thds_mutex_key; +static PSI_mutex_key mrn_open_tables_mutex_key; +static PSI_mutex_key mrn_long_term_share_mutex_key; +PSI_mutex_key mrn_share_mutex_key; +PSI_mutex_key mrn_long_term_share_auto_inc_mutex_key; +static PSI_mutex_key mrn_db_manager_mutex_key; +static PSI_mutex_key mrn_log_mutex_key; + +static PSI_mutex_info mrn_mutexes[] = +{ + {&mrn_open_tables_mutex_key, "open_tables", PSI_FLAG_GLOBAL}, + {&mrn_long_term_share_mutex_key, "long_term_share", PSI_FLAG_GLOBAL}, + {&mrn_allocated_thds_mutex_key, "allocated_thds", PSI_FLAG_GLOBAL}, + {&mrn_share_mutex_key, "share", 0}, + {&mrn_long_term_share_auto_inc_mutex_key, + "long_term_share::auto_inc", 0}, + {&mrn_log_mutex_key, "log", PSI_FLAG_GLOBAL}, + {&mrn_db_manager_mutex_key, "DatabaseManager", PSI_FLAG_GLOBAL} +}; + +#ifdef WIN32 +# ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE + PSI_mutex_key *mrn_table_share_lock_share; +# endif +# ifdef MRN_TABLE_SHARE_HAVE_LOCK_HA_DATA + PSI_mutex_key *mrn_table_share_lock_ha_data; +# endif +#endif + +#else +#undef MRN_TABLE_SHARE_HAVE_LOCK_SHARE +#undef MRN_TABLE_SHARE_HAVE_LOCK_HA_DATA +#endif + + #ifdef WIN32 static inline double round(double x) { @@ -506,6 +527,31 @@ static int mrn_lock_timeout = grn_get_lock_timeout(); static char *mrn_libgroonga_version = const_cast(grn_get_version()); static char *mrn_version = const_cast(MRN_VERSION); static char *mrn_vector_column_delimiter = NULL; +static my_bool mrn_libgroonga_support_zlib = FALSE; +static my_bool mrn_libgroonga_support_lz4 = FALSE; +typedef enum { + MRN_BOOLEAN_MODE_SYNTAX_FLAG_DEFAULT = (1 << 0), + MRN_BOOLEAN_MODE_SYNTAX_FLAG_SYNTAX_QUERY = (1 << 1), + MRN_BOOLEAN_MODE_SYNTAX_FLAG_SYNTAX_SCRIPT = (1 << 2), + MRN_BOOLEAN_MODE_SYNTAX_FLAG_ALLOW_COLUMN = (1 << 3), + MRN_BOOLEAN_MODE_SYNTAX_FLAG_ALLOW_UPDATE = (1 << 4), + MRN_BOOLEAN_MODE_SYNTAX_FLAG_ALLOW_LEADING_NOT = (1 << 5) +} mrn_boolean_mode_syntax_flag; +static const char *mrn_boolean_mode_sytnax_flag_names[] = { + "DEFAULT", + "SYNTAX_QUERY", + "SYNTAX_SCRIPT", + "ALLOW_COLUMN", + "ALLOW_UPDATE", + "ALLOW_LEADING_NOT", + NullS +}; +static TYPELIB mrn_boolean_mode_syntax_flags_typelib = { + array_elements(mrn_boolean_mode_sytnax_flag_names) - 1, + "", + mrn_boolean_mode_sytnax_flag_names, + NULL +}; typedef enum { MRN_ACTION_ON_ERROR_ERROR, @@ -552,9 +598,6 @@ static grn_logger mrn_logger = { NULL }; -/* global hashes and mutexes */ -HASH mrn_allocated_thds; -pthread_mutex_t mrn_allocated_thds_mutex; static uchar *mrn_allocated_thds_get_key(const uchar *record, size_t *length, my_bool not_used __attribute__ ((unused))) @@ -578,13 +621,21 @@ static struct st_mysql_show_var mrn_status_variables[] = {NullS, NullS, SHOW_LONG} }; -static const char *mrn_log_level_type_names[] = { "NONE", "EMERG", "ALERT", - "CRIT", "ERROR", "WARNING", - "NOTICE", "INFO", "DEBUG", - "DUMP", NullS }; -static TYPELIB mrn_log_level_typelib = -{ - array_elements(mrn_log_level_type_names)-1, +static const char *mrn_log_level_type_names[] = { + "NONE", + "EMERG", + "ALERT", + "CRIT", + "ERROR", + "WARNING", + "NOTICE", + "INFO", + "DEBUG", + "DUMP", + NullS +}; +static TYPELIB mrn_log_level_typelib = { + array_elements(mrn_log_level_type_names) - 1, "mrn_log_level_typelib", mrn_log_level_type_names, NULL @@ -678,7 +729,7 @@ static void mrn_log_file_update(THD *thd, struct st_mysql_sys_var *var, #ifdef MRN_NEED_FREE_STRING_MEMALLOC_PLUGIN_VAR char *old_log_file_name = *old_value_ptr; *old_value_ptr = my_strdup(new_log_file_name, MYF(MY_WME)); - my_free(old_log_file_name, MYF(0)); + my_free(old_log_file_name); #else *old_value_ptr = my_strdup(new_log_file_name, MYF(MY_WME)); #endif @@ -717,7 +768,7 @@ static void mrn_default_parser_update(THD *thd, struct st_mysql_sys_var *var, } #ifdef MRN_NEED_FREE_STRING_MEMALLOC_PLUGIN_VAR - my_free(*old_value_ptr, MYF(0)); + my_free(*old_value_ptr); *old_value_ptr = my_strdup(new_value, MYF(MY_WME)); #else *old_value_ptr = (char *)new_value; @@ -771,7 +822,7 @@ static void mrn_vector_column_delimiter_update(THD *thd, struct st_mysql_sys_var char **old_value_ptr = (char **)var_ptr; #ifdef MRN_NEED_FREE_STRING_MEMALLOC_PLUGIN_VAR - my_free(*old_value_ptr, MYF(0)); + my_free(*old_value_ptr); *old_value_ptr = my_strdup(new_value, MYF(MY_WME)); #else *old_value_ptr = (char *)new_value; @@ -796,7 +847,7 @@ static void mrn_database_path_prefix_update(THD *thd, char **old_value_ptr = (char **)var_ptr; #ifdef MRN_NEED_FREE_STRING_MEMALLOC_PLUGIN_VAR if (*old_value_ptr) - my_free(*old_value_ptr, MYF(0)); + my_free(*old_value_ptr); if (new_value) *old_value_ptr = my_strdup(new_value, MYF(MY_WME)); else @@ -876,6 +927,58 @@ static MYSQL_SYSVAR_STR(version, mrn_version, NULL, MRN_VERSION); +static my_bool grn_check_zlib_support() +{ + bool is_zlib_support = false; + grn_obj grn_support_p; + + GRN_BOOL_INIT(&grn_support_p, 0); + grn_obj_get_info(&mrn_ctx, NULL, GRN_INFO_SUPPORT_ZLIB, &grn_support_p); + is_zlib_support = (GRN_BOOL_VALUE(&grn_support_p)); + grn_obj_unlink(&mrn_ctx, &grn_support_p); + + return is_zlib_support; +} + +static my_bool grn_check_lz4_support() +{ + bool is_lz4_support = false; + grn_obj grn_support_p; + + GRN_BOOL_INIT(&grn_support_p, 0); + grn_obj_get_info(&mrn_ctx, NULL, GRN_INFO_SUPPORT_LZ4, &grn_support_p); + is_lz4_support = (GRN_BOOL_VALUE(&grn_support_p)); + grn_obj_unlink(&mrn_ctx, &grn_support_p); + + return is_lz4_support; +} + +static MYSQL_SYSVAR_BOOL(libgroonga_support_zlib, mrn_libgroonga_support_zlib, + PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY, + "The status of libgroonga supports zlib", + NULL, + NULL, + grn_check_zlib_support()); + +static MYSQL_SYSVAR_BOOL(libgroonga_support_lz4, mrn_libgroonga_support_lz4, + PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY, + "The status of libgroonga supports LZ4", + NULL, + NULL, + grn_check_lz4_support()); + +static MYSQL_THDVAR_SET(boolean_mode_syntax_flags, + PLUGIN_VAR_RQCMDARG, + "The flags to custom syntax in BOOLEAN MODE. " + "Available flags: " + "DEFAULT(=SYNTAX_QUERY,ALLOW_LEADING_NOT), " + "SYNTAX_QUERY, SYNTAX_SCRIPT, " + "ALLOW_COLUMN, ALLOW_UPDATE and ALLOW_LEADING_NOT", + NULL, + NULL, + MRN_BOOLEAN_MODE_SYNTAX_FLAG_DEFAULT, + &mrn_boolean_mode_syntax_flags_typelib); + static struct st_mysql_sys_var *mrn_system_variables[] = { MYSQL_SYSVAR(log_level), @@ -891,6 +994,9 @@ static struct st_mysql_sys_var *mrn_system_variables[] = MYSQL_SYSVAR(libgroonga_version), MYSQL_SYSVAR(version), MYSQL_SYSVAR(vector_column_delimiter), + MYSQL_SYSVAR(libgroonga_support_zlib), + MYSQL_SYSVAR(libgroonga_support_lz4), + MYSQL_SYSVAR(boolean_mode_syntax_flags), NULL }; @@ -917,7 +1023,7 @@ static ST_FIELD_INFO i_s_mrn_stats_fields_info[] = MYSQL_TYPE_LONG, 0, 0, - "Rows written to groonga", + "Rows written to Groonga", SKIP_OPEN_TABLE }, { @@ -926,7 +1032,7 @@ static ST_FIELD_INFO i_s_mrn_stats_fields_info[] = MYSQL_TYPE_LONG, 0, 0, - "Rows read from groonga", + "Rows read from Groonga", SKIP_OPEN_TABLE } }; @@ -1191,6 +1297,65 @@ static grn_builtin_type mrn_grn_type_from_field(grn_ctx *ctx, Field *field, return type; } +grn_obj_flags mrn_parse_grn_column_create_flags(THD *thd, + grn_ctx *ctx, + const char *flag_names, + uint flag_names_length) +{ + grn_obj_flags flags = 0; + const char *flag_names_end = flag_names + flag_names_length; + + while (flag_names < flag_names_end) { + uint rest_length = flag_names_end - flag_names; + + if (*flag_names == '|' || *flag_names == ' ') { + flag_names += 1; + continue; + } + if (rest_length >= 13 && !memcmp(flag_names, "COLUMN_SCALAR", 13)) { + flags |= GRN_OBJ_COLUMN_SCALAR; + flag_names += 13; + } else if (rest_length >= 13 && !memcmp(flag_names, "COLUMN_VECTOR", 13)) { + flags |= GRN_OBJ_COLUMN_VECTOR; + flag_names += 13; + } else if (rest_length >= 13 && !memcmp(flag_names, "COMPRESS_ZLIB", 13)) { + if (mrn_libgroonga_support_zlib) { + flags |= GRN_OBJ_COMPRESS_ZLIB; + } else { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_MRN_UNSUPPORTED_COLUMN_FLAG_NUM, + ER_MRN_UNSUPPORTED_COLUMN_FLAG_STR, + "COMPRESS_ZLIB"); + } + flag_names += 13; + } else if (rest_length >= 12 && !memcmp(flag_names, "COMPRESS_LZ4", 12)) { + if (mrn_libgroonga_support_lz4) { + flags |= GRN_OBJ_COMPRESS_LZ4; + } else { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_MRN_UNSUPPORTED_COLUMN_FLAG_NUM, + ER_MRN_UNSUPPORTED_COLUMN_FLAG_STR, + "COMPRESS_LZ4"); + } + flag_names += 12; + } else { + char invalid_flag_name[MRN_MESSAGE_BUFFER_SIZE]; + snprintf(invalid_flag_name, MRN_MESSAGE_BUFFER_SIZE, + "%.*s", + static_cast(rest_length), + flag_names); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_MRN_INVALID_COLUMN_FLAG_NUM, + ER_MRN_INVALID_COLUMN_FLAG_STR, + invalid_flag_name, + "COLUMN_SCALAR"); + flags |= GRN_OBJ_COLUMN_SCALAR; + break; + } + } + return flags; +} + #ifdef HAVE_SPATIAL static int mrn_set_geometry(grn_ctx *ctx, grn_obj *buf, const char *wkb, uint wkb_size) @@ -1275,7 +1440,7 @@ static int mrn_init(void *p) hton = (handlerton *)p; hton->state = SHOW_OPTION_YES; hton->create = mrn_handler_create; - hton->flags = HTON_NO_PARTITION; + hton->flags = 0; hton->drop_database = mrn_drop_database; hton->close_connection = mrn_close_connection; hton->flush_logs = mrn_flush_logs; @@ -1294,13 +1459,8 @@ static int mrn_init(void *p) # endif # ifndef MRN_HAVE_TDC_LOCK_TABLE_SHARE mrn_LOCK_open = -# if MYSQL_VERSION_ID >= 50500 (mysql_mutex_t *)GetProcAddress(current_module, "?LOCK_open@@3Ust_mysql_mutex@@A"); -# else - (pthread_mutex_t *)GetProcAddress(current_module, - "?LOCK_open@@3U_RTL_CRITICAL_SECTION@@A"); -# endif # endif # ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE mrn_table_share_lock_share = @@ -1321,7 +1481,14 @@ static int mrn_init(void *p) # endif #endif - // init groonga +#ifdef HAVE_PSI_INTERFACE + if (PSI_server) { + const char *category = "mroonga"; + int n_mutexes = array_elements(mrn_mutexes); + PSI_server->register_mutex(category, mrn_mutexes, n_mutexes); + } +#endif + if (grn_init() != GRN_SUCCESS) { goto err_grn_init; } @@ -1335,7 +1502,9 @@ static int mrn_init(void *p) if (mrn_change_encoding(ctx, system_charset_info)) goto err_mrn_change_encoding; - if (pthread_mutex_init(&mrn_log_mutex, NULL) != 0) { + if (mysql_mutex_init(mrn_log_mutex_key, + &mrn_log_mutex, + MY_MUTEX_INIT_FAST) != 0) { goto err_log_mutex_init; } @@ -1358,25 +1527,39 @@ static int mrn_init(void *p) grn_ctx_init(&mrn_db_manager_ctx, 0); grn_logger_set(&mrn_db_manager_ctx, &mrn_logger); - mrn_db_manager = new mrn::DatabaseManager(&mrn_db_manager_ctx); + if (mysql_mutex_init(mrn_db_manager_mutex_key, + &mrn_db_manager_mutex, + MY_MUTEX_INIT_FAST) != 0) { + GRN_LOG(&mrn_db_manager_ctx, GRN_LOG_ERROR, + "failed to initialize mutex for database manager"); + goto err_db_manager_mutex_init; + } + mrn_db_manager = new mrn::DatabaseManager(&mrn_db_manager_ctx, + &mrn_db_manager_mutex); if (!mrn_db_manager->init()) { goto err_db_manager_init; } - if ((pthread_mutex_init(&mrn_allocated_thds_mutex, NULL) != 0)) { + if ((mysql_mutex_init(mrn_allocated_thds_mutex_key, + &mrn_allocated_thds_mutex, + MY_MUTEX_INIT_FAST) != 0)) { goto err_allocated_thds_mutex_init; } if (my_hash_init(&mrn_allocated_thds, system_charset_info, 32, 0, 0, mrn_allocated_thds_get_key, 0, 0)) { goto error_allocated_thds_hash_init; } - if ((pthread_mutex_init(&mrn_open_tables_mutex, NULL) != 0)) { + if ((mysql_mutex_init(mrn_open_tables_mutex_key, + &mrn_open_tables_mutex, + MY_MUTEX_INIT_FAST) != 0)) { goto err_allocated_open_tables_mutex_init; } if (my_hash_init(&mrn_open_tables, system_charset_info, 32, 0, 0, mrn_open_tables_get_key, 0, 0)) { goto error_allocated_open_tables_hash_init; } - if ((pthread_mutex_init(&mrn_long_term_share_mutex, NULL) != 0)) { + if ((mysql_mutex_init(mrn_long_term_share_mutex_key, + &mrn_long_term_share_mutex, + MY_MUTEX_INIT_FAST) != 0)) { goto error_allocated_long_term_share_mutex_init; } if (my_hash_init(&mrn_long_term_share, system_charset_info, 32, 0, 0, @@ -1391,18 +1574,20 @@ static int mrn_init(void *p) return 0; error_allocated_long_term_share_hash_init: - pthread_mutex_destroy(&mrn_long_term_share_mutex); + mysql_mutex_destroy(&mrn_long_term_share_mutex); error_allocated_long_term_share_mutex_init: my_hash_free(&mrn_open_tables); error_allocated_open_tables_hash_init: - pthread_mutex_destroy(&mrn_open_tables_mutex); + mysql_mutex_destroy(&mrn_open_tables_mutex); err_allocated_open_tables_mutex_init: my_hash_free(&mrn_allocated_thds); error_allocated_thds_hash_init: - pthread_mutex_destroy(&mrn_allocated_thds_mutex); + mysql_mutex_destroy(&mrn_allocated_thds_mutex); err_allocated_thds_mutex_init: err_db_manager_init: delete mrn_db_manager; + mysql_mutex_destroy(&mrn_db_manager_mutex); +err_db_manager_mutex_init: grn_ctx_fin(&mrn_db_manager_ctx); grn_obj_unlink(ctx, mrn_db); err_db_create: @@ -1411,7 +1596,7 @@ err_db_create: mrn_log_file_opened = false; } err_log_file_open: - pthread_mutex_destroy(&mrn_log_mutex); + mysql_mutex_destroy(&mrn_log_mutex); err_log_mutex_init: err_mrn_change_encoding: grn_ctx_fin(ctx); @@ -1450,12 +1635,13 @@ static int mrn_deinit(void *p) } my_hash_free(&mrn_long_term_share); - pthread_mutex_destroy(&mrn_long_term_share_mutex); + mysql_mutex_destroy(&mrn_long_term_share_mutex); my_hash_free(&mrn_open_tables); - pthread_mutex_destroy(&mrn_open_tables_mutex); + mysql_mutex_destroy(&mrn_open_tables_mutex); my_hash_free(&mrn_allocated_thds); - pthread_mutex_destroy(&mrn_allocated_thds_mutex); + mysql_mutex_destroy(&mrn_allocated_thds_mutex); delete mrn_db_manager; + mysql_mutex_destroy(&mrn_db_manager_mutex); grn_ctx_fin(&mrn_db_manager_ctx); grn_obj_unlink(ctx, mrn_db); @@ -1466,7 +1652,7 @@ static int mrn_deinit(void *p) fclose(mrn_log_file); mrn_log_file_opened = false; } - pthread_mutex_destroy(&mrn_log_mutex); + mysql_mutex_destroy(&mrn_log_mutex); return 0; } @@ -1489,6 +1675,18 @@ mrn_declare_plugin(MRN_PLUGIN_NAME) i_s_mrn_stats mrn_declare_plugin_end; +static double mrn_get_score_value(grn_obj *score) +{ + MRN_DBUG_ENTER_FUNCTION(); + double score_value; + if (score->header.domain == GRN_DB_FLOAT) { + score_value = GRN_FLOAT_VALUE(score); + } else { + score_value = (double)GRN_INT32_VALUE(score); + } + DBUG_RETURN(score_value); +} + static void mrn_generic_ft_clear(FT_INFO *handler) { MRN_DBUG_ENTER_FUNCTION(); @@ -1555,7 +1753,7 @@ static float mrn_wrapper_ft_find_relevance(FT_INFO *handler, uchar *record, GRN_BULK_REWIND(&(info->score)); grn_obj_get_value(info->ctx, info->score_column, result_record_id, &(info->score)); - score = (float)GRN_INT32_VALUE(&(info->score)); + score = mrn_get_score_value(&(info->score)); } } @@ -1593,7 +1791,7 @@ static float mrn_wrapper_ft_get_relevance(FT_INFO *handler) GRN_BULK_REWIND(&(info->score)); grn_obj_get_value(info->ctx, info->score_column, result_record_id, &(info->score)); - score = (float)GRN_INT32_VALUE(&(info->score)); + score = mrn_get_score_value(&(info->score)); } } @@ -1640,7 +1838,7 @@ static float mrn_storage_ft_find_relevance(FT_INFO *handler, uchar *record, GRN_BULK_REWIND(&(info->score)); grn_obj_get_value(info->ctx, info->score_column, result_record_id, &(info->score)); - score = (float)GRN_INT32_VALUE(&(info->score)); + score = mrn_get_score_value(&(info->score)); } } DBUG_PRINT("info", ("mroonga: record_id=%d score=%g", @@ -1672,7 +1870,7 @@ static float mrn_storage_ft_get_relevance(FT_INFO *handler) GRN_BULK_REWIND(&(info->score)); grn_obj_get_value(info->ctx, info->score_column, result_record_id, &(info->score)); - score = (float)GRN_INT32_VALUE(&(info->score)); + score = mrn_get_score_value(&(info->score)); } } DBUG_PRINT("info", @@ -1916,7 +2114,6 @@ ha_mroonga::ha_mroonga(handlerton *hton, TABLE_SHARE *share_arg) grn_column_ranges(NULL), grn_index_tables(NULL), grn_index_columns(NULL), - grn_table_is_referenced(false), grn_source_column_geo(NULL), cursor_geo(NULL), @@ -2126,7 +2323,7 @@ uint ha_mroonga::wrapper_max_supported_key_length() const uint ha_mroonga::storage_max_supported_key_length() const { MRN_DBUG_ENTER_METHOD(); - DBUG_RETURN(HA_MAX_REC_LENGTH); + DBUG_RETURN(GRN_TABLE_MAX_KEY_SIZE); } uint ha_mroonga::max_supported_key_length() const @@ -2173,7 +2370,7 @@ uint ha_mroonga::wrapper_max_supported_key_part_length() const uint ha_mroonga::storage_max_supported_key_part_length() const { MRN_DBUG_ENTER_METHOD(); - DBUG_RETURN(HA_MAX_REC_LENGTH); + DBUG_RETURN(GRN_TABLE_MAX_KEY_SIZE); } uint ha_mroonga::max_supported_key_part_length() const @@ -2467,7 +2664,7 @@ int ha_mroonga::wrapper_create(const char *name, TABLE *table, share = NULL; if (wrap_key_info) { - my_free(wrap_key_info, MYF(0)); + my_free(wrap_key_info); wrap_key_info = NULL; } base_key_info = NULL; @@ -2486,7 +2683,7 @@ int ha_mroonga::wrapper_create(const char *name, TABLE *table, if (wrap_key_info) { - my_free(wrap_key_info, MYF(0)); + my_free(wrap_key_info); wrap_key_info = NULL; } base_key_info = NULL; @@ -2838,9 +3035,9 @@ int ha_mroonga::storage_create(const char *name, TABLE *table, if (key_parts == 1) { grn_obj *normalizer = NULL; if (tmp_share->normalizer) { - normalizer = grn_ctx_get(ctx, - tmp_share->normalizer, - tmp_share->normalizer_length); + normalizer = grn_ctx_get(ctx, + tmp_share->normalizer, + tmp_share->normalizer_length); } else { Field *field = &(key_info.key_part->field[0]); if (should_normalize(field)) { @@ -2902,12 +3099,10 @@ int ha_mroonga::storage_create(const char *name, TABLE *table, grn_obj_flags col_flags = GRN_OBJ_PERSISTENT; if (tmp_share->col_flags[i]) { - // TODO: parse flags - if (strcmp(tmp_share->col_flags[i], "COLUMN_VECTOR") == 0) { - col_flags |= GRN_OBJ_COLUMN_VECTOR; - } else { - col_flags |= GRN_OBJ_COLUMN_SCALAR; - } + col_flags |= mrn_parse_grn_column_create_flags(ha_thd(), + ctx, + tmp_share->col_flags[i], + tmp_share->col_flags_length[i]); } else { col_flags |= GRN_OBJ_COLUMN_SCALAR; } @@ -3448,7 +3643,8 @@ int ha_mroonga::storage_create_indexes(TABLE *table, const char *grn_table_name, } if (error) { while (true) { - if (index_tables[i]) { + if (index_tables[i] && + !(tmp_share->index_table && tmp_share->index_table[i])) { grn_obj_remove(ctx, index_tables[i]); } if (!i) @@ -3574,7 +3770,7 @@ int ha_mroonga::wrapper_open(const char *name, int mode, uint test_if_locked) MRN_SET_BASE_TABLE_KEY(this, table); if (wrap_key_info) { - my_free(wrap_key_info, MYF(0)); + my_free(wrap_key_info); wrap_key_info = NULL; } base_key_info = NULL; @@ -3598,7 +3794,7 @@ int ha_mroonga::wrapper_open(const char *name, int mode, uint test_if_locked) MRN_SET_BASE_TABLE_KEY(this, table); if (wrap_key_info) { - my_free(wrap_key_info, MYF(0)); + my_free(wrap_key_info); wrap_key_info = NULL; } base_key_info = NULL; @@ -3626,7 +3822,7 @@ int ha_mroonga::wrapper_open(const char *name, int mode, uint test_if_locked) wrap_handler = NULL; if (wrap_key_info) { - my_free(wrap_key_info, MYF(0)); + my_free(wrap_key_info); wrap_key_info = NULL; } base_key_info = NULL; @@ -3806,55 +4002,6 @@ int ha_mroonga::storage_open(const char *name, int mode, uint test_if_locked) DBUG_RETURN(0); } -void ha_mroonga::update_grn_table_is_referenced() -{ - MRN_DBUG_ENTER_METHOD(); - - grn_table_is_referenced = false; - - grn_table_cursor *cursor; - int flags = GRN_CURSOR_BY_ID | GRN_CURSOR_ASCENDING;; - cursor = grn_table_cursor_open(ctx, grn_ctx_db(ctx), - NULL, 0, - NULL, 0, - 0, -1, flags); - if (cursor) { - grn_id id; - grn_id grn_table_id; - - grn_table_id = grn_obj_id(ctx, grn_table); - while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) { - grn_obj *object; - grn_id range = GRN_ID_NIL; - - object = grn_ctx_at(ctx, id); - if (!object) { - ctx->rc = GRN_SUCCESS; - continue; - } - - switch (object->header.type) { - case GRN_COLUMN_FIX_SIZE: - case GRN_COLUMN_VAR_SIZE: - range = grn_obj_get_range(ctx, object); - break; - default: - break; - } - grn_obj_unlink(ctx, object); - - if (range == grn_table_id) { - grn_table_is_referenced = true; - break; - } - } - - grn_table_cursor_close(ctx, cursor); - } - - DBUG_VOID_RETURN; -} - int ha_mroonga::open_table(const char *name) { int error; @@ -3881,8 +4028,6 @@ int ha_mroonga::open_table(const char *name) DBUG_RETURN(error); } - update_grn_table_is_referenced(); - DBUG_RETURN(0); } @@ -4104,7 +4249,7 @@ int ha_mroonga::wrapper_close() wrap_handler = NULL; if (wrap_key_info) { - my_free(wrap_key_info, MYF(0)); + my_free(wrap_key_info); wrap_key_info = NULL; } base_key_info = NULL; @@ -4323,7 +4468,6 @@ int ha_mroonga::delete_table(const char *name) } if (!tmp_table_share) { - mrn::PathMapper mapper(name); #ifdef MRN_TABLE_LIST_INIT_REQUIRE_ALIAS table_list.init_one_table(mapper.db_name(), strlen(mapper.db_name()), mapper.mysql_table_name(), @@ -5090,6 +5234,7 @@ int ha_mroonga::storage_write_row(uchar *buf) { MRN_DBUG_ENTER_METHOD(); int error = 0; + bool unique_indexes_are_processed = false; if (is_dry_write()) { DBUG_PRINT("info", ("mroonga: dry write: ha_mroonga::%s", __FUNCTION__)); @@ -5098,7 +5243,6 @@ int ha_mroonga::storage_write_row(uchar *buf) THD *thd = ha_thd(); int i; - uint j; int n_columns = table->s->fields; if (table->next_number_field && buf == table->record[0]) @@ -5156,6 +5300,11 @@ int ha_mroonga::storage_write_row(uchar *buf) } } + if (grn_table->header.type != GRN_TABLE_NO_KEY && pkey_size == 0) { + my_message(ER_ERROR_ON_WRITE, "primary key is empty", MYF(0)); + DBUG_RETURN(ER_ERROR_ON_WRITE); + } + int added; record_id = grn_table_add(ctx, grn_table, pkey, pkey_size, &added); if (ctx->rc) { @@ -5179,6 +5328,7 @@ int ha_mroonga::storage_write_row(uchar *buf) { goto err; } + unique_indexes_are_processed = true; grn_obj colbuf; GRN_VOID_INIT(&colbuf); @@ -5270,13 +5420,16 @@ int ha_mroonga::storage_write_row(uchar *buf) DBUG_RETURN(0); err: - for (j = 0; j < table->s->keys; j++) { - if (j == pkey_nr) { - continue; - } - KEY *key_info = &table->key_info[j]; - if (key_info->flags & HA_NOSAME) { - grn_table_delete_by_id(ctx, grn_index_tables[j], key_id[j]); + if (unique_indexes_are_processed) { + uint j; + for (j = 0; j < table->s->keys; j++) { + if (j == pkey_nr) { + continue; + } + KEY *key_info = &table->key_info[j]; + if (key_info->flags & HA_NOSAME) { + grn_table_delete_by_id(ctx, grn_index_tables[j], key_id[j]); + } } } grn_table_delete_by_id(ctx, grn_table, record_id); @@ -5363,6 +5516,7 @@ err: int ha_mroonga::storage_write_row_unique_index(uchar *buf, KEY *key_info, grn_obj *index_table, + grn_obj *index_column, grn_id *key_id) { char *ukey = NULL; @@ -5398,7 +5552,29 @@ int ha_mroonga::storage_write_row_unique_index(uchar *buf, if (!added) { // duplicated error error = HA_ERR_FOUND_DUPP_KEY; - memcpy(dup_ref, key_id, sizeof(grn_id)); + grn_id duplicated_record_id = GRN_ID_NIL; + { + grn_table_cursor *table_cursor; + table_cursor = grn_table_cursor_open(ctx, index_table, + ukey, ukey_size, + ukey, ukey_size, + 0, -1, 0); + if (table_cursor) { + grn_obj *index_cursor; + index_cursor = grn_index_cursor_open(ctx, table_cursor, index_column, + GRN_ID_NIL, GRN_ID_MAX, 0); + if (index_cursor) { + grn_posting *posting; + posting = grn_index_cursor_next(ctx, index_cursor, NULL); + if (posting) { + duplicated_record_id = posting->rid; + } + } + grn_obj_unlink(ctx, index_cursor); + } + grn_table_cursor_close(ctx, table_cursor); + } + memcpy(dup_ref, &duplicated_record_id, sizeof(grn_id)); if (!ignoring_duplicated_key) { GRN_LOG(ctx, GRN_LOG_ERROR, "duplicated id on insert: update unique index: <%.*s>", @@ -5431,9 +5607,14 @@ int ha_mroonga::storage_write_row_unique_indexes(uchar *buf) if (!index_table) { continue; } + grn_obj *index_column = grn_index_columns[i]; + if (!index_column) { + continue; + } if ((error = storage_write_row_unique_index(buf, key_info, - index_table, &key_id[i]))) + index_table, index_column, + &key_id[i]))) { if (error == HA_ERR_FOUND_DUPP_KEY) { @@ -5449,7 +5630,16 @@ err: mrn_change_encoding(ctx, NULL); do { i--; + + if (i == table->s->primary_key) { + continue; + } + KEY *key_info = &table->key_info[i]; + if (!(key_info->flags & HA_NOSAME)) { + continue; + } + if (key_info->flags & HA_NOSAME) { grn_table_delete_by_id(ctx, grn_index_tables[i], key_id[i]); } @@ -5914,6 +6104,13 @@ int ha_mroonga::storage_update_row_unique_indexes(uchar *new_data) continue; } + grn_obj *index_column = grn_index_columns[i]; + if (!index_column) { + key_id[i] = GRN_ID_NIL; + del_key_id[i] = GRN_ID_NIL; + continue; + } + if ( KEY_N_KEY_PARTS(key_info) == 1 && !bitmap_is_set(table->write_set, @@ -5926,7 +6123,8 @@ int ha_mroonga::storage_update_row_unique_indexes(uchar *new_data) } if ((error = storage_write_row_unique_index(new_data, key_info, - index_table, &key_id[i]))) + index_table, index_column, + &key_id[i]))) { if (error == HA_ERR_FOUND_DUPP_KEY) { @@ -6276,24 +6474,34 @@ int ha_mroonga::delete_row(const uchar *buf) DBUG_RETURN(error); } -uint ha_mroonga::wrapper_max_supported_key_parts() +uint ha_mroonga::wrapper_max_supported_key_parts() const { MRN_DBUG_ENTER_METHOD(); DBUG_RETURN(MAX_REF_PARTS); } -uint ha_mroonga::storage_max_supported_key_parts() +uint ha_mroonga::storage_max_supported_key_parts() const { MRN_DBUG_ENTER_METHOD(); - DBUG_RETURN(1); + DBUG_RETURN(MAX_REF_PARTS); } -uint ha_mroonga::max_supported_key_parts() +uint ha_mroonga::max_supported_key_parts() const { MRN_DBUG_ENTER_METHOD(); uint parts; - if (share->wrapper_mode) - { + if (!share && !analyzed_for_create && + ( + thd_sql_command(ha_thd()) == SQLCOM_CREATE_TABLE || + thd_sql_command(ha_thd()) == SQLCOM_CREATE_INDEX || + thd_sql_command(ha_thd()) == SQLCOM_ALTER_TABLE + ) + ) { + create_share_for_create(); + } + if (analyzed_for_create && share_for_create.wrapper_mode) { + parts = wrapper_max_supported_key_parts(); + } else if (wrap_handler && share && share->wrapper_mode) { parts = wrapper_max_supported_key_parts(); } else { parts = storage_max_supported_key_parts(); @@ -7594,6 +7802,34 @@ bool ha_mroonga::generic_ft_init_ext_parse_pragma_w(struct st_mrn_ft_info *info, DBUG_RETURN(n_weights > 0); } +grn_expr_flags ha_mroonga::expr_flags_in_boolean_mode() +{ + MRN_DBUG_ENTER_METHOD(); + + ulonglong syntax_flags = THDVAR(ha_thd(), boolean_mode_syntax_flags); + grn_expr_flags expression_flags = 0; + if (syntax_flags == MRN_BOOLEAN_MODE_SYNTAX_FLAG_DEFAULT) { + expression_flags = GRN_EXPR_SYNTAX_QUERY | GRN_EXPR_ALLOW_LEADING_NOT; + } else { + if (syntax_flags & MRN_BOOLEAN_MODE_SYNTAX_FLAG_SYNTAX_SCRIPT) { + expression_flags |= GRN_EXPR_SYNTAX_SCRIPT; + } else { + expression_flags |= GRN_EXPR_SYNTAX_QUERY; + } + if (syntax_flags & MRN_BOOLEAN_MODE_SYNTAX_FLAG_ALLOW_COLUMN) { + expression_flags |= GRN_EXPR_ALLOW_COLUMN; + } + if (syntax_flags & MRN_BOOLEAN_MODE_SYNTAX_FLAG_ALLOW_UPDATE) { + expression_flags |= GRN_EXPR_ALLOW_UPDATE; + } + if (syntax_flags & MRN_BOOLEAN_MODE_SYNTAX_FLAG_ALLOW_LEADING_NOT) { + expression_flags |= GRN_EXPR_ALLOW_LEADING_NOT; + } + } + + DBUG_RETURN(expression_flags); +} + grn_rc ha_mroonga::generic_ft_init_ext_prepare_expression_in_boolean_mode( struct st_mrn_ft_info *info, String *key, @@ -7674,12 +7910,10 @@ grn_rc ha_mroonga::generic_ft_init_ext_prepare_expression_in_boolean_mode( if (!weight_specified) { grn_expr_append_obj(info->ctx, match_columns, index_column, GRN_OP_PUSH, 1); } - grn_expr_flags expression_flags = - GRN_EXPR_SYNTAX_QUERY | GRN_EXPR_ALLOW_LEADING_NOT; rc = grn_expr_parse(info->ctx, expression, keyword, keyword_length, match_columns, GRN_OP_MATCH, default_operator, - expression_flags); + expr_flags_in_boolean_mode()); if (rc) { char error_message[MRN_MESSAGE_BUFFER_SIZE]; snprintf(error_message, MRN_MESSAGE_BUFFER_SIZE, @@ -8351,7 +8585,8 @@ int ha_mroonga::drop_index(MRN_SHARE *target_share, uint key_index) const char *table_name = target_share->index_table[key_index]; snprintf(target_name, GRN_TABLE_MAX_KEY_SIZE, "%s.%s", table_name, key_info[key_index].name); - grn_obj *index_column = grn_ctx_get(ctx, target_name, strlen(target_name)); + target_name_length = strlen(target_name); + grn_obj *index_column = grn_ctx_get(ctx, target_name, target_name_length); if (index_column) { rc = grn_obj_remove(ctx, index_column); } @@ -8366,6 +8601,8 @@ int ha_mroonga::drop_index(MRN_SHARE *target_share, uint key_index) target_name_length = grn_obj_name(ctx, index_table, target_name, GRN_TABLE_MAX_KEY_SIZE); rc = grn_obj_remove(ctx, index_table); + } else { + target_name_length = 0; } } @@ -8421,6 +8658,7 @@ grn_obj *ha_mroonga::find_normalizer(KEY *key_info) { MRN_DBUG_ENTER_METHOD(); grn_obj *normalizer = NULL; + bool use_normalizer = true; #if MYSQL_VERSION_ID >= 50500 if (key_info->comment.length > 0) { mrn::ParametersParser parser(key_info->comment.str, @@ -8428,11 +8666,15 @@ grn_obj *ha_mroonga::find_normalizer(KEY *key_info) parser.parse(); const char *normalizer_name = parser["normalizer"]; if (normalizer_name) { - normalizer = grn_ctx_get(ctx, normalizer_name, -1); + if (strcmp(normalizer_name, "none") == 0) { + use_normalizer = false; + } else { + normalizer = grn_ctx_get(ctx, normalizer_name, -1); + } } } #endif - if (!normalizer) { + if (use_normalizer && !normalizer) { Field *field = key_info->key_part[0].field; mrn::FieldNormalizer field_normalizer(ctx, ha_thd(), field); normalizer = field_normalizer.find_grn_normalizer(); @@ -9438,9 +9680,9 @@ int ha_mroonga::generic_store_bulk_blob(Field *field, grn_obj *buf) int error = 0; String buffer; Field_blob *blob = (Field_blob *)field; - const char *value = blob->val_str(0, &buffer)->ptr(); + String *value = blob->val_str(0, &buffer); grn_obj_reinit(ctx, buf, GRN_DB_TEXT, 0); - GRN_TEXT_SET(ctx, buf, value, blob->get_length()); + GRN_TEXT_SET(ctx, buf, value->ptr(), value->length()); DBUG_RETURN(error); } @@ -9451,8 +9693,9 @@ int ha_mroonga::generic_store_bulk_geometry(Field *field, grn_obj *buf) #ifdef HAVE_SPATIAL String buffer; Field_geom *geometry = (Field_geom *)field; - const char *wkb = geometry->val_str(0, &buffer)->ptr(); - int len = geometry->get_length(); + String *value = geometry->val_str(0, &buffer); + const char *wkb = value->ptr(); + int len = value->length(); error = mrn_set_geometry(ctx, buf, wkb, len); #endif DBUG_RETURN(error); @@ -9994,7 +10237,7 @@ void ha_mroonga::storage_store_field(Field *field, } } -void ha_mroonga::storage_store_field_column(Field *field, +void ha_mroonga::storage_store_field_column(Field *field, bool is_primary_key, int nth_column, grn_id record_id) { MRN_DBUG_ENTER_METHOD(); @@ -10009,7 +10252,6 @@ void ha_mroonga::storage_store_field_column(Field *field, grn_obj_reinit(ctx, value, range_id, GRN_OBJ_VECTOR); grn_obj_get_value(ctx, column, record_id, value); - // TODO: Check whether reference type or not grn_obj unvectored_value; GRN_TEXT_INIT(&unvectored_value, 0); int n_ids = GRN_BULK_VSIZE(value) / sizeof(grn_id); @@ -10042,7 +10284,15 @@ void ha_mroonga::storage_store_field_column(Field *field, } else { grn_obj_reinit(ctx, value, range_id, 0); grn_obj_get_value(ctx, column, record_id, value); - storage_store_field(field, GRN_BULK_HEAD(value), GRN_BULK_VSIZE(value)); + if (is_primary_key && GRN_BULK_VSIZE(value) == 0) { + char key[GRN_TABLE_MAX_KEY_SIZE]; + int key_length; + key_length = grn_table_get_key(ctx, grn_table, record_id, + &key, GRN_TABLE_MAX_KEY_SIZE); + storage_store_field(field, key, key_length); + } else { + storage_store_field(field, GRN_BULK_HEAD(value), GRN_BULK_VSIZE(value)); + } } DBUG_VOID_RETURN; @@ -10056,9 +10306,11 @@ void ha_mroonga::storage_store_fields(uchar *buf, grn_id record_id) my_ptrdiff_t ptr_diff = PTR_BYTE_DIFF(buf, table->record[0]); Field *primary_key_field = NULL; - if (grn_table_is_referenced && table->s->primary_key != MAX_INDEXES) { + if (table->s->primary_key != MAX_INDEXES) { KEY *key_info = &(table->s->key_info[table->s->primary_key]); - primary_key_field = key_info->key_part[0].field; + if (KEY_N_KEY_PARTS(key_info) == 1) { + primary_key_field = key_info->key_part[0].field; + } } int i; @@ -10087,13 +10339,9 @@ void ha_mroonga::storage_store_fields(uchar *buf, grn_id record_id) } else if (primary_key_field && strcmp(primary_key_field->field_name, column_name) == 0) { // for primary key column - char key[GRN_TABLE_MAX_KEY_SIZE]; - int key_length; - key_length = grn_table_get_key(ctx, grn_table, record_id, - &key, GRN_TABLE_MAX_KEY_SIZE); - storage_store_field(field, key, key_length); + storage_store_field_column(field, true, i, record_id); } else { - storage_store_field_column(field, i ,record_id); + storage_store_field_column(field, false, i, record_id); } field->move_field_offset(-ptr_diff); } @@ -10770,12 +11018,12 @@ int ha_mroonga::wrapper_reset() MRN_SET_BASE_TABLE_KEY(this, table); #ifdef MRN_HANDLER_HAVE_CHECK_IF_SUPPORTED_INPLACE_ALTER if (alter_key_info_buffer) { - my_free(alter_key_info_buffer, MYF(0)); + my_free(alter_key_info_buffer); alter_key_info_buffer = NULL; } #else if (wrap_alter_key_info) { - my_free(wrap_alter_key_info, MYF(0)); + my_free(wrap_alter_key_info); wrap_alter_key_info = NULL; } #endif @@ -11787,7 +12035,7 @@ void ha_mroonga::update_create_info(HA_CREATE_INFO* create_info) if (slot_data) { slot_data->alter_create_info = create_info; if (slot_data->alter_connect_string) { - my_free(slot_data->alter_connect_string, MYF(0)); + my_free(slot_data->alter_connect_string); slot_data->alter_connect_string = NULL; } if (create_info->connect_string.str) { @@ -11797,7 +12045,7 @@ void ha_mroonga::update_create_info(HA_CREATE_INFO* create_info) MYF(MY_WME)); } if (slot_data->alter_comment) { - my_free(slot_data->alter_comment, MYF(0)); + my_free(slot_data->alter_comment); slot_data->alter_comment = NULL; } if (create_info->comment.str) { @@ -12184,6 +12432,44 @@ bool ha_mroonga::auto_repair() const DBUG_RETURN(crashed); } +int ha_mroonga::generic_disable_index(int i, KEY *key_info) +{ + MRN_DBUG_ENTER_METHOD(); + + int error = 0; + if (share->index_table[i]) { + char index_column_name[GRN_TABLE_MAX_KEY_SIZE]; + snprintf(index_column_name, GRN_TABLE_MAX_KEY_SIZE - 1, + "%s.%s", share->index_table[i], key_info[i].name); + grn_obj *index_column = grn_ctx_get(ctx, + index_column_name, + strlen(index_column_name)); + if (index_column) { + grn_obj_remove(ctx, index_column); + } + } else { + mrn::PathMapper mapper(share->table_name); + mrn::IndexTableName index_table_name(mapper.table_name(), + key_info[i].name); + grn_obj *index_table = grn_ctx_get(ctx, + index_table_name.c_str(), + index_table_name.length()); + if (index_table) { + grn_obj_remove(ctx, index_table); + } + } + if (ctx->rc == GRN_SUCCESS) { + grn_index_tables[i] = NULL; + grn_index_columns[i] = NULL; + } else { + // TODO: Implement ctx->rc to error converter and use it. + error = ER_ERROR_ON_WRITE; + my_message(error, ctx->errbuf, MYF(0)); + } + + DBUG_RETURN(error); +} + int ha_mroonga::wrapper_disable_indexes(uint mode) { int error = 0; @@ -12212,23 +12498,16 @@ int ha_mroonga::wrapper_disable_indexes(uint mode) } } KEY *key_info = table_share->key_info; - mrn::PathMapper mapper(share->table_name); for (i = 0; i < table_share->keys; i++) { if (!(key_info[i].flags & HA_FULLTEXT) && !mrn_is_geo_key(&key_info[i])) { continue; } - mrn::IndexTableName index_table_name(mapper.table_name(), - key_info[i].name); - grn_obj *index_table = grn_ctx_get(ctx, - index_table_name.c_str(), - index_table_name.length()); - if (index_table) { - grn_obj_remove(ctx, index_table); + int sub_error = generic_disable_index(i, key_info); + if (error != 0 && sub_error != 0) { + error = sub_error; } - grn_index_tables[i] = NULL; - grn_index_columns[i] = NULL; } } else { error = HA_ERR_WRONG_COMMAND; @@ -12239,6 +12518,7 @@ int ha_mroonga::wrapper_disable_indexes(uint mode) int ha_mroonga::storage_disable_indexes(uint mode) { + int error = 0; MRN_DBUG_ENTER_METHOD(); if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE || mode == HA_KEY_SWITCH_ALL) { uint i; @@ -12252,7 +12532,6 @@ int ha_mroonga::storage_disable_indexes(uint mode) } } KEY *key_info = table_share->key_info; - mrn::PathMapper mapper(share->table_name); for (i = 0; i < table_share->keys; i++) { if (i == table->s->primary_key) { continue; @@ -12262,21 +12541,15 @@ int ha_mroonga::storage_disable_indexes(uint mode) continue; } - mrn::IndexTableName index_table_name(mapper.table_name(), - key_info[i].name); - grn_obj *index_table = grn_ctx_get(ctx, - index_table_name.c_str(), - index_table_name.length()); - if (index_table) { - grn_obj_remove(ctx, index_table); + int sub_error = generic_disable_index(i, key_info); + if (error != 0 && sub_error != 0) { + error = sub_error; } - grn_index_tables[i] = NULL; - grn_index_columns[i] = NULL; } } else { DBUG_RETURN(HA_ERR_WRONG_COMMAND); } - DBUG_RETURN(0); + DBUG_RETURN(error); } int ha_mroonga::disable_indexes(uint mode) @@ -12305,7 +12578,7 @@ int ha_mroonga::wrapper_enable_indexes(uint mode) if (share->wrap_key_nr[i] < MAX_KEY) { continue; } - if (!grn_index_tables[i]) { + if (!grn_index_columns[i]) { break; } } @@ -12334,7 +12607,7 @@ int ha_mroonga::wrapper_enable_indexes(uint mode) } index_tables[i] = NULL; index_columns[i] = NULL; - if (!grn_index_tables[i]) { + if (!grn_index_columns[i]) { if ( (key_info[i].flags & HA_FULLTEXT) && (error = wrapper_create_index_fulltext(mapper.table_name(), @@ -12394,7 +12667,7 @@ int ha_mroonga::storage_enable_indexes(uint mode) if (i == table->s->primary_key) { continue; } - if (!grn_index_tables[i]) { + if (!grn_index_columns[i]) { break; } } @@ -12420,7 +12693,7 @@ int ha_mroonga::storage_enable_indexes(uint mode) break; } index_tables[i] = NULL; - if (!grn_index_tables[i]) { + if (!grn_index_columns[i]) { if ((error = storage_create_index(table, mapper.table_name(), grn_table, share, &key_info[i], index_tables, index_columns, i))) @@ -12434,6 +12707,8 @@ int ha_mroonga::storage_enable_indexes(uint mode) mrn_set_bitmap_by_key(table->read_set, &key_info[i]); have_multiple_column_index = true; } + grn_index_tables[i] = index_tables[i]; + grn_index_columns[i] = index_columns[i]; } else { index_columns[i] = NULL; } @@ -12902,6 +13177,7 @@ int ha_mroonga::storage_add_index_multiple_columns(KEY *key_info, if ((error = storage_write_row_unique_index(table->record[0], current_key_info, index_tables[i], + index_columns[i], &key_id))) { if (error == HA_ERR_FOUND_DUPP_KEY) @@ -13308,7 +13584,7 @@ bool ha_mroonga::wrapper_inplace_alter_table( result = true; } mrn_free_share_alloc(tmp_share); - my_free(tmp_share, MYF(0)); + my_free(tmp_share); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_tables); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_columns); DBUG_RETURN(result); @@ -13434,6 +13710,12 @@ bool ha_mroonga::storage_inplace_alter_table_index( ha_alter_info->key_count, index_tables, index_columns, false); + if (error == HA_ERR_FOUND_DUPP_UNIQUE) { + my_printf_error(ER_DUP_UNIQUE, ER(ER_DUP_UNIQUE), MYF(0), + table_share->table_name); + } else if (error) { + my_message(error, "failed to create multiple column index", MYF(0)); + } for (i = 0; i < n_columns; ++i) { Field *field = altered_table->field[i]; field->move_field_offset(-ptr_diff); @@ -13460,7 +13742,7 @@ bool ha_mroonga::storage_inplace_alter_table_index( have_error = true; } mrn_free_share_alloc(tmp_share); - my_free(tmp_share, MYF(0)); + my_free(tmp_share); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_tables); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_columns); @@ -13532,12 +13814,10 @@ bool ha_mroonga::storage_inplace_alter_table_add_column( grn_obj_flags col_flags = GRN_OBJ_PERSISTENT; if (tmp_share->col_flags[i]) { - // TODO: parse flags - if (strcmp(tmp_share->col_flags[i], "COLUMN_VECTOR") == 0) { - col_flags |= GRN_OBJ_COLUMN_VECTOR; - } else { - col_flags |= GRN_OBJ_COLUMN_SCALAR; - } + col_flags |= mrn_parse_grn_column_create_flags(ha_thd(), + ctx, + tmp_share->col_flags[i], + tmp_share->col_flags_length[i]); } else { col_flags |= GRN_OBJ_COLUMN_SCALAR; } @@ -13570,7 +13850,7 @@ bool ha_mroonga::storage_inplace_alter_table_add_column( grn_obj_unlink(ctx, table_obj); mrn_free_share_alloc(tmp_share); - my_free(tmp_share, MYF(0)); + my_free(tmp_share); DBUG_RETURN(have_error); } @@ -13752,7 +14032,7 @@ bool ha_mroonga::wrapper_commit_inplace_alter_table( bool result; MRN_DBUG_ENTER_METHOD(); if (!alter_handler_flags) { - my_free(alter_key_info_buffer, MYF(0)); + my_free(alter_key_info_buffer); alter_key_info_buffer = NULL; DBUG_RETURN(false); } @@ -13765,7 +14045,7 @@ bool ha_mroonga::wrapper_commit_inplace_alter_table( MRN_SET_BASE_ALTER_KEY(this, ha_alter_info); MRN_SET_BASE_SHARE_KEY(share, table->s); MRN_SET_BASE_TABLE_KEY(this, table); - my_free(alter_key_info_buffer, MYF(0)); + my_free(alter_key_info_buffer); alter_key_info_buffer = NULL; DBUG_RETURN(result); } @@ -13990,7 +14270,7 @@ int ha_mroonga::wrapper_add_index(TABLE *table_arg, KEY *key_info, } #endif mrn_free_share_alloc(tmp_share); - my_free(tmp_share, MYF(0)); + my_free(tmp_share); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_tables); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_columns); DBUG_RETURN(error); @@ -14104,7 +14384,7 @@ int ha_mroonga::storage_add_index(TABLE *table_arg, KEY *key_info, } #endif mrn_free_share_alloc(tmp_share); - my_free(tmp_share, MYF(0)); + my_free(tmp_share); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_tables); MRN_FREE_VARIABLE_LENGTH_ARRAYS(index_columns); DBUG_RETURN(error); @@ -15277,7 +15557,7 @@ void ha_mroonga::wrapper_free_foreign_key_create_info(char* str) void ha_mroonga::storage_free_foreign_key_create_info(char* str) { MRN_DBUG_ENTER_METHOD(); - my_free(str, MYF(0)); + my_free(str); DBUG_VOID_RETURN; } #else diff --git a/storage/mroonga/ha_mroonga.hpp b/storage/mroonga/ha_mroonga.hpp index 224abb09732..a5379dbddbb 100644 --- a/storage/mroonga/ha_mroonga.hpp +++ b/storage/mroonga/ha_mroonga.hpp @@ -263,7 +263,6 @@ private: grn_obj **grn_column_ranges; grn_obj **grn_index_tables; grn_obj **grn_index_columns; - bool grn_table_is_referenced; // buffers grn_obj encoded_key_buffer; @@ -349,7 +348,7 @@ public: uint max_supported_record_length() const; uint max_supported_keys() const; - uint max_supported_key_parts(); + uint max_supported_key_parts() const; uint max_supported_key_length() const; uint max_supported_key_part_length() const; @@ -641,7 +640,7 @@ private: void storage_store_field_geometry(Field *field, const char *value, uint value_length); void storage_store_field(Field *field, const char *value, uint value_length); - void storage_store_field_column(Field *field, + void storage_store_field_column(Field *field, bool is_primary_key, int nth_column, grn_id record_id); void storage_store_fields(uchar *buf, grn_id record_id); void storage_store_fields_for_prep_update(const uchar *old_data, @@ -742,7 +741,6 @@ private: int wrapper_open(const char *name, int mode, uint test_if_locked); int wrapper_open_indexes(const char *name); int storage_open(const char *name, int mode, uint test_if_locked); - void update_grn_table_is_referenced(); int open_table(const char *name); int storage_open_columns(void); int storage_open_indexes(const char *name); @@ -785,7 +783,9 @@ private: grn_obj *index_column); int storage_write_row_multiple_column_indexes(uchar *buf, grn_id record_id); int storage_write_row_unique_index(uchar *buf, - KEY *key_info, grn_obj *index_table, + KEY *key_info, + grn_obj *index_table, + grn_obj *index_column, grn_id *key_id); int storage_write_row_unique_indexes(uchar *buf); int wrapper_get_record_id(uchar *data, grn_id *record_id, const char *context); @@ -812,8 +812,8 @@ private: uint storage_max_supported_record_length() const; uint wrapper_max_supported_keys() const; uint storage_max_supported_keys() const; - uint wrapper_max_supported_key_parts(); - uint storage_max_supported_key_parts(); + uint wrapper_max_supported_key_parts() const; + uint storage_max_supported_key_parts() const; uint wrapper_max_supported_key_length() const; uint storage_max_supported_key_length() const; uint wrapper_max_supported_key_part_length() const; @@ -904,6 +904,7 @@ private: grn_obj *match_columns, uint *consumed_keyword_length, grn_obj *tmp_objects); + grn_expr_flags expr_flags_in_boolean_mode(); grn_rc generic_ft_init_ext_prepare_expression_in_boolean_mode( struct st_mrn_ft_info *info, String *key, @@ -1029,6 +1030,7 @@ private: bool storage_is_crashed() const; bool wrapper_auto_repair(int error) const; bool storage_auto_repair(int error) const; + int generic_disable_index(int i, KEY *key_info); int wrapper_disable_indexes(uint mode); int storage_disable_indexes(uint mode); int wrapper_enable_indexes(uint mode); diff --git a/storage/mroonga/lib/mrn_database_manager.cpp b/storage/mroonga/lib/mrn_database_manager.cpp index 52ec78fccc0..365f47337fa 100644 --- a/storage/mroonga/lib/mrn_database_manager.cpp +++ b/storage/mroonga/lib/mrn_database_manager.cpp @@ -26,6 +26,8 @@ #include "mrn_lock.hpp" #include "mrn_path_mapper.hpp" +#include + // for debug #define MRN_CLASS_NAME "mrn::DatabaseManager" @@ -38,19 +40,19 @@ # define MRN_MKDIR(pathname, mode) mkdir((pathname), (mode)) #endif +extern "C" { + grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(init, normalizers_mysql)(grn_ctx *ctx); + grn_rc GRN_PLUGIN_IMPL_NAME_TAGGED(register, normalizers_mysql)(grn_ctx *ctx); +} + namespace mrn { - DatabaseManager::DatabaseManager(grn_ctx *ctx) + DatabaseManager::DatabaseManager(grn_ctx *ctx, mysql_mutex_t *mutex) : ctx_(ctx), cache_(NULL), - mutex_(), - mutex_initialized_(false) { + mutex_(mutex) { } DatabaseManager::~DatabaseManager(void) { - if (mutex_initialized_) { - pthread_mutex_destroy(&mutex_); - } - if (cache_) { void *db_address; GRN_HASH_EACH(ctx_, cache_, id, NULL, 0, &db_address, { @@ -75,13 +77,6 @@ namespace mrn { DBUG_RETURN(false); } - if (pthread_mutex_init(&mutex_, NULL) != 0) { - GRN_LOG(ctx_, GRN_LOG_ERROR, - "failed to initialize mutex for opened database cache hash table"); - DBUG_RETURN(false); - } - - mutex_initialized_ = true; DBUG_RETURN(true); } @@ -92,7 +87,7 @@ namespace mrn { *db = NULL; mrn::PathMapper mapper(path); - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); error = mrn::encoding::set(ctx_, system_charset_info); if (error) { @@ -145,7 +140,7 @@ namespace mrn { MRN_DBUG_ENTER_METHOD(); mrn::PathMapper mapper(path); - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); grn_id id; void *db_address; @@ -171,7 +166,7 @@ namespace mrn { MRN_DBUG_ENTER_METHOD(); mrn::PathMapper mapper(path); - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); grn_id id; void *db_address; @@ -211,7 +206,7 @@ namespace mrn { int error = 0; - mrn::Lock lock(&mutex_); + mrn::Lock lock(mutex_); grn_hash_cursor *cursor; cursor = grn_hash_cursor_open(ctx_, cache_, @@ -323,15 +318,12 @@ namespace mrn { if (mysql_normalizer) { grn_obj_unlink(ctx_, mysql_normalizer); } else { -#ifdef GROONGA_NORMALIZER_MYSQL_PLUGIN_IS_BUNDLED_STATIC - char ref_path[FN_REFLEN + 1], *tmp; - tmp = strmov(ref_path, opt_plugin_dir); - tmp = strmov(tmp, "/ha_mroonga"); - strcpy(tmp, SO_EXT); - grn_plugin_register_by_path(ctx_, ref_path); -#else +# ifdef MRN_GROONGA_NORMALIZER_MYSQL_EMBED + GRN_PLUGIN_IMPL_NAME_TAGGED(init, normalizers_mysql)(ctx_); + GRN_PLUGIN_IMPL_NAME_TAGGED(register, normalizers_mysql)(ctx_); +# else grn_plugin_register(ctx_, GROONGA_NORMALIZER_MYSQL_PLUGIN_NAME); -#endif +# endif } } #endif diff --git a/storage/mroonga/lib/mrn_database_manager.hpp b/storage/mroonga/lib/mrn_database_manager.hpp index 46bce7ab1a5..76c76dab6d5 100644 --- a/storage/mroonga/lib/mrn_database_manager.hpp +++ b/storage/mroonga/lib/mrn_database_manager.hpp @@ -27,7 +27,7 @@ namespace mrn { class DatabaseManager { public: - DatabaseManager(grn_ctx *ctx); + DatabaseManager(grn_ctx *ctx, mysql_mutex_t *mutex); ~DatabaseManager(void); bool init(void); int open(const char *path, grn_obj **db); @@ -38,8 +38,7 @@ namespace mrn { private: grn_ctx *ctx_; grn_hash *cache_; - pthread_mutex_t mutex_; - bool mutex_initialized_; + mysql_mutex_t *mutex_; void mkdir_p(const char *directory); void ensure_database_directory(void); diff --git a/storage/mroonga/lib/mrn_lock.cpp b/storage/mroonga/lib/mrn_lock.cpp index 94f8a4774af..3340149b237 100644 --- a/storage/mroonga/lib/mrn_lock.cpp +++ b/storage/mroonga/lib/mrn_lock.cpp @@ -20,12 +20,12 @@ #include "mrn_lock.hpp" namespace mrn { - Lock::Lock(pthread_mutex_t *mutex) + Lock::Lock(mysql_mutex_t *mutex) : mutex_(mutex) { - pthread_mutex_lock(mutex_); + mysql_mutex_lock(mutex_); } Lock::~Lock() { - pthread_mutex_unlock(mutex_); + mysql_mutex_unlock(mutex_); } } diff --git a/storage/mroonga/lib/mrn_lock.hpp b/storage/mroonga/lib/mrn_lock.hpp index 31dd7b3e53b..08e47b39c58 100644 --- a/storage/mroonga/lib/mrn_lock.hpp +++ b/storage/mroonga/lib/mrn_lock.hpp @@ -26,10 +26,10 @@ namespace mrn { class Lock { public: - Lock(pthread_mutex_t *mutex); + Lock(mysql_mutex_t *mutex); ~Lock(); private: - pthread_mutex_t *mutex_; + mysql_mutex_t *mutex_; }; } diff --git a/storage/mroonga/lib/mrn_parameters_parser.cpp b/storage/mroonga/lib/mrn_parameters_parser.cpp index 9a05097e548..3edf910ee91 100644 --- a/storage/mroonga/lib/mrn_parameters_parser.cpp +++ b/storage/mroonga/lib/mrn_parameters_parser.cpp @@ -35,10 +35,10 @@ namespace mrn { }; ~Parameter() { if (key_) { - my_free(key_, MYF(0)); + my_free(key_); } if (value_) { - my_free(value_, MYF(0)); + my_free(value_); } }; }; diff --git a/storage/mroonga/lib/mrn_path_mapper.cpp b/storage/mroonga/lib/mrn_path_mapper.cpp index ee5432f16bb..796101a10d1 100644 --- a/storage/mroonga/lib/mrn_path_mapper.cpp +++ b/storage/mroonga/lib/mrn_path_mapper.cpp @@ -2,7 +2,7 @@ /* Copyright(C) 2010 Tetsuro IKEDA Copyright(C) 2011-2013 Kentoku SHIBA - Copyright(C) 2011-2012 Kouhei Sutou + Copyright(C) 2011-2015 Kouhei Sutou This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -184,6 +184,9 @@ namespace mrn { int i = len, j = 0; for (; mysql_path_[--i] != FN_LIBCHAR ;) {} for (; i < len ;) { + if (len - i - 1 >= 3 && strncmp(mysql_path_ + i + 1, "#P#", 3) == 0) { + break; + } mysql_table_name_[j++] = mysql_path_[++i]; } mysql_table_name_[j] = '\0'; diff --git a/storage/mroonga/mrn_err.h b/storage/mroonga/mrn_err.h index c2ca885407a..bfaf2d44fa8 100644 --- a/storage/mroonga/mrn_err.h +++ b/storage/mroonga/mrn_err.h @@ -28,5 +28,11 @@ #define ER_MRN_ERROR_FROM_GROONGA_STR "Error from Groonga [%s]" #define ER_MRN_INVALID_NULL_VALUE_NUM 16505 #define ER_MRN_INVALID_NULL_VALUE_STR "NULL value can't be used for %s" +#define ER_MRN_UNSUPPORTED_COLUMN_FLAG_NUM 16506 +#define ER_MRN_UNSUPPORTED_COLUMN_FLAG_STR \ + "The column flag '%-.64s' is unsupported. It is ignored" +#define ER_MRN_INVALID_COLUMN_FLAG_NUM 16507 +#define ER_MRN_INVALID_COLUMN_FLAG_STR \ + "The column flag '%-.64s' is invalid. '%-64s' is used instead" #endif /* MRN_ERR_H_ */ diff --git a/storage/mroonga/mrn_mysql_compat.h b/storage/mroonga/mrn_mysql_compat.h index 7312dd70827..61b4ddd67a2 100644 --- a/storage/mroonga/mrn_mysql_compat.h +++ b/storage/mroonga/mrn_mysql_compat.h @@ -1,6 +1,6 @@ /* -*- c-basic-offset: 2 -*- */ /* - Copyright(C) 2011-2013 Kouhei Sutou + Copyright(C) 2011-2014 Kouhei Sutou This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,15 +22,6 @@ #include "mrn_mysql.h" -#if MYSQL_VERSION_ID >= 50500 -# define my_free(PTR, FLAG) my_free(PTR) -#endif - -#if MYSQL_VERSION_ID < 50500 -# define mysql_mutex_lock(mutex) pthread_mutex_lock(mutex) -# define mysql_mutex_unlock(mutex) pthread_mutex_unlock(mutex) -#endif - #if MYSQL_VERSION_ID >= 50604 # define MRN_HAVE_MYSQL_TYPE_TIMESTAMP2 # define MRN_HAVE_MYSQL_TYPE_DATETIME2 diff --git a/storage/mroonga/mrn_table.cpp b/storage/mroonga/mrn_table.cpp index fd406ac2dcf..aa82c1845c1 100644 --- a/storage/mroonga/mrn_table.cpp +++ b/storage/mroonga/mrn_table.cpp @@ -47,6 +47,7 @@ extern HASH *mrn_table_def_cache; #endif +#ifdef HAVE_PSI_INTERFACE #ifdef WIN32 # ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE extern PSI_mutex_key *mrn_table_share_lock_share; @@ -55,20 +56,23 @@ extern PSI_mutex_key *mrn_table_share_lock_share; extern PSI_mutex_key *mrn_table_share_lock_ha_data; # endif #endif +extern PSI_mutex_key mrn_share_mutex_key; +extern PSI_mutex_key mrn_long_term_share_auto_inc_mutex_key; +#endif #ifdef __cplusplus extern "C" { #endif extern HASH mrn_open_tables; -extern pthread_mutex_t mrn_open_tables_mutex; +extern mysql_mutex_t mrn_open_tables_mutex; extern HASH mrn_long_term_share; -extern pthread_mutex_t mrn_long_term_share_mutex; +extern mysql_mutex_t mrn_long_term_share_mutex; extern char *mrn_default_parser; extern char *mrn_default_wrapper_engine; extern handlerton *mrn_hton_ptr; extern HASH mrn_allocated_thds; -extern pthread_mutex_t mrn_allocated_thds_mutex; +extern mysql_mutex_t mrn_allocated_thds_mutex; static char *mrn_get_string_between_quote(const char *ptr) { @@ -424,7 +428,7 @@ int mrn_parse_table_param(MRN_SHARE *share, TABLE *table) } } - my_free(params_string, MYF(0)); + my_free(params_string); params_string = NULL; } } @@ -455,7 +459,7 @@ int mrn_parse_table_param(MRN_SHARE *share, TABLE *table) !strncasecmp(share->engine, MRN_GROONGA_STR, MRN_GROONGA_LEN) ) ) { - my_free(share->engine, MYF(0)); + my_free(share->engine); share->engine = NULL; share->engine_length = 0; } else { @@ -474,7 +478,7 @@ int mrn_parse_table_param(MRN_SHARE *share, TABLE *table) error: if (params_string) - my_free(params_string, MYF(0)); + my_free(params_string); DBUG_RETURN(error); } @@ -500,7 +504,7 @@ int mrn_add_index_param(MRN_SHARE *share, KEY *key_info, int i) if (key_info->comment.length == 0) { if (share->key_parser[i]) { - my_free(share->key_parser[i], MYF(0)); + my_free(share->key_parser[i]); } if ( !(share->key_parser[i] = my_strdup(mrn_default_parser, MYF(MY_WME))) @@ -574,12 +578,12 @@ int mrn_add_index_param(MRN_SHARE *share, KEY *key_info, int i) } if (param_string) - my_free(param_string, MYF(0)); + my_free(param_string); DBUG_RETURN(0); error: if (param_string) - my_free(param_string, MYF(0)); + my_free(param_string); #if MYSQL_VERSION_ID >= 50500 error_alloc_param_string: #endif @@ -677,12 +681,12 @@ int mrn_add_column_param(MRN_SHARE *share, Field *field, int i) } if (param_string) - my_free(param_string, MYF(0)); + my_free(param_string); DBUG_RETURN(0); error: if (param_string) - my_free(param_string, MYF(0)); + my_free(param_string); error_alloc_param_string: DBUG_RETURN(error); } @@ -714,26 +718,26 @@ int mrn_free_share_alloc( uint i; MRN_DBUG_ENTER_FUNCTION(); if (share->engine) - my_free(share->engine, MYF(0)); + my_free(share->engine); if (share->default_tokenizer) - my_free(share->default_tokenizer, MYF(0)); + my_free(share->default_tokenizer); if (share->normalizer) - my_free(share->normalizer, MYF(0)); + my_free(share->normalizer); if (share->token_filters) - my_free(share->token_filters, MYF(0)); + my_free(share->token_filters); for (i = 0; i < share->table_share->keys; i++) { if (share->index_table && share->index_table[i]) - my_free(share->index_table[i], MYF(0)); + my_free(share->index_table[i]); if (share->key_parser[i]) - my_free(share->key_parser[i], MYF(0)); + my_free(share->key_parser[i]); } for (i = 0; i < share->table_share->fields; i++) { if (share->col_flags && share->col_flags[i]) - my_free(share->col_flags[i], MYF(0)); + my_free(share->col_flags[i]); if (share->col_type && share->col_type[i]) - my_free(share->col_type[i], MYF(0)); + my_free(share->col_type[i]); } DBUG_RETURN(0); } @@ -745,8 +749,8 @@ void mrn_free_long_term_share(MRN_LONG_TERM_SHARE *long_term_share) mrn::Lock lock(&mrn_long_term_share_mutex); my_hash_delete(&mrn_long_term_share, (uchar*) long_term_share); } - pthread_mutex_destroy(&long_term_share->auto_inc_mutex); - my_free(long_term_share, MYF(0)); + mysql_mutex_destroy(&long_term_share->auto_inc_mutex); + my_free(long_term_share); DBUG_VOID_RETURN; } @@ -775,8 +779,9 @@ MRN_LONG_TERM_SHARE *mrn_get_long_term_share(const char *table_name, long_term_share->table_name = tmp_name; long_term_share->table_name_length = table_name_length; memcpy(long_term_share->table_name, table_name, table_name_length); - if (pthread_mutex_init(&long_term_share->auto_inc_mutex, - MY_MUTEX_INIT_FAST)) + if (mysql_mutex_init(mrn_long_term_share_auto_inc_mutex_key, + &long_term_share->auto_inc_mutex, + MY_MUTEX_INIT_FAST) != 0) { *error = HA_ERR_OUT_OF_MEM; goto error_init_auto_inc_mutex; @@ -790,9 +795,9 @@ MRN_LONG_TERM_SHARE *mrn_get_long_term_share(const char *table_name, DBUG_RETURN(long_term_share); error_hash_insert: - pthread_mutex_destroy(&long_term_share->auto_inc_mutex); + mysql_mutex_destroy(&long_term_share->auto_inc_mutex); error_init_auto_inc_mutex: - my_free(long_term_share, MYF(0)); + my_free(long_term_share); error_alloc_long_term_share: DBUG_RETURN(NULL); } @@ -912,7 +917,9 @@ MRN_SHARE *mrn_get_share(const char *table_name, TABLE *table, int *error) share->wrap_table_share = wrap_table_share; } - if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) + if (mysql_mutex_init(mrn_share_mutex_key, + &share->mutex, + MY_MUTEX_INIT_FAST) != 0) { *error = HA_ERR_OUT_OF_MEM; goto error_init_mutex; @@ -934,11 +941,11 @@ MRN_SHARE *mrn_get_share(const char *table_name, TABLE *table, int *error) error_hash_insert: error_get_long_term_share: - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); error_init_mutex: error_parse_table_param: mrn_free_share_alloc(share); - my_free(share, MYF(0)); + my_free(share); error_alloc_share: DBUG_RETURN(NULL); } @@ -954,7 +961,7 @@ int mrn_free_share(MRN_SHARE *share) plugin_unlock(NULL, share->plugin); mrn_free_share_alloc(share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); + mysql_mutex_destroy(&share->mutex); if (share->wrapper_mode) { #ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE mysql_mutex_destroy(&(share->wrap_table_share->LOCK_share)); @@ -963,7 +970,7 @@ int mrn_free_share(MRN_SHARE *share) mysql_mutex_destroy(&(share->wrap_table_share->LOCK_ha_data)); #endif } - my_free(share, MYF(0)); + my_free(share); } DBUG_RETURN(0); } @@ -1025,9 +1032,9 @@ TABLE_SHARE *mrn_create_tmp_table_share(TABLE_LIST *table_list, const char *path } share->tmp_table = INTERNAL_TMP_TABLE; // TODO: is this right? share->path.str = (char *) path; - share->path.length = strlen(path); - share->normalized_path.str = share->path.str; - share->normalized_path.length = share->path.length; + share->path.length = strlen(share->path.str); + share->normalized_path.str = my_strdup(path, MYF(MY_WME)); + share->normalized_path.length = strlen(share->normalized_path.str); if (open_table_def(thd, share, GTS_TABLE)) { *error = ER_CANT_OPEN_FILE; @@ -1039,7 +1046,9 @@ TABLE_SHARE *mrn_create_tmp_table_share(TABLE_LIST *table_list, const char *path void mrn_free_tmp_table_share(TABLE_SHARE *tmp_table_share) { MRN_DBUG_ENTER_FUNCTION(); + char *normalized_path = tmp_table_share->normalized_path.str; free_table_share(tmp_table_share); + my_free(normalized_path); DBUG_VOID_RETURN; } @@ -1131,11 +1140,11 @@ void mrn_clear_alter_share(THD *thd) slot_data->alter_create_info = NULL; slot_data->disable_keys_create_info = NULL; if (slot_data->alter_connect_string) { - my_free(slot_data->alter_connect_string, MYF(0)); + my_free(slot_data->alter_connect_string); slot_data->alter_connect_string = NULL; } if (slot_data->alter_comment) { - my_free(slot_data->alter_comment, MYF(0)); + my_free(slot_data->alter_comment); slot_data->alter_comment = NULL; } } diff --git a/storage/mroonga/mrn_table.hpp b/storage/mroonga/mrn_table.hpp index 813e69e1023..9118455b53d 100644 --- a/storage/mroonga/mrn_table.hpp +++ b/storage/mroonga/mrn_table.hpp @@ -33,7 +33,7 @@ typedef struct st_mroonga_long_term_share uint table_name_length; // for auto_increment (storage mode only) - pthread_mutex_t auto_inc_mutex; + mysql_mutex_t auto_inc_mutex; bool auto_inc_inited; ulonglong auto_inc_value; } MRN_LONG_TERM_SHARE; @@ -43,7 +43,7 @@ typedef struct st_mroonga_share char *table_name; uint table_name_length; uint use_count; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; TABLE_SHARE *table_share; TABLE_SHARE *wrap_table_share; diff --git a/storage/mroonga/mysql-test/mroonga/include/mroonga/check_libgroonga_support_lz4.inc b/storage/mroonga/mysql-test/mroonga/include/mroonga/check_libgroonga_support_lz4.inc new file mode 100644 index 00000000000..1c74cbffc46 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/include/mroonga/check_libgroonga_support_lz4.inc @@ -0,0 +1,20 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--disable_query_log +let $libgroonga_support_lz4 = + `SELECT @@mroonga_libgroonga_support_lz4;`; +--enable_query_log diff --git a/storage/mroonga/mysql-test/mroonga/include/mroonga/check_libgroonga_support_zlib.inc b/storage/mroonga/mysql-test/mroonga/include/mroonga/check_libgroonga_support_zlib.inc new file mode 100644 index 00000000000..5ab5fcd2fb8 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/include/mroonga/check_libgroonga_support_zlib.inc @@ -0,0 +1,20 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--disable_query_log +let $libgroonga_support_zlib = + `SELECT @@mroonga_libgroonga_support_zlib;`; +--enable_query_log diff --git a/storage/mroonga/mysql-test/mroonga/include/mroonga/support_libgroonga_lz4.inc b/storage/mroonga/mysql-test/mroonga/include/mroonga/support_libgroonga_lz4.inc new file mode 100644 index 00000000000..e67f826b0ce --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/include/mroonga/support_libgroonga_lz4.inc @@ -0,0 +1,22 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/check_libgroonga_support_lz4.inc + +if (!$libgroonga_support_lz4) { + --source ../../include/mroonga/have_mroonga_deinit.inc + skip "This test is for libgroonga supports lz4"; +} diff --git a/storage/mroonga/mysql-test/mroonga/include/mroonga/support_libgroonga_zlib.inc b/storage/mroonga/mysql-test/mroonga/include/mroonga/support_libgroonga_zlib.inc new file mode 100644 index 00000000000..9f5196f742b --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/include/mroonga/support_libgroonga_zlib.inc @@ -0,0 +1,22 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/check_libgroonga_support_zlib.inc + +if (!$libgroonga_support_zlib) { + --source ../../include/mroonga/have_mroonga_deinit.inc + skip "This test is for libgroonga supports zlib"; +} diff --git a/storage/mroonga/mysql-test/mroonga/include/mroonga/unsupport_libgroonga_lz4.inc b/storage/mroonga/mysql-test/mroonga/include/mroonga/unsupport_libgroonga_lz4.inc new file mode 100644 index 00000000000..80874a7a50b --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/include/mroonga/unsupport_libgroonga_lz4.inc @@ -0,0 +1,22 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/check_libgroonga_support_lz4.inc + +if ($libgroonga_support_lz4) { + --source ../../include/mroonga/have_mroonga_deinit.inc + skip "This test is for libgroonga doesn't support lz4"; +} diff --git a/storage/mroonga/mysql-test/mroonga/include/mroonga/unsupport_libgroonga_zlib.inc b/storage/mroonga/mysql-test/mroonga/include/mroonga/unsupport_libgroonga_zlib.inc new file mode 100644 index 00000000000..d6c3f6dbeda --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/include/mroonga/unsupport_libgroonga_zlib.inc @@ -0,0 +1,22 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/check_libgroonga_support_zlib.inc + +if ($libgroonga_support_zlib) { + --source ../../include/mroonga/have_mroonga_deinit.inc + skip "This test is for libgroonga doesn't support zlib"; +} diff --git a/storage/mroonga/mysql-test/mroonga/storage/disabled.def b/storage/mroonga/mysql-test/mroonga/storage/disabled.def index 3f546dad2a4..6866adc1e35 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/disabled.def +++ b/storage/mroonga/mysql-test/mroonga/storage/disabled.def @@ -6,4 +6,5 @@ create_table_token_filters_index_comment_one_token_filter : Bundled Mroonga does create_table_token_filters_table_comment_multiple_token_filters : Bundled Mroonga does not support token filter yet. create_table_token_filters_table_comment_one_token_filter : Bundled Mroonga does not support token filter yet. foreign_key_create : Bundled Mroonga does not support this test yet. +partition_insert : Bundled Mroonga does not support this test yet. diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_add_index_unique_multiple_column_duplicated.result b/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_add_index_unique_multiple_column_duplicated.result new file mode 100644 index 00000000000..8ab7ef22aca --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_add_index_unique_multiple_column_duplicated.result @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS ids; +CREATE TABLE ids ( +id1 INT, +id2 INT +) DEFAULT CHARSET=utf8mb4; +INSERT INTO ids (id1, id2) values (1, 2), (1, 2); +ALTER TABLE ids ADD UNIQUE INDEX (id1, id2); +ERROR 23000: Can't write, because of unique constraint, to table 'ids' +SHOW CREATE TABLE ids; +Table Create Table +ids CREATE TABLE `ids` ( + `id1` int(11) DEFAULT NULL, + `id2` int(11) DEFAULT NULL +) ENGINE=Mroonga DEFAULT CHARSET=utf8mb4 +SELECT * FROM ids; +id1 id2 +1 2 +1 2 +DROP TABLE ids; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_disable_keys_fulltext_table.result b/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_disable_keys_fulltext_table.result new file mode 100644 index 00000000000..c7051127946 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_disable_keys_fulltext_table.result @@ -0,0 +1,27 @@ +SET NAMES utf8; +CREATE TABLE terms ( +term varchar(256) NOT NULL PRIMARY KEY +) COMMENT='default_tokenizer "TokenBigram", normalizer "NormalizerAuto"' + DEFAULT CHARSET=utf8; +CREATE TABLE memos ( +id int PRIMARY KEY, +content text NOT NULL, +FULLTEXT INDEX content_index (content) COMMENT 'table "terms"' +) DEFAULT CHARSET=utf8; +SELECT mroonga_command("dump"); +mroonga_command("dump") +table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +column_create terms term COLUMN_SCALAR ShortText +table_create memos TABLE_PAT_KEY Int32 +column_create memos content COLUMN_SCALAR LongText +column_create memos id COLUMN_SCALAR Int32 +column_create terms content_index COLUMN_INDEX|WITH_POSITION memos content +ALTER TABLE memos DISABLE KEYS; +SELECT mroonga_command("dump"); +mroonga_command("dump") +table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +column_create terms term COLUMN_SCALAR ShortText +table_create memos TABLE_PAT_KEY Int32 +column_create memos content COLUMN_SCALAR LongText +column_create memos id COLUMN_SCALAR Int32 +DROP TABLE memos, terms; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_enable_keys_fulltext_table.result b/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_enable_keys_fulltext_table.result new file mode 100644 index 00000000000..97d2be3f8d5 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/alter_table_enable_keys_fulltext_table.result @@ -0,0 +1,28 @@ +SET NAMES utf8; +CREATE TABLE terms ( +term varchar(256) NOT NULL PRIMARY KEY +) COMMENT='default_tokenizer "TokenBigram", normalizer "NormalizerAuto"' + DEFAULT CHARSET=utf8; +CREATE TABLE memos ( +id int PRIMARY KEY, +content text NOT NULL, +FULLTEXT INDEX content_index (content) COMMENT 'table "terms"' +) DEFAULT CHARSET=utf8; +ALTER TABLE memos DISABLE KEYS; +SELECT mroonga_command("dump"); +mroonga_command("dump") +table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +column_create terms term COLUMN_SCALAR ShortText +table_create memos TABLE_PAT_KEY Int32 +column_create memos content COLUMN_SCALAR LongText +column_create memos id COLUMN_SCALAR Int32 +ALTER TABLE memos ENABLE KEYS; +SELECT mroonga_command("dump"); +mroonga_command("dump") +table_create terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +column_create terms term COLUMN_SCALAR ShortText +table_create memos TABLE_PAT_KEY Int32 +column_create memos content COLUMN_SCALAR LongText +column_create memos id COLUMN_SCALAR Int32 +column_create terms content_index COLUMN_INDEX|WITH_POSITION memos content +DROP TABLE memos, terms; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_other_table.result b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_other_table.result index 87c14a98f15..767fe491e99 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_other_table.result +++ b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_other_table.result @@ -1,42 +1,30 @@ -DROP DATABASE IF EXISTS mroonga; -CREATE DATABASE mroonga; -USE mroonga; -CREATE TABLE tags ( +CREATE TABLE terms ( name VARCHAR(64) PRIMARY KEY ) DEFAULT CHARSET=utf8 -COLLATE=utf8_bin -COMMENT='default_tokenizer "TokenDelimit"'; +COMMENT='default_tokenizer "TokenBigram"'; CREATE TABLE bugs ( id INT UNSIGNED PRIMARY KEY, -tags TEXT COMMENT 'flags "COLUMN_VECTOR", type "tags"', -FULLTEXT INDEX bugs_tags_index (tags) COMMENT 'table "tags"' +title TEXT, +FULLTEXT INDEX (title) COMMENT 'table "terms"' ) DEFAULT CHARSET=utf8; -INSERT INTO bugs (id, tags) VALUES (1, "Linux MySQL groonga"); -SELECT mroonga_command("dump"); -mroonga_command("dump") -table_create tags TABLE_PAT_KEY ShortText --default_tokenizer TokenDelimit -column_create tags name COLUMN_SCALAR ShortText -table_create bugs TABLE_PAT_KEY UInt32 -column_create bugs id COLUMN_SCALAR UInt32 -column_create bugs tags COLUMN_VECTOR tags -column_create tags bugs_tags_index COLUMN_INDEX|WITH_POSITION bugs tags -load --table tags -[ -["_key","name"], -["Linux",""], -["MySQL",""], -["groonga",""] -] -load --table bugs -[ -["_key","id","tags"], -[1,1,["Linux","MySQL","groonga"]] -] -SELECT *, MATCH (tags) AGAINST ("MySQL" IN BOOLEAN MODE) AS score +INSERT INTO bugs (id, title) VALUES (1, "Mroonga can't build with MySQL X.Y.Z"); +SELECT * FROM terms ORDER BY name; +name +' +. +BUILD +CAN +MROONGA +MYSQL +T +WITH +X +Y +Z +SELECT *, MATCH (title) AGAINST ("+MySQL" IN BOOLEAN MODE) AS score FROM bugs -WHERE MATCH (tags) AGAINST ("MySQL" IN BOOLEAN MODE); -id tags score -1 Linux MySQL groonga 1 +WHERE MATCH (title) AGAINST ("+MySQL" IN BOOLEAN MODE); +id title score +1 Mroonga can't build with MySQL X.Y.Z 1 DROP TABLE bugs; -DROP TABLE tags; -DROP DATABASE mroonga; +DROP TABLE terms; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_vector_other_table.result b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_vector_other_table.result new file mode 100644 index 00000000000..6ac2e1937fe --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_index_fulltext_vector_other_table.result @@ -0,0 +1,42 @@ +DROP DATABASE IF EXISTS mroonga; +CREATE DATABASE mroonga; +USE mroonga; +CREATE TABLE tags ( +name VARCHAR(64) PRIMARY KEY +) DEFAULT CHARSET=utf8 +COLLATE=utf8_bin +COMMENT='default_tokenizer "TokenDelimit"'; +CREATE TABLE bugs ( +id INT UNSIGNED PRIMARY KEY, +tags TEXT COMMENT 'flags "COLUMN_VECTOR", type "tags"', +FULLTEXT INDEX bugs_tags_index (tags) COMMENT 'table "tags"' +) DEFAULT CHARSET=utf8; +INSERT INTO bugs (id, tags) VALUES (1, "Linux MySQL groonga"); +SELECT mroonga_command("dump"); +mroonga_command("dump") +table_create tags TABLE_PAT_KEY ShortText --default_tokenizer TokenDelimit +column_create tags name COLUMN_SCALAR ShortText +table_create bugs TABLE_PAT_KEY UInt32 +column_create bugs id COLUMN_SCALAR UInt32 +column_create bugs tags COLUMN_VECTOR tags +column_create tags bugs_tags_index COLUMN_INDEX|WITH_POSITION bugs tags +load --table tags +[ +["_key","name"], +["Linux",""], +["MySQL",""], +["groonga",""] +] +load --table bugs +[ +["_key","id","tags"], +[1,1,["Linux","MySQL","groonga"]] +] +SELECT *, MATCH (tags) AGAINST ("+MySQL" IN BOOLEAN MODE) AS score +FROM bugs +WHERE MATCH (tags) AGAINST ("+MySQL" IN BOOLEAN MODE); +id tags score +1 Linux MySQL groonga 1 +DROP TABLE bugs; +DROP TABLE tags; +DROP DATABASE mroonga; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_support_lz4.result b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_support_lz4.result new file mode 100644 index 00000000000..11875e15018 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_support_lz4.result @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS entries; +CREATE TABLE entries ( +id INT UNSIGNED PRIMARY KEY, +content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_LZ4"' +) DEFAULT CHARSET=utf8; +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); +SELECT * FROM entries; +id content +1 I found Mroonga that is a MySQL storage engine to use Groonga! +DROP TABLE entries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_support_zlib.result b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_support_zlib.result new file mode 100644 index 00000000000..5d704e3ebec --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_support_zlib.result @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS entries; +CREATE TABLE entries ( +id INT UNSIGNED PRIMARY KEY, +content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_ZLIB"' +) DEFAULT CHARSET=utf8; +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); +SELECT * FROM entries; +id content +1 I found Mroonga that is a MySQL storage engine to use Groonga! +DROP TABLE entries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_unsupport_lz4.result b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_unsupport_lz4.result new file mode 100644 index 00000000000..a9a5f55fd7f --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_unsupport_lz4.result @@ -0,0 +1,12 @@ +DROP TABLE IF EXISTS entries; +CREATE TABLE entries ( +id INT UNSIGNED PRIMARY KEY, +content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_LZ4"' +) DEFAULT CHARSET=utf8; +Warnings: +Warning 16506 The column flag 'COMPRESS_LZ4' is unsupported. It is ignored +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); +SELECT * FROM entries; +id content +1 I found Mroonga that is a MySQL storage engine to use Groonga! +DROP TABLE entries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_unsupport_zlib.result b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_unsupport_zlib.result new file mode 100644 index 00000000000..068ce58bf74 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/column_groonga_scalar_unsupport_zlib.result @@ -0,0 +1,12 @@ +DROP TABLE IF EXISTS entries; +CREATE TABLE entries ( +id INT UNSIGNED PRIMARY KEY, +content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_ZLIB"' +) DEFAULT CHARSET=utf8; +Warnings: +Warning 16506 The column flag 'COMPRESS_ZLIB' is unsupported. It is ignored +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); +SELECT * FROM entries; +id content +1 I found Mroonga that is a MySQL storage engine to use Groonga! +DROP TABLE entries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index.result b/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_comment.result similarity index 100% rename from storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index.result rename to storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_comment.result diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_no_utf8_charset_with_utf8_normalizer.result b/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_no_utf8_charset_with_utf8_normalizer.result similarity index 100% rename from storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_no_utf8_charset_with_utf8_normalizer.result rename to storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_no_utf8_charset_with_utf8_normalizer.result diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_none.result b/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_none.result new file mode 100644 index 00000000000..52c6f055e88 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_fulltext_index_none.result @@ -0,0 +1,16 @@ +DROP TABLE IF EXISTS diaries; +SET NAMES utf8; +CREATE TABLE diaries ( +day DATE PRIMARY KEY, +content VARCHAR(64) NOT NULL, +FULLTEXT INDEX (content) COMMENT 'normalizer "none"' +) DEFAULT CHARSET=utf8; +INSERT INTO diaries VALUES ("2013-04-23", "Mroonga"); +SELECT * FROM diaries +WHERE MATCH (content) AGAINST ("+Mroonga" IN BOOLEAN MODE); +day content +2013-04-23 Mroonga +SELECT * FROM diaries +WHERE MATCH (content) AGAINST ("+mroonga" IN BOOLEAN MODE); +day content +DROP TABLE diaries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_table_comment.result b/storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_primary_key_table_comment.result similarity index 100% rename from storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_table_comment.result rename to storage/mroonga/mysql-test/mroonga/storage/r/create_table_normalizer_primary_key_table_comment.result diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/index_unique_search_after_duplicated.result b/storage/mroonga/mysql-test/mroonga/storage/r/index_unique_search_after_duplicated.result new file mode 100644 index 00000000000..1d9d5fbbf51 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/index_unique_search_after_duplicated.result @@ -0,0 +1,18 @@ +DROP TABLE IF EXISTS users; +CREATE TABLE users ( +id int PRIMARY KEY, +name varchar(100) NOT NULL, +UNIQUE KEY (name) +) DEFAULT CHARSET=utf8; +INSERT INTO users VALUES (1, "Alice"); +INSERT INTO users VALUES (2, "Bob"); +INSERT INTO users VALUES (3, "Bob"); +ERROR 23000: Duplicate entry 'Bob' for key 'name' +SELECT * FROM users; +id name +1 Alice +2 Bob +SELECT * FROM users WHERE name = "Bob"; +id name +2 Bob +DROP TABLE users; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/information_schema_plugins.result b/storage/mroonga/mysql-test/mroonga/storage/r/information_schema_plugins.result index 8d3decfa32a..63ecb8c669a 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/r/information_schema_plugins.result +++ b/storage/mroonga/mysql-test/mroonga/storage/r/information_schema_plugins.result @@ -1,4 +1,4 @@ select PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_TYPE from information_schema.plugins where plugin_name = "Mroonga"; PLUGIN_NAME PLUGIN_VERSION PLUGIN_TYPE -Mroonga 4.6 STORAGE ENGINE +Mroonga 5.0 STORAGE ENGINE diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/insert_on_duplicate_key_update_unique_key.result b/storage/mroonga/mysql-test/mroonga/storage/r/insert_on_duplicate_key_update_unique_key.result index 288e9e3a2c8..fbec44527f7 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/r/insert_on_duplicate_key_update_unique_key.result +++ b/storage/mroonga/mysql-test/mroonga/storage/r/insert_on_duplicate_key_update_unique_key.result @@ -15,16 +15,19 @@ diaries CREATE TABLE `diaries` ( UNIQUE KEY `day` (`day`) ) ENGINE=Mroonga DEFAULT CHARSET=utf8 INSERT INTO diaries (day, title) -VALUES ("2012-02-14", "clear day") -ON DUPLICATE KEY UPDATE title = "clear day (duplicated)"; +VALUES ("2012-02-14", "clear day1") +ON DUPLICATE KEY UPDATE title = "clear day1 (duplicated)"; INSERT INTO diaries (day, title) -VALUES ("2012-02-14", "rainy day") -ON DUPLICATE KEY UPDATE title = "rainy day (duplicated)"; +VALUES ("2012-02-14", "clear day2") +ON DUPLICATE KEY UPDATE title = "clear day2 (duplicated)"; +INSERT INTO diaries (day, title) +VALUES ("2012-02-14", "clear day3") +ON DUPLICATE KEY UPDATE title = "clear day3 (duplicated)"; INSERT INTO diaries (day, title) VALUES ("2012-02-15", "cloudy day") ON DUPLICATE KEY UPDATE title = "cloudy day (duplicated)"; SELECT * FROM diaries; id day title -1 2012-02-14 rainy day (duplicated) -3 2012-02-15 cloudy day +1 2012-02-14 clear day3 (duplicated) +4 2012-02-15 cloudy day DROP TABLE diaries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/partition_insert.result b/storage/mroonga/mysql-test/mroonga/storage/r/partition_insert.result new file mode 100644 index 00000000000..ea1e63e39d0 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/partition_insert.result @@ -0,0 +1,42 @@ +DROP TABLE IF EXISTS logs; +SET NAMES UTF8; +CREATE TABLE logs ( +timestamp DATETIME, +message TEXT +) DEFAULT CHARSET=UTF8 +PARTITION BY RANGE (TO_DAYS(timestamp)) ( +PARTITION p201501 VALUES LESS THAN (TO_DAYS('2015-02-01')), +PARTITION p201502 VALUES LESS THAN (TO_DAYS('2015-03-01')), +PARTITION p201503 VALUES LESS THAN (TO_DAYS('2015-04-01')), +PARTITION pfuture VALUES LESS THAN MAXVALUE +); +SHOW CREATE TABLE logs; +Table Create Table +logs CREATE TABLE `logs` ( + `timestamp` datetime DEFAULT NULL, + `message` text +) ENGINE=Mroonga DEFAULT CHARSET=utf8 +/*!50100 PARTITION BY RANGE (TO_DAYS(timestamp)) +(PARTITION p201501 VALUES LESS THAN (735995) ENGINE = Mroonga, + PARTITION p201502 VALUES LESS THAN (736023) ENGINE = Mroonga, + PARTITION p201503 VALUES LESS THAN (736054) ENGINE = Mroonga, + PARTITION pfuture VALUES LESS THAN MAXVALUE ENGINE = Mroonga) */ +INSERT INTO logs VALUES('2015-01-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-01-31 23:59:59', 'Shutdown'); +INSERT INTO logs VALUES('2015-02-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-02-28 23:59:59', 'Shutdown'); +INSERT INTO logs VALUES('2015-03-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-03-31 23:59:59', 'Shutdown'); +INSERT INTO logs VALUES('2015-04-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-04-30 23:59:59', 'Shutdown'); +SELECT * FROM logs ORDER BY timestamp; +timestamp message +2015-01-01 00:00:00 Start +2015-01-31 23:59:59 Shutdown +2015-02-01 00:00:00 Start +2015-02-28 23:59:59 Shutdown +2015-03-01 00:00:00 Start +2015-03-31 23:59:59 Shutdown +2015-04-01 00:00:00 Start +2015-04-30 23:59:59 Shutdown +DROP TABLE logs; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/replace_without_key.result b/storage/mroonga/mysql-test/mroonga/storage/r/replace_without_key.result new file mode 100644 index 00000000000..2c6c1cbc7e8 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/replace_without_key.result @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS diaries; +SET NAMES utf8; +CREATE TABLE diaries ( +id varchar(32) NOT NULL PRIMARY KEY, +content text, +FULLTEXT INDEX (content) +) DEFAULT CHARSET=utf8; +REPLACE INTO diaries(content) VALUES("Hello"); +ERROR HY000: primary key is empty +DROP TABLE diaries; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_column.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_column.result new file mode 100644 index 00000000000..37826335b02 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_column.result @@ -0,0 +1,18 @@ +SET @mroonga_boolean_mode_syntax_flags_backup = +@@mroonga_boolean_mode_syntax_flags; +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY,ALLOW_COLUMN"; +SET NAMES UTF8; +CREATE TABLE diaries ( +title TEXT, +content TEXT, +FULLTEXT KEY (title), +FULLTEXT KEY (content) +) DEFAULT CHARSET=utf8; +INSERT INTO diaries VALUES("Groonga", "Hello Groonga"); +SELECT * FROM diaries +WHERE MATCH(title) AGAINST("content:@Hello" IN BOOLEAN MODE); +title content +Groonga Hello Groonga +DROP TABLE diaries; +SET mroonga_boolean_mode_syntax_flags = +@mroonga_boolean_mode_syntax_flags_backup; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_leading_not.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_leading_not.result new file mode 100644 index 00000000000..d3ccb150eab --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_leading_not.result @@ -0,0 +1,16 @@ +SET @mroonga_boolean_mode_syntax_flags_backup = +@@mroonga_boolean_mode_syntax_flags; +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY,ALLOW_LEADING_NOT"; +SET NAMES UTF8; +CREATE TABLE diaries ( +title TEXT, +FULLTEXT KEY (title) +) DEFAULT CHARSET=utf8; +INSERT INTO diaries VALUES("Groonga"); +INSERT INTO diaries VALUES("Mroonga"); +SELECT * FROM diaries WHERE MATCH(title) AGAINST("-Groonga" IN BOOLEAN MODE); +title +Mroonga +DROP TABLE diaries; +SET mroonga_boolean_mode_syntax_flags = +@mroonga_boolean_mode_syntax_flags_backup; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_update.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_update.result new file mode 100644 index 00000000000..55cd8742758 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_allow_update.result @@ -0,0 +1,18 @@ +SET @mroonga_boolean_mode_syntax_flags_backup = +@@mroonga_boolean_mode_syntax_flags; +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY,ALLOW_COLUMN,ALLOW_UPDATE"; +SET NAMES UTF8; +CREATE TABLE diaries ( +title TEXT, +content TEXT, +FULLTEXT KEY (title), +FULLTEXT KEY (content) +) DEFAULT CHARSET=utf8; +INSERT INTO diaries VALUES("Groonga", "Hello Groonga"); +SELECT * FROM diaries +WHERE MATCH(title) AGAINST('content:="Hello Mroonga"' IN BOOLEAN MODE); +title content +Groonga Hello Mroonga +DROP TABLE diaries; +SET mroonga_boolean_mode_syntax_flags = +@mroonga_boolean_mode_syntax_flags_backup; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_syntax_query.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_syntax_query.result new file mode 100644 index 00000000000..5736fd52c89 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_syntax_query.result @@ -0,0 +1,15 @@ +SET @mroonga_boolean_mode_syntax_flags_backup = +@@mroonga_boolean_mode_syntax_flags; +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY"; +SET NAMES UTF8; +CREATE TABLE diaries ( +title TEXT, +FULLTEXT KEY (title) +) DEFAULT CHARSET=utf8; +INSERT INTO diaries VALUES("Re:Mroonga"); +SELECT * FROM diaries WHERE MATCH(title) AGAINST("Re:Mroonga" IN BOOLEAN MODE); +title +Re:Mroonga +DROP TABLE diaries; +SET mroonga_boolean_mode_syntax_flags = +@mroonga_boolean_mode_syntax_flags_backup; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_syntax_script.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_syntax_script.result new file mode 100644 index 00000000000..e42fa259e4a --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_boolean_mode_syntax_flags_syntax_script.result @@ -0,0 +1,16 @@ +SET @mroonga_boolean_mode_syntax_flags_backup = +@@mroonga_boolean_mode_syntax_flags; +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_SCRIPT"; +SET NAMES UTF8; +CREATE TABLE diaries ( +title TEXT, +FULLTEXT KEY (title) +) DEFAULT CHARSET=utf8; +INSERT INTO diaries VALUES("Re:Mroonga"); +SELECT * FROM diaries +WHERE MATCH(title) AGAINST("title @ 'Re:Mroonga'" IN BOOLEAN MODE); +title +Re:Mroonga +DROP TABLE diaries; +SET mroonga_boolean_mode_syntax_flags = +@mroonga_boolean_mode_syntax_flags_backup; diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/variable_version.result b/storage/mroonga/mysql-test/mroonga/storage/r/variable_version.result index aae83fe2b38..9b99165c047 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/r/variable_version.result +++ b/storage/mroonga/mysql-test/mroonga/storage/r/variable_version.result @@ -1,3 +1,3 @@ show variables like 'mroonga_version'; Variable_name Value -mroonga_version 4.06 +mroonga_version 5.00 diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_add_index_unique_multiple_column_duplicated.test b/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_add_index_unique_multiple_column_duplicated.test new file mode 100644 index 00000000000..72e0ebc14a4 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_add_index_unique_multiple_column_duplicated.test @@ -0,0 +1,39 @@ +# Copyright(C) 2015 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source include/not_embedded.inc +--source ../../include/mroonga/have_mroonga.inc + +--disable_warnings +DROP TABLE IF EXISTS ids; +--enable_warnings + +CREATE TABLE ids ( + id1 INT, + id2 INT +) DEFAULT CHARSET=utf8mb4; + +INSERT INTO ids (id1, id2) values (1, 2), (1, 2); + +--error ER_DUP_UNIQUE +ALTER TABLE ids ADD UNIQUE INDEX (id1, id2); +SHOW CREATE TABLE ids; + +SELECT * FROM ids; + +DROP TABLE ids; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_disable_keys_fulltext_table.test b/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_disable_keys_fulltext_table.test new file mode 100644 index 00000000000..d0c1313c784 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_disable_keys_fulltext_table.test @@ -0,0 +1,45 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_query_log +DROP DATABASE test; +CREATE DATABASE test; +USE test; +--enable_query_log + +SET NAMES utf8; +CREATE TABLE terms ( + term varchar(256) NOT NULL PRIMARY KEY +) COMMENT='default_tokenizer "TokenBigram", normalizer "NormalizerAuto"' + DEFAULT CHARSET=utf8; + +CREATE TABLE memos ( + id int PRIMARY KEY, + content text NOT NULL, + FULLTEXT INDEX content_index (content) COMMENT 'table "terms"' +) DEFAULT CHARSET=utf8; + +SELECT mroonga_command("dump"); +ALTER TABLE memos DISABLE KEYS; +SELECT mroonga_command("dump"); + +DROP TABLE memos, terms; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_enable_keys_fulltext_table.test b/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_enable_keys_fulltext_table.test new file mode 100644 index 00000000000..b05fa6aa116 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/alter_table_enable_keys_fulltext_table.test @@ -0,0 +1,46 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_query_log +DROP DATABASE test; +CREATE DATABASE test; +USE test; +--enable_query_log + +SET NAMES utf8; +CREATE TABLE terms ( + term varchar(256) NOT NULL PRIMARY KEY +) COMMENT='default_tokenizer "TokenBigram", normalizer "NormalizerAuto"' + DEFAULT CHARSET=utf8; + +CREATE TABLE memos ( + id int PRIMARY KEY, + content text NOT NULL, + FULLTEXT INDEX content_index (content) COMMENT 'table "terms"' +) DEFAULT CHARSET=utf8; + +ALTER TABLE memos DISABLE KEYS; +SELECT mroonga_command("dump"); +ALTER TABLE memos ENABLE KEYS; +SELECT mroonga_command("dump"); + +DROP TABLE memos, terms; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_other_table.test b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_other_table.test index 805c744236f..dbaf2fb429f 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_other_table.test +++ b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_other_table.test @@ -1,4 +1,4 @@ -# Copyright(C) 2013 Kouhei Sutou +# Copyright(C) 2014 Kouhei Sutou # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -16,39 +16,27 @@ --source include/not_embedded.inc --source ../../include/mroonga/have_mroonga.inc ---source ../../include/mroonga/load_mroonga_functions.inc ---disable_warnings -DROP DATABASE IF EXISTS mroonga; ---enable_warnings - -CREATE DATABASE mroonga; -USE mroonga; - -CREATE TABLE tags ( +CREATE TABLE terms ( name VARCHAR(64) PRIMARY KEY ) DEFAULT CHARSET=utf8 - COLLATE=utf8_bin - COMMENT='default_tokenizer "TokenDelimit"'; + COMMENT='default_tokenizer "TokenBigram"'; CREATE TABLE bugs ( id INT UNSIGNED PRIMARY KEY, - tags TEXT COMMENT 'flags "COLUMN_VECTOR", type "tags"', - FULLTEXT INDEX bugs_tags_index (tags) COMMENT 'table "tags"' + title TEXT, + FULLTEXT INDEX (title) COMMENT 'table "terms"' ) DEFAULT CHARSET=utf8; -INSERT INTO bugs (id, tags) VALUES (1, "Linux MySQL groonga"); +INSERT INTO bugs (id, title) VALUES (1, "Mroonga can't build with MySQL X.Y.Z"); -SELECT mroonga_command("dump"); +SELECT * FROM terms ORDER BY name; -SELECT *, MATCH (tags) AGAINST ("MySQL" IN BOOLEAN MODE) AS score +SELECT *, MATCH (title) AGAINST ("+MySQL" IN BOOLEAN MODE) AS score FROM bugs - WHERE MATCH (tags) AGAINST ("MySQL" IN BOOLEAN MODE); + WHERE MATCH (title) AGAINST ("+MySQL" IN BOOLEAN MODE); DROP TABLE bugs; -DROP TABLE tags; +DROP TABLE terms; -DROP DATABASE mroonga; - ---source ../../include/mroonga/unload_mroonga_functions.inc --source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_vector_other_table.test b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_vector_other_table.test new file mode 100644 index 00000000000..86ef09cc8bb --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_index_fulltext_vector_other_table.test @@ -0,0 +1,54 @@ +# Copyright(C) 2013 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source include/not_embedded.inc +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_warnings +DROP DATABASE IF EXISTS mroonga; +--enable_warnings + +CREATE DATABASE mroonga; +USE mroonga; + +CREATE TABLE tags ( + name VARCHAR(64) PRIMARY KEY +) DEFAULT CHARSET=utf8 + COLLATE=utf8_bin + COMMENT='default_tokenizer "TokenDelimit"'; + +CREATE TABLE bugs ( + id INT UNSIGNED PRIMARY KEY, + tags TEXT COMMENT 'flags "COLUMN_VECTOR", type "tags"', + FULLTEXT INDEX bugs_tags_index (tags) COMMENT 'table "tags"' +) DEFAULT CHARSET=utf8; + +INSERT INTO bugs (id, tags) VALUES (1, "Linux MySQL groonga"); + +SELECT mroonga_command("dump"); + +SELECT *, MATCH (tags) AGAINST ("+MySQL" IN BOOLEAN MODE) AS score + FROM bugs + WHERE MATCH (tags) AGAINST ("+MySQL" IN BOOLEAN MODE); + +DROP TABLE bugs; +DROP TABLE tags; + +DROP DATABASE mroonga; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_support_lz4.test b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_support_lz4.test new file mode 100644 index 00000000000..5de8f951d8f --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_support_lz4.test @@ -0,0 +1,37 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/support_libgroonga_lz4.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_warnings +DROP TABLE IF EXISTS entries; +--enable_warnings + +CREATE TABLE entries ( + id INT UNSIGNED PRIMARY KEY, + content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_LZ4"' +) DEFAULT CHARSET=utf8; + +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); + +SELECT * FROM entries; + +DROP TABLE entries; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_support_zlib.test b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_support_zlib.test new file mode 100644 index 00000000000..3ec14ebef76 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_support_zlib.test @@ -0,0 +1,37 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/support_libgroonga_zlib.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_warnings +DROP TABLE IF EXISTS entries; +--enable_warnings + +CREATE TABLE entries ( + id INT UNSIGNED PRIMARY KEY, + content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_ZLIB"' +) DEFAULT CHARSET=utf8; + +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); + +SELECT * FROM entries; + +DROP TABLE entries; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_unsupport_lz4.test b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_unsupport_lz4.test new file mode 100644 index 00000000000..324b7ac89f5 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_unsupport_lz4.test @@ -0,0 +1,37 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/unsupport_libgroonga_lz4.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_warnings +DROP TABLE IF EXISTS entries; +--enable_warnings + +CREATE TABLE entries ( + id INT UNSIGNED PRIMARY KEY, + content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_LZ4"' +) DEFAULT CHARSET=utf8; + +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); + +SELECT * FROM entries; + +DROP TABLE entries; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_unsupport_zlib.test b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_unsupport_zlib.test new file mode 100644 index 00000000000..10e77e40e3d --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/column_groonga_scalar_unsupport_zlib.test @@ -0,0 +1,37 @@ +# Copyright(C) 2014 Naoya Murakami +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/unsupport_libgroonga_zlib.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_warnings +DROP TABLE IF EXISTS entries; +--enable_warnings + +CREATE TABLE entries ( + id INT UNSIGNED PRIMARY KEY, + content TEXT COMMENT 'flags "COLUMN_SCALAR|COMPRESS_ZLIB"' +) DEFAULT CHARSET=utf8; + +INSERT INTO entries (id, content) VALUES (1, "I found Mroonga that is a MySQL storage engine to use Groonga!"); + +SELECT * FROM entries; + +DROP TABLE entries; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index.test b/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_comment.test similarity index 100% rename from storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index.test rename to storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_comment.test diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_no_utf8_charset_with_utf8_normalizer.test b/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_no_utf8_charset_with_utf8_normalizer.test similarity index 100% rename from storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_no_utf8_charset_with_utf8_normalizer.test rename to storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_no_utf8_charset_with_utf8_normalizer.test diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_none.test b/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_none.test new file mode 100644 index 00000000000..ae4d4cb9f1b --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_fulltext_index_none.test @@ -0,0 +1,42 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc +--source ../../include/mroonga/load_mroonga_functions.inc + +--disable_warnings +DROP TABLE IF EXISTS diaries; +--enable_warnings + +SET NAMES utf8; + +CREATE TABLE diaries ( + day DATE PRIMARY KEY, + content VARCHAR(64) NOT NULL, + FULLTEXT INDEX (content) COMMENT 'normalizer "none"' +) DEFAULT CHARSET=utf8; + +INSERT INTO diaries VALUES ("2013-04-23", "Mroonga"); + +SELECT * FROM diaries + WHERE MATCH (content) AGAINST ("+Mroonga" IN BOOLEAN MODE); +SELECT * FROM diaries + WHERE MATCH (content) AGAINST ("+mroonga" IN BOOLEAN MODE); + +DROP TABLE diaries; + +--source ../../include/mroonga/unload_mroonga_functions.inc +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_table_comment.test b/storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_primary_key_table_comment.test similarity index 100% rename from storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_table_comment.test rename to storage/mroonga/mysql-test/mroonga/storage/t/create_table_normalizer_primary_key_table_comment.test diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/index_unique_search_after_duplicated.test b/storage/mroonga/mysql-test/mroonga/storage/t/index_unique_search_after_duplicated.test new file mode 100644 index 00000000000..533422ec087 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/index_unique_search_after_duplicated.test @@ -0,0 +1,40 @@ +# Copyright(C) 2015 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +--disable_warnings +DROP TABLE IF EXISTS users; +--enable_warnings + +CREATE TABLE users ( + id int PRIMARY KEY, + name varchar(100) NOT NULL, + UNIQUE KEY (name) +) DEFAULT CHARSET=utf8; + +INSERT INTO users VALUES (1, "Alice"); + +INSERT INTO users VALUES (2, "Bob"); +-- error ER_DUP_ENTRY +INSERT INTO users VALUES (3, "Bob"); + +SELECT * FROM users; +SELECT * FROM users WHERE name = "Bob"; + +DROP TABLE users; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/insert_on_duplicate_key_update_unique_key.test b/storage/mroonga/mysql-test/mroonga/storage/t/insert_on_duplicate_key_update_unique_key.test index 782b7bee9ca..350440515c1 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/t/insert_on_duplicate_key_update_unique_key.test +++ b/storage/mroonga/mysql-test/mroonga/storage/t/insert_on_duplicate_key_update_unique_key.test @@ -29,11 +29,14 @@ CREATE TABLE diaries ( SHOW CREATE TABLE diaries; INSERT INTO diaries (day, title) - VALUES ("2012-02-14", "clear day") - ON DUPLICATE KEY UPDATE title = "clear day (duplicated)"; + VALUES ("2012-02-14", "clear day1") + ON DUPLICATE KEY UPDATE title = "clear day1 (duplicated)"; INSERT INTO diaries (day, title) - VALUES ("2012-02-14", "rainy day") - ON DUPLICATE KEY UPDATE title = "rainy day (duplicated)"; + VALUES ("2012-02-14", "clear day2") + ON DUPLICATE KEY UPDATE title = "clear day2 (duplicated)"; +INSERT INTO diaries (day, title) + VALUES ("2012-02-14", "clear day3") + ON DUPLICATE KEY UPDATE title = "clear day3 (duplicated)"; INSERT INTO diaries (day, title) VALUES ("2012-02-15", "cloudy day") ON DUPLICATE KEY UPDATE title = "cloudy day (duplicated)"; diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/partition_insert.test b/storage/mroonga/mysql-test/mroonga/storage/t/partition_insert.test new file mode 100644 index 00000000000..219c3440d69 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/partition_insert.test @@ -0,0 +1,49 @@ +# Copyright(C) 2015 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +--disable_warnings +DROP TABLE IF EXISTS logs; +--enable_warnings + +SET NAMES UTF8; +CREATE TABLE logs ( + timestamp DATETIME, + message TEXT +) DEFAULT CHARSET=UTF8 + PARTITION BY RANGE (TO_DAYS(timestamp)) ( + PARTITION p201501 VALUES LESS THAN (TO_DAYS('2015-02-01')), + PARTITION p201502 VALUES LESS THAN (TO_DAYS('2015-03-01')), + PARTITION p201503 VALUES LESS THAN (TO_DAYS('2015-04-01')), + PARTITION pfuture VALUES LESS THAN MAXVALUE +); +SHOW CREATE TABLE logs; + +INSERT INTO logs VALUES('2015-01-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-01-31 23:59:59', 'Shutdown'); +INSERT INTO logs VALUES('2015-02-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-02-28 23:59:59', 'Shutdown'); +INSERT INTO logs VALUES('2015-03-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-03-31 23:59:59', 'Shutdown'); +INSERT INTO logs VALUES('2015-04-01 00:00:00', 'Start'); +INSERT INTO logs VALUES('2015-04-30 23:59:59', 'Shutdown'); + +SELECT * FROM logs ORDER BY timestamp; + +DROP TABLE logs; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/replace_without_key.test b/storage/mroonga/mysql-test/mroonga/storage/t/replace_without_key.test new file mode 100644 index 00000000000..a38c4953e67 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/replace_without_key.test @@ -0,0 +1,35 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +--disable_warnings +DROP TABLE IF EXISTS diaries; +--enable_warnings + +SET NAMES utf8; +CREATE TABLE diaries ( + id varchar(32) NOT NULL PRIMARY KEY, + content text, + FULLTEXT INDEX (content) +) DEFAULT CHARSET=utf8; + +-- error ER_ERROR_ON_WRITE +REPLACE INTO diaries(content) VALUES("Hello"); + +DROP TABLE diaries; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_column.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_column.test new file mode 100644 index 00000000000..11ca867d82c --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_column.test @@ -0,0 +1,43 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +SET @mroonga_boolean_mode_syntax_flags_backup = + @@mroonga_boolean_mode_syntax_flags; + +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY,ALLOW_COLUMN"; + +SET NAMES UTF8; + +CREATE TABLE diaries ( + title TEXT, + content TEXT, + FULLTEXT KEY (title), + FULLTEXT KEY (content) +) DEFAULT CHARSET=utf8; + +INSERT INTO diaries VALUES("Groonga", "Hello Groonga"); + +SELECT * FROM diaries + WHERE MATCH(title) AGAINST("content:@Hello" IN BOOLEAN MODE); + +DROP TABLE diaries; + +SET mroonga_boolean_mode_syntax_flags = + @mroonga_boolean_mode_syntax_flags_backup; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_leading_not.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_leading_not.test new file mode 100644 index 00000000000..665682fde6e --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_leading_not.test @@ -0,0 +1,41 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +SET @mroonga_boolean_mode_syntax_flags_backup = + @@mroonga_boolean_mode_syntax_flags; + +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY,ALLOW_LEADING_NOT"; + +SET NAMES UTF8; + +CREATE TABLE diaries ( + title TEXT, + FULLTEXT KEY (title) +) DEFAULT CHARSET=utf8; + +INSERT INTO diaries VALUES("Groonga"); +INSERT INTO diaries VALUES("Mroonga"); + +SELECT * FROM diaries WHERE MATCH(title) AGAINST("-Groonga" IN BOOLEAN MODE); + +DROP TABLE diaries; + +SET mroonga_boolean_mode_syntax_flags = + @mroonga_boolean_mode_syntax_flags_backup; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_update.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_update.test new file mode 100644 index 00000000000..8a55c0fb0f7 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_allow_update.test @@ -0,0 +1,43 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +SET @mroonga_boolean_mode_syntax_flags_backup = + @@mroonga_boolean_mode_syntax_flags; + +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY,ALLOW_COLUMN,ALLOW_UPDATE"; + +SET NAMES UTF8; + +CREATE TABLE diaries ( + title TEXT, + content TEXT, + FULLTEXT KEY (title), + FULLTEXT KEY (content) +) DEFAULT CHARSET=utf8; + +INSERT INTO diaries VALUES("Groonga", "Hello Groonga"); + +SELECT * FROM diaries + WHERE MATCH(title) AGAINST('content:="Hello Mroonga"' IN BOOLEAN MODE); + +DROP TABLE diaries; + +SET mroonga_boolean_mode_syntax_flags = + @mroonga_boolean_mode_syntax_flags_backup; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_syntax_query.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_syntax_query.test new file mode 100644 index 00000000000..0ff2d8aed43 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_syntax_query.test @@ -0,0 +1,40 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +SET @mroonga_boolean_mode_syntax_flags_backup = + @@mroonga_boolean_mode_syntax_flags; + +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_QUERY"; + +SET NAMES UTF8; + +CREATE TABLE diaries ( + title TEXT, + FULLTEXT KEY (title) +) DEFAULT CHARSET=utf8; + +INSERT INTO diaries VALUES("Re:Mroonga"); + +SELECT * FROM diaries WHERE MATCH(title) AGAINST("Re:Mroonga" IN BOOLEAN MODE); + +DROP TABLE diaries; + +SET mroonga_boolean_mode_syntax_flags = + @mroonga_boolean_mode_syntax_flags_backup; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_syntax_script.test b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_syntax_script.test new file mode 100644 index 00000000000..61d5daa63d9 --- /dev/null +++ b/storage/mroonga/mysql-test/mroonga/storage/t/variable_boolean_mode_syntax_flags_syntax_script.test @@ -0,0 +1,41 @@ +# Copyright(C) 2014 Kouhei Sutou +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +--source ../../include/mroonga/have_mroonga.inc + +SET @mroonga_boolean_mode_syntax_flags_backup = + @@mroonga_boolean_mode_syntax_flags; + +SET mroonga_boolean_mode_syntax_flags = "SYNTAX_SCRIPT"; + +SET NAMES UTF8; + +CREATE TABLE diaries ( + title TEXT, + FULLTEXT KEY (title) +) DEFAULT CHARSET=utf8; + +INSERT INTO diaries VALUES("Re:Mroonga"); + +SELECT * FROM diaries + WHERE MATCH(title) AGAINST("title @ 'Re:Mroonga'" IN BOOLEAN MODE); + +DROP TABLE diaries; + +SET mroonga_boolean_mode_syntax_flags = + @mroonga_boolean_mode_syntax_flags_backup; + +--source ../../include/mroonga/have_mroonga_deinit.inc diff --git a/storage/mroonga/packages/Makefile.am b/storage/mroonga/packages/Makefile.am new file mode 100644 index 00000000000..fed925c3dfc --- /dev/null +++ b/storage/mroonga/packages/Makefile.am @@ -0,0 +1,7 @@ +SUBDIRS = \ + apt \ + rpm \ + source \ + ubuntu \ + windows \ + yum diff --git a/storage/mroonga/packages/apt/Makefile.am b/storage/mroonga/packages/apt/Makefile.am new file mode 100644 index 00000000000..26f5609c527 --- /dev/null +++ b/storage/mroonga/packages/apt/Makefile.am @@ -0,0 +1,67 @@ +REPOSITORIES_PATH = repositories +DISTRIBUTIONS = debian +ARCHITECTURES = i386 amd64 +CODE_NAMES = wheezy + +all: + +release: build sign-packages update-repository sign-repository upload + +remove-existing-packages: + for distribution in $(DISTRIBUTIONS); do \ + find $(REPOSITORIES_PATH)/$${distribution}/pool \ + -type f -delete; \ + done + +download: + for distribution in $(DISTRIBUTIONS); do \ + rsync -avz --progress --delete \ + $(RSYNC_PATH)/$${distribution} $(REPOSITORIES_PATH)/; \ + done + +sign-packages: + ./sign-packages.sh '$(GPG_UID)' '$(REPOSITORIES_PATH)/' '$(CODE_NAMES)' + +update-repository: + ./update-repository.sh '$(PACKAGE_NAME)' '$(REPOSITORIES_PATH)/' \ + '$(ARCHITECTURES)' '$(CODE_NAMES)' + +sign-repository: + ./sign-repository.sh '$(GPG_UID)' '$(REPOSITORIES_PATH)/' '$(CODE_NAMES)' + +ensure-rsync-path: + @if test -z "$(RSYNC_PATH)"; then \ + echo "--with-rsync-path configure option must be specified."; \ + false; \ + fi + +upload: ensure-rsync-path + for distribution in $(DISTRIBUTIONS); do \ + (cd $(REPOSITORIES_PATH)/$${distribution}; \ + rsync -avz --progress --delete \ + dists pool $(RSYNC_PATH)/$${distribution}; \ + ); \ + done + +build: build-package-deb + +build-package-deb: prepare-build-package-deb + vagrant destroy --force + for architecture in $(ARCHITECTURES); do \ + for code_name in $(CODE_NAMES); do \ + id=debian-$$code_name-$$architecture; \ + vagrant up $$id || exit 1; \ + vagrant destroy --force $$id; \ + done; \ + done + +prepare-build-package-deb: source env.sh + cp env.sh tmp/ + rm -rf tmp/debian + cp -rp $(srcdir)/../debian tmp/ + +source: tmp/$(PACKAGE)-$(VERSION).tar.gz + +tmp/$(PACKAGE)-$(VERSION).tar.gz: $(abs_top_builddir)/$(PACKAGE)-$(VERSION).tar.gz + mkdir -p tmp + cp $(abs_top_builddir)/$(PACKAGE)-$(VERSION).tar.gz $@ diff --git a/storage/mroonga/packages/apt/Vagrantfile b/storage/mroonga/packages/apt/Vagrantfile new file mode 100644 index 00000000000..4483412326a --- /dev/null +++ b/storage/mroonga/packages/apt/Vagrantfile @@ -0,0 +1,29 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + vms = [ + { + :id => "debian-wheezy-i386", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_debian-7.8-i386_chef-provisionerless.box", + }, + { + :id => "debian-wheezy-amd64", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_debian-7.8_chef-provisionerless.box", + }, + ] + + vms.each do |vm| + config.vm.define(vm[:id]) do |node| + node.vm.box = vm[:id] + node.vm.box_url = vm[:box_url] + node.vm.provision(:shell, :path => "build-deb.sh") + node.vm.provider("virtualbox") do |virtual_box| + virtual_box.memory = 768 + end + end + end +end diff --git a/storage/mroonga/packages/apt/build-deb.sh b/storage/mroonga/packages/apt/build-deb.sh new file mode 100755 index 00000000000..7db24068a7c --- /dev/null +++ b/storage/mroonga/packages/apt/build-deb.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +LANG=C + +mysql_server_package=mysql-server + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +. /vagrant/tmp/env.sh + +grep '^deb ' /etc/apt/sources.list | \ + sed -e 's/^deb /deb-src /' > /etc/apt/sources.list.d/base-source.list + +run apt-get update +run apt-get install -y lsb-release + +distribution=$(lsb_release --id --short | tr 'A-Z' 'a-z') +code_name=$(lsb_release --codename --short) +case "${distribution}" in + debian) + component=main + run cat < /etc/apt/sources.list.d/groonga.list +deb http://packages.groonga.org/debian/ wheezy main +deb-src http://packages.groonga.org/debian/ wheezy main +EOF + if ! grep --quiet security /etc/apt/sources.list; then + run cat < /etc/apt/sources.list.d/security.list +deb http://security.debian.org/ ${code_name}/updates main +deb-src http://security.debian.org/ ${code_name}/updates main +EOF + fi + run apt-get update + run apt-get install -y --allow-unauthenticated groonga-keyring + run apt-get update + ;; + ubuntu) + component=universe + run cat < /etc/apt/sources.list.d/security.list +deb http://security.ubuntu.com/ubuntu ${code_name}-security main restricted +deb-src http://security.ubuntu.com/ubuntu ${code_name}-security main restricted +EOF + run sed -e 's/main/universe/' /etc/apt/sources.list > \ + /etc/apt/sources.list.d/universe.list + run apt-get -y install software-properties-common + run add-apt-repository -y universe + run add-apt-repository -y ppa:groonga/ppa + run apt-get update + ;; +esac + +run apt-get install -V -y build-essential devscripts ${DEPENDED_PACKAGES} +run apt-get build-dep -y ${mysql_server_package} + +run mkdir -p build +run cp /vagrant/tmp/${PACKAGE}-${VERSION}.tar.gz \ + build/${PACKAGE}_${VERSION}.orig.tar.gz +run cd build +run tar xfz ${PACKAGE}_${VERSION}.orig.tar.gz +run cd ${PACKAGE}-${VERSION}/ +run cp -rp /vagrant/tmp/debian debian +# export DEB_BUILD_OPTIONS=noopt +MYSQL_PACKAGE_INFO=$(apt-cache show mysql-server | grep Version | sort | tail -1) +MYSQL_PACKAGE_VERSION=${MYSQL_PACKAGE_INFO##Version: } +sed -i "s/MYSQL_VERSION/$MYSQL_PACKAGE_VERSION/" debian/control +run debuild -us -uc +run cd - + +package_initial=$(echo "${PACKAGE}" | sed -e 's/\(.\).*/\1/') +pool_dir="/vagrant/repositories/${distribution}/pool/${code_name}/${component}/${package_initial}/${PACKAGE}" +run mkdir -p "${pool_dir}/" +run cp *.tar.gz *.diff.gz *.dsc *.deb "${pool_dir}/" diff --git a/storage/mroonga/packages/apt/env.sh.in b/storage/mroonga/packages/apt/env.sh.in new file mode 100644 index 00000000000..a44d6b36871 --- /dev/null +++ b/storage/mroonga/packages/apt/env.sh.in @@ -0,0 +1,15 @@ +PACKAGE=@PACKAGE@ +VERSION=@VERSION@ +DEPENDED_PACKAGES=" +debhelper +autotools-dev +libgroonga-dev +pkg-config +libmecab-dev +mecab-utils +libmysqlclient-dev +libmysqld-dev +libssl-dev +groonga-normalizer-mysql +wget +" diff --git a/storage/mroonga/packages/apt/sign-packages.sh b/storage/mroonga/packages/apt/sign-packages.sh new file mode 100755 index 00000000000..11a4aea26db --- /dev/null +++ b/storage/mroonga/packages/apt/sign-packages.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +script_base_dir=`dirname $0` + +if [ $# != 3 ]; then + echo "Usage: $0 GPG_UID DESITINATION CODES" + echo " e.g.: $0 'F10399C0' repositories/ 'lenny unstable hardy karmic'" + exit 1 +fi + +GPG_UID=$1 +DESTINATION=$2 +CODES=$3 + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +for code_name in ${CODES}; do + case ${code_name} in + squeeze|wheezy|jessie|unstable) + distribution=debian + ;; + *) + distribution=ubuntu + ;; + esac + + base_directory=${DESTINATION}${distribution} + debsign -pgpg2 --re-sign -k${GPG_UID} \ + $(find ${base_directory} -name '*.dsc' -or -name '*.changes') & + if [ "${PARALLEL}" != "yes" ]; then + wait + fi +done + +wait diff --git a/storage/mroonga/packages/apt/sign-repository.sh b/storage/mroonga/packages/apt/sign-repository.sh new file mode 100755 index 00000000000..fb0de850d6f --- /dev/null +++ b/storage/mroonga/packages/apt/sign-repository.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +script_base_dir=`dirname $0` + +if [ $# != 3 ]; then + echo "Usage: $0 GPG_UID DESTINATION CODES" + echo " e.g.: $0 'F10399C0' repositories/ 'lenny unstable hardy karmic'" + exit 1 +fi + +GPG_UID=$1 +DESTINATION=$2 +CODES=$3 + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +for code_name in ${CODES}; do + case ${code_name} in + squeeze|wheezy|jessie|unstable) + distribution=debian + ;; + *) + distribution=ubuntu + ;; + esac + + release=${DESTINATION}${distribution}/dists/${code_name}/Release + rm -f ${release}.gpg + gpg2 --sign --detach-sign --armor \ + --local-user ${GPG_UID} \ + --output ${release}.gpg \ + ${release} & + + if [ "${PARALLEL}" != "yes" ]; then + wait + fi +done + +wait diff --git a/storage/mroonga/packages/apt/update-repository.sh b/storage/mroonga/packages/apt/update-repository.sh new file mode 100755 index 00000000000..da1f8cd121c --- /dev/null +++ b/storage/mroonga/packages/apt/update-repository.sh @@ -0,0 +1,130 @@ +#!/bin/sh + +script_base_dir=`dirname $0` + +if [ $# != 4 ]; then + echo "Usage: $0 PROJECT_NAME DESTINATION ARCHITECTURES CODES" + echo " e.g.: $0 mroonga repositories/ 'i386 amd64' 'lenny unstable hardy karmic'" + exit 1 +fi + +PROJECT_NAME=$1 +DESTINATION=$2 +ARCHITECTURES=$3 +CODES=$4 + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +update_repository() +{ + distribution=$1 + code_name=$2 + component=$3 + + rm -rf dists/${code_name} + mkdir -p dists/${code_name}/${component}/binary-i386/ + mkdir -p dists/${code_name}/${component}/binary-amd64/ + mkdir -p dists/${code_name}/${component}/source/ + + cat < dists/.htaccess +Options +Indexes +EOF + + cat < dists/${code_name}/${component}/binary-i386/Release +Archive: ${code_name} +Component: ${component} +Origin: The ${PROJECT_NAME} project +Label: The ${PROJECT_NAME} project +Architecture: i386 +EOF + + cat < dists/${code_name}/${component}/binary-amd64/Release +Archive: ${code_name} +Component: ${component} +Origin: The ${PROJECT_NAME} project +Label: The ${PROJECT_NAME} project +Architecture: amd64 +EOF + + cat < dists/${code_name}/${component}/source/Release +Archive: ${code_name} +Component: ${component} +Origin: The ${PROJECT_NAME} project +Label: The ${PROJECT_NAME} project +Architecture: source +EOF + + cat < generate-${code_name}.conf +Dir::ArchiveDir "."; +Dir::CacheDir "."; +TreeDefault::Directory "pool/${code_name}/${component}"; +TreeDefault::SrcDirectory "pool/${code_name}/${component}"; +Default::Packages::Extensions ".deb"; +Default::Packages::Compress ". gzip bzip2"; +Default::Sources::Compress ". gzip bzip2"; +Default::Contents::Compress "gzip bzip2"; + +BinDirectory "dists/${code_name}/${component}/binary-i386" { + Packages "dists/${code_name}/${component}/binary-i386/Packages"; + Contents "dists/${code_name}/Contents-i386"; + SrcPackages "dists/${code_name}/${component}/source/Sources"; +}; + +BinDirectory "dists/${code_name}/${component}/binary-amd64" { + Packages "dists/${code_name}/${component}/binary-amd64/Packages"; + Contents "dists/${code_name}/Contents-amd64"; + SrcPackages "dists/${code_name}/${component}/source/Sources"; +}; + +Tree "dists/${code_name}" { + Sections "${component}"; + Architectures "i386 amd64 source"; +}; +EOF + apt-ftparchive generate generate-${code_name}.conf + chmod 644 dists/${code_name}/Contents-* + + rm -f dists/${code_name}/Release* + rm -f *.db + cat < release-${code_name}.conf +APT::FTPArchive::Release::Origin "The ${PROJECT_NAME} project"; +APT::FTPArchive::Release::Label "The ${PROJECT_NAME} project"; +APT::FTPArchive::Release::Architectures "i386 amd64"; +APT::FTPArchive::Release::Codename "${code_name}"; +APT::FTPArchive::Release::Suite "${code_name}"; +APT::FTPArchive::Release::Components "${component}"; +APT::FTPArchive::Release::Description "${PACKAGE_NAME} packages"; +EOF + apt-ftparchive -c release-${code_name}.conf \ + release dists/${code_name} > /tmp/Release + mv /tmp/Release dists/${code_name} +} + +for code_name in ${CODES}; do + case ${code_name} in + squeeze|wheezy|jessie|unstable) + distribution=debian + component=main + ;; + *) + distribution=ubuntu + component=universe + ;; + esac + + mkdir -p ${DESTINATION}${distribution} + (cd ${DESTINATION}${distribution} + update_repository $distribution $code_name $component) & + if [ "${PARALLEL}" != "yes" ]; then + wait + fi +done + +wait diff --git a/storage/mroonga/packages/check-utility.sh b/storage/mroonga/packages/check-utility.sh new file mode 100755 index 00000000000..211e231a473 --- /dev/null +++ b/storage/mroonga/packages/check-utility.sh @@ -0,0 +1,665 @@ +#!/bin/sh + +# Usage: check-utility.sh [--install-groonga] +# [--check-install] +# [--check-address] +# [--enable-repository] +# +# CODES="squeeze wheezy unstable lucid natty oneiric precise" +# DISTRIBUTIONS="centos fedora" + +CHROOT_ROOT=/var/lib/chroot +CHECK_ADDRESS=0 +CHECK_INSTALL=0 +CHECK_INSTALL_PACKAGE=mysql-server-mroonga +CHECK_BUILD=0 +CHECK_DEPENDS=0 +CHECK_PROVIDES=0 +ENABLE_REPOSITORY=0 +DISABLE_REPOSITORY=0 +INSTALL_SCRIPT=0 +INSTALL_MROONGA=0 +UNINSTALL_MROONGA=0 + +common_deb_procedure () +{ + for code in $CODES; do + for arch in $DEB_ARCHITECTURES; do + root_dir=$CHROOT_ROOT/$code-$arch + eval $1 $code $arch $root_dir + done + done +} + +common_rpm_procedure () +{ + for dist in $DISTRIBUTIONS; do + case $dist in + "fedora") + DISTRIBUTIONS_VERSION="19" + ;; + "centos") + DISTRIBUTIONS_VERSION="5 6" + ;; + esac + for ver in $DISTRIBUTIONS_VERSION; do + for arch in $RPM_ARCHITECTURES; do + root_dir=$CHROOT_ROOT/$dist-$ver-$arch + eval $1 $dist $arch $ver $root_dir + done + done + done +} + +echo_packages_repository_address () +{ + root_dir=$1 + code=$2 + arch=$3 + address=`grep "packages.groonga.org" $root_dir/etc/hosts | grep -v "#"` + if [ -z "$address" ]; then + echo "$code-$arch: default" + else + echo "$code-$arch: $address" + fi +} + +setup_distributions () +{ + if [ -z "$DISTRIBUTIONS" ]; then + DISTRIBUTIONS="centos fedora" + fi +} + +setup_rpm_architectures () +{ + if [ -z "$RPM_ARCHITECTURES" ]; then + RPM_ARCHITECTURES="i386 x86_64" + fi +} + +setup_codes () +{ + if [ -z "$CODES" ]; then + CODES="squeeze wheezy jessie unstable lucid precise quantal raring" + fi +} +setup_deb_architectures () +{ + if [ -z "$DEB_ARCHITECTURES" ]; then + DEB_ARCHITECTURES="i386 amd64" + fi +} + +check_packages_repository_address () +{ + common_deb_procedure "check_packages_deb_repository_address" + common_rpm_procedure "check_packages_rpm_repository_address" +} + +check_packages_deb_repository_address () +{ + code=$1 + arch=$2 + root_dir=$4 + echo_packages_repository_address "$root_dir" "$code" "$arch" +} + +check_packages_rpm_repository_address () +{ + dist=$1 + arch=$2 + ver=$3 + root_dir=$4 + echo_packages_repository_address "$root_dir" "$dist-$ver" "$arch" +} + +host_address () +{ + ifconfig_result=`LANG=C /sbin/ifconfig wlan0` + inet_addr=`echo "$ifconfig_result" | grep "inet addr:192"` + address=`echo $inet_addr | ruby -ne '/inet addr:(.+?)\s/ =~ $_ && puts($1)'` + HOST_ADDRESS=$address +} + +check_build_packages () +{ + common_deb_procedure "check_build_deb_packages" + common_rpm_procedure "check_build_rpm_packages" +} + +check_build_deb_packages () +{ + code=$1 + arch=$2 + BASE_VERSION=`cat ../version` + RESULT_SET=`find apt/repositories -name "*$BASE_VERSION*" | grep $code | grep $arch` + if [ -z "$RESULT_SET" ]; then + printf "%8s %5s %s => 0 deb\n" $code $arch $BASE_VERSION + else + PACKAGE_COUNT=`find apt/repositories -name "*$BASE_VERSION*" | grep $code | grep $arch | wc | awk '{print \$1}'` + printf "%8s %5s %s => %2d debs\n" $code $arch $BASE_VERSION $PACKAGE_COUNT + fi +} + +check_build_rpm_packages () +{ + dist=$1 + arch=$2 + ver=$3 + BASE_VERSION=`cat ../version` + FIND_PATH=yum/repositories/$dist/$ver/$arch + RESULT_SET=`find $FIND_PATH -name "*$BASE_VERSION*"` + if [ -z "$RESULT_SET" ]; then + printf "%8s %6s %s => 0 rpm\n" $dist$ver $arch $BASE_VERSION + else + PACKAGE_COUNT=`find $FIND_PATH -name "*$BASE_VERSION*" | wc -l` + printf "%8s %6s %s => %2d rpms\n" $dist$ver $arch $BASE_VERSION $PACKAGE_COUNT + fi +} + +check_depends_packages () +{ + common_deb_procedure "check_depends_deb_packages" + common_rpm_procedure "check_depends_rpm_packages" +} + +check_depends_deb_packages () +{ + code=$1 + arch=$2 + BASE_VERSION=`cat ../version` + FIND_PATH=apt/repositories/*/pool/$code + RESULT_SET=`find $FIND_PATH -name "*$BASE_VERSION*.deb"` + if [ -z "$RESULT_SET" ]; then + printf "%8s %5s %s => 404 deb\n" $code $arch $BASE_VERSION + else + for pkg in $RESULT_SET; do + DEB_NAME=`basename $pkg` + DEPENDS=`dpkg -I $pkg | grep "Depends"` + printf "%8s %5s %s => %s\n" $code $arch $DEB_NAME "$DEPENDS" + done + fi +} + +check_depends_rpm_packages () +{ + dist=$1 + arch=$2 + ver=$3 + BASE_VERSION=`cat ../version` + FIND_PATH=yum/repositories/$dist/$ver/$arch + RESULT_SET=`find $FIND_PATH -name "*$BASE_VERSION*"` + if [ -z "$RESULT_SET" ]; then + printf "%8s %6s %s => 404 rpm\n" $dist$ver $arch $BASE_VERSION + else + for pkg in $RESULT_SET; do + RPM_NAME=`basename $pkg` + DEPENDS=`rpm -qp --requires $pkg | grep -i "mysql" | tr -t '\n' ' '` + printf "%9s %6s %s => %s\n" $dist$ver $arch $RPM_NAME "$DEPENDS" + done + fi +} + +check_provided_mysql_packages () +{ + common_deb_procedure "check_provided_mysql_deb_packages" + common_rpm_procedure "check_provided_mysql_rpm_packages" + for code in $CODES; do + echo $code + cat tmp/$code-amd64-mysql-server.txt + done + for dist in $DISTRIBUTIONS; do + echo $dist + cat tmp/$dist-x86_64-mysql-server.txt + done +} + +check_provided_mysql_deb_packages () +{ + code=$1 + arch=$2 + root_dir=$3 + cat > tmp/check-provided-mysql.sh < /dev/null +apt-cache show mysql-server | grep "Version" | head -1 > /tmp/$code-$arch-mysql-server.txt +EOF + if [ -d $root_dir ]; then + CHECK_SCRIPT=check-provided-mysql.sh + echo "copy check script $CHECK_SCRIPT to $root_dir/tmp" + sudo rm -f $root_dir/tmp/$CHECK_SCRIPT + cp tmp/$CHECK_SCRIPT $root_dir/tmp + sudo chmod 755 $root_dir/tmp/$CHECK_SCRIPT + sudo chname $code-$arch chroot $root_dir /tmp/$CHECK_SCRIPT + cp $root_dir/tmp/$code-$arch-mysql-server.txt tmp + fi +} + +check_provided_mysql_rpm_packages () +{ + dist=$1 + arch=$2 + ver=$3 + root_dir=$4 + cat > tmp/check-provided-mysql.sh < /dev/null +yum info mysql-server | grep "Version" > /tmp/$code-$arch-mysql-server.txt +EOF + if [ -d $root_dir ]; then + CHECK_SCRIPT=check-provided-mysql.sh + echo "copy check script $CHECK_SCRIPT to $root_dir/tmp" + sudo rm -f $root_dir/tmp/$CHECK_SCRIPT + cp tmp/$CHECK_SCRIPT $root_dir/tmp + sudo chmod 755 $root_dir/tmp/$CHECK_SCRIPT + sudo chname $code-$arch chroot $root_dir /tmp/$CHECK_SCRIPT + cp $root_dir/tmp/$code-$arch-mysql-server.txt tmp + fi +} + +check_installed_mroonga_packages () +{ + common_deb_procedure "check_installed_mroonga_deb_packages" + common_rpm_procedure "check_installed_mroonga_rpm_packages" +} + +check_installed_mroonga_deb_packages () +{ + code=$1 + arch=$2 + root_dir=$3 + cat > tmp/check-deb-mroonga.sh < tmp/check-rpm-mroonga.sh < tmp/install-aptitude-mroonga.sh < tmp/install-aptget-mroonga.sh < tmp/install-centos5-mroonga.sh < tmp/install-centos6-mroonga.sh < tmp/install-fedora-mroonga.sh < $UNINSTALL_SCRIPT < tmp/$UNINSTALL_SCRIPT < tmp/enable-repository.sh < /tmp/hosts +echo "$HOST_ADDRESS packages.groonga.org" >> /tmp/hosts +cp -f /tmp/hosts /etc/hosts +EOF + common_deb_procedure "enable_temporaly_mroonga_deb_repository" + common_rpm_procedure "enable_temporaly_mroonga_rpm_repository" + check_packages_repository_address +} + +enable_temporaly_mroonga_deb_repository () +{ + code=$1 + arch=$2 + root_dir=$4 + today=`date '+%Y%m%d.%s'` + if [ -d $root_dir ]; then + sudo cp $root_dir/etc/hosts $root_dir/etc/hosts.$today + sudo cp tmp/enable-repository.sh $root_dir/tmp + sudo chname $code-$arch chroot $root_dir /tmp/enable-repository.sh + fi +} + +enable_temporaly_mroonga_rpm_repository () +{ + dist=$1 + arch=$2 + ver=$3 + root_dir=$4 + today=`date '+%Y%m%d.%s'` + if [ -d $root_dir ]; then + sudo cp $root_dir/etc/hosts $root_dir/etc/hosts.$today + sudo cp tmp/enable-repository.sh $root_dir/tmp + sudo chname $code-$arch chroot $root_dir /tmp/enable-repository.sh + fi +} + +disable_temporaly_mroonga_repository () +{ + cat > tmp/disable-repository.sh < /tmp/hosts +cp -f /tmp/hosts /etc/hosts +EOF + common_deb_procedure "disable_temporaly_mroonga_deb_repository" + common_rpm_procedure "disable_temporaly_mroonga_rpm_repository" + check_packages_repository_address +} + +disable_temporaly_mroonga_deb_repository () +{ + code=$1 + arch=$2 + root_dir=$4 + DISABLE_SCRIPT=disable-repository.sh + today=`date '+%Y%m%d.%s'` + if [ -d $root_dir ]; then + sudo cp $root_dir/etc/hosts $root_dir/etc/hosts.$today + cp tmp/$DISABLE_SCRIPT $root_dir/tmp + chmod 755 $root_dir/tmp/$DISABLE_SCRIPT + sudo chname $code-$arch chroot $root_dir /tmp/$DISABLE_SCRIPT + fi + +} + +disable_temporaly_mroonga_rpm_repository () +{ + dist=$1 + arch=$2 + ver=$3 + root_dir=$4 + DISABLE_SCRIPT=disable-repository.sh + today=`date '+%Y%m%d.%s'` + if [ -d $root_dir ]; then + sudo cp $root_dir/etc/hosts $root_dir/etc/hosts.$today + cp tmp/$DISABLE_SCRIPT $root_dir/tmp + chmod 755 $root_dir/tmp/$DISABLE_SCRIPT + sudo chname $code-$arch chroot $root_dir /tmp/$DISABLE_SCRIPT + fi +} + +host_address +echo $HOST_ADDRESS + +while [ $# -ne 0 ]; do + case $1 in + --check-install) + CHECK_INSTALL=1 + shift + if [ ! -z "$1" ]; then + case $1 in + groonga|mroonga|roonga|mecab|mysql) + CHECK_INSTALL_PACKAGE=$1 + ;; + *) + ;; + esac + fi + ;; + --check-address) + CHECK_ADDRESS=1 + shift + ;; + --check-depends) + CHECK_DEPENDS=1 + shift + ;; + --check-provides) + CHECK_PROVIDES=1 + shift + ;; + --check-build) + CHECK_BUILD=1 + shift + ;; + --enable-repository) + ENABLE_REPOSITORY=1 + shift + ;; + --disable-repository) + DISABLE_REPOSITORY=1 + shift + ;; + --install-mroonga) + INSTALL_MROONGA=1 + shift + ;; + --uninstall-mroonga) + UNINSTALL_MROONGA=1 + shift + ;; + --code) + shift + if [ "$1" = "all" ]; then + setup_codes + else + CODES=$1 + fi + shift + ;; + --code-arch) + shift + if [ "$1" = "all" ]; then + setup_deb_architectures + else + DEB_ARCHITECTURES=$1 + fi + shift + ;; + --dist) + shift + if [ "$1" = "all" ]; then + setup_distributions + else + DISTRIBUTIONS=$1 + fi + shift + ;; + --dist-arch) + shift + if [ "$1" = "all" ]; then + setup_rpm_architectures + else + RPM_ARCHITECTURES=$1 + fi + shift + ;; + *) + shift + ;; + esac +done + +mkdir -p tmp +setup_deb_architectures +setup_rpm_architectures + +if [ $CHECK_INSTALL -ne 0 ]; then + check_installed_mroonga_packages +fi +if [ $CHECK_ADDRESS -ne 0 ]; then + check_packages_repository_address +fi +if [ $CHECK_BUILD -ne 0 ]; then + check_build_packages +fi +if [ $CHECK_DEPENDS -ne 0 ]; then + check_depends_packages +fi +if [ $CHECK_PROVIDES -ne 0 ]; then + check_provided_mysql_packages +fi +if [ $ENABLE_REPOSITORY -ne 0 ]; then + enable_temporaly_mroonga_repository +fi +if [ $DISABLE_REPOSITORY -ne 0 ]; then + disable_temporaly_mroonga_repository +fi +if [ $INSTALL_MROONGA -ne 0 ]; then + install_mroonga_packages +fi +if [ $UNINSTALL_MROONGA -ne 0 ]; then + uninstall_mroonga_packages +fi + diff --git a/storage/mroonga/packages/debian/apparmor/mysql-server-mroonga b/storage/mroonga/packages/debian/apparmor/mysql-server-mroonga new file mode 100644 index 00000000000..259f8d1dc0c --- /dev/null +++ b/storage/mroonga/packages/debian/apparmor/mysql-server-mroonga @@ -0,0 +1,5 @@ +/usr/lib/groonga/plugins/ r, +/usr/lib/groonga/plugins/** rm, +/etc/mecabrc r, +/var/lib/mecab/dic/** r, +#include diff --git a/storage/mroonga/packages/debian/changelog b/storage/mroonga/packages/debian/changelog new file mode 100644 index 00000000000..6aa6fd58d17 --- /dev/null +++ b/storage/mroonga/packages/debian/changelog @@ -0,0 +1,391 @@ +mroonga (5.00-1) unstable; urgency=low + + * New upstream release. + + -- Mon, 09 Feb 2015 00:00:00 +0900 + +mroonga (4.10-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Thu, 29 Jan 2015 00:00:00 +0900 + +mroonga (4.09-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Mon, 29 Dec 2014 00:00:00 +0900 + +mroonga (4.08-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sat, 29 Nov 2014 00:00:00 +0900 + +mroonga (4.07-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Wed, 29 Oct 2014 00:00:00 +0900 + +mroonga (4.06-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Mon, 29 Sep 2014 00:00:00 +0900 + +mroonga (4.05-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Fri, 29 Aug 2014 00:00:00 +0900 + +mroonga (4.04-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Tue, 29 Jul 2014 00:00:00 +0900 + +mroonga (4.03-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Thu, 29 May 2014 00:00:00 +0900 + +mroonga (4.02-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Tue, 29 Apr 2014 00:00:00 +0900 + +mroonga (4.01-2) unstable; urgency=low + + * Built for mysql-server 5.5.37 + + -- HAYASHI Kentaro Mon, 28 Apr 2014 00:00:00 +0900 + +mroonga (4.01-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sat, 29 Mar 2014 00:00:00 +0900 + +mroonga (4.00-2) unstable; urgency=low + + * Built for mysql-server 5.5.35+dfsg-2 on Debian jessie + * Built for mysql-server 5.5.35+dfsg-2 on Debian sid + + -- HAYASHI Kentaro Thu, 06 Mar 2014 00:00:00 +0900 + +mroonga (4.00-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sun, 09 Feb 2014 00:00:00 +0900 + +mroonga (3.12-2) unstable; urgency=low + + * Built for mysql-server updates on Ubuntu 12.04,12.10, and 13.10. + + -- HAYASHI Kentaro Wed, 29 Jan 2014 13:12:56 +0900 + +mroonga (3.12-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Wed, 29 Jan 2014 00:00:00 +0900 + +mroonga (3.11-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sun, 29 Dec 2013 00:00:00 +0900 + +mroonga (3.10-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Fri, 29 Nov 2013 00:00:00 +0900 + +mroonga (3.09-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Tue, 29 Oct 2013 00:00:00 +0900 + +mroonga (3.08-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sun, 29 Sep 2013 00:00:00 +0900 + +mroonga (3.07-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Thu, 29 Aug 2013 00:00:00 +0900 + +mroonga (3.06-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Mon, 29 Jul 2013 00:00:00 +0900 + +mroonga (3.05-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sat, 29 Jun 2013 00:00:00 +0900 + +mroonga (3.04-2) unstable; urgency=low + + * Built for mysql-server 5.5.31-0ubuntu0.12.04.2 on Ubuntu 12.04 (precise) + + -- HAYASHI Kentaro Thu, 13 Jun 2013 00:00:00 +0900 + +mroonga (3.04-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Wed, 29 May 2013 00:00:00 +0900 + +mroonga (3.03-2) unstable; urgency=low + + * Built for mysql-server 5.5.31+dfsg-0+wheezy1 on Debian wheezy + * Built for mysql-server 5.5.31+dfsg-1 on Debian unstable + + -- HAYASHI Kentaro Thu, 16 May 2013 00:00:00 +0900 + +mroonga (3.03-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Mon, 29 Apr 2013 00:00:00 +0900 + +mroonga (3.02-2) unstable; urgency=low + + * Built for mysql-server 5.5.29-0ubuntu0.12.04.2 on Ubuntu 12.04 (precise) + + -- HAYASHI Kentaro Fri, 29 Mar 2013 22:15:39 +0900 + +mroonga (3.02-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Fri, 29 Mar 2013 00:00:00 +0900 + +mroonga (3.01-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Thu, 28 Feb 2013 00:00:00 +0900 + +mroonga (3.00-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sat, 09 Feb 2013 00:00:00 +0900 + +mroonga (2.10-2) unstable; urgency=low + + * Built for mysql-server 5.5.29+dfsg-1 on Debian/unstable. + * Built for mysql-server 5.1.67-0ubuntu0.10.04.1 on Ubuntu 10.04(lucid). + * Built for mysql-server 5.1.67-0ubuntu0.11.10.1 on Ubuntu 11.10(oneiric). + * Built for mysql-server 5.5.29-0ubuntu0.12.04.1 on Ubuntu 12.04(precise). + * Built for mysql-server 5.5.29-0ubuntu0.12.10.1 on Ubuntu 12.10(quantal). + + -- HAYASHI Kentaro Thu, 24 Jan 2013 10:28:16 +0900 + +mroonga (2.10-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sat, 29 Dec 2012 00:00:00 +0900 + +mroonga (2.09-2) unstable; urgency=low + + * Built for mysql-server 5.5.28-0ubuntu0.12.10.2 on Ubuntu 12.10. + Reported by @watanabekiyokaz + + -- HAYASHI Kentaro Wed, 12 Dec 2012 13:28:00 +0900 + +mroonga (2.09-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Thu, 29 Nov 2012 00:00:00 +0900 + +mroonga (2.08-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Mon, 29 Oct 2012 00:00:00 +0900 + +mroonga (2.07-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sat, 29 Sep 2012 00:00:00 +0900 + +mroonga (2.06-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Wed, 29 Aug 2012 00:00:00 +0900 + +mroonga (2.05-1) unstable; urgency=low + + * New upstream release. + + -- HAYASHI Kentaro Sun, 29 Jul 2012 00:00:00 +0900 + +mroonga (2.04-1) unstable; urgency=low + + * New upstream release. + * Ensure deleting mroonga plugin before install. + Suggested by Kazuhiro Isobe. Thanks!!! + + -- Kouhei Sutou Fri, 29 Jun 2012 00:00:00 +0900 + +mroonga (2.03-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Tue, 29 May 2012 00:00:00 +0900 + +mroonga (2.02-1) unstable; urgency=low + + * New upstream release. + * Require groonga >= 2.0.2. + + -- Kouhei Sutou Sun, 29 Apr 2012 00:00:00 +0900 + +mroonga (2.01-1) unstable; urgency=low + + * New upstream release. + * Ensure plugin is uninstalled by closing all tables use mroonga. + + -- Kouhei Sutou Thu, 29 Mar 2012 00:00:00 +0900 + +mroonga (2.00-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Wed, 29 Feb 2012 00:00:00 +0900 + +mroonga (1.20-1) unstable; urgency=low + + * New upstream release. + * Add mysql-server-mroonga-compatible package for "groonga" storage engine. + + -- Kouhei Sutou Sun, 29 Jan 2012 00:00:00 +0900 + +mroonga (1.11-1) unstable; urgency=low + + * New upstream release. + * Change apparmor configuration file name: + mysql-server-groonga -> mysql-server-mroonga + + -- Kouhei Sutou Thu, 29 Dec 2011 00:00:00 +0900 + +mroonga (1.10-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Sat, 29 Oct 2011 00:00:00 +0900 + +groonga-storage-engine (1.0.0-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Thu, 29 Sep 2011 00:00:00 +0900 + +groonga-storage-engine (0.9-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Mon, 29 Aug 2011 00:00:00 +0900 + +groonga-storage-engine (0.8-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Fri, 29 Jul 2011 00:00:00 +0900 + +groonga-storage-engine (0.7-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Wed, 29 Jun 2011 00:00:00 +0900 + +groonga-storage-engine (0.6-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Sun, 29 May 2011 00:00:00 +0900 + +groonga-storage-engine (0.5-4) unstable; urgency=low + + * fix a typo. + + -- Kouhei Sutou Tue, 30 Mar 2011 01:05:00 +0900 + +groonga-storage-engine (0.5-3) unstable; urgency=low + + * fix AppArmor files. + + -- Kouhei Sutou Tue, 30 Mar 2011 00:59:00 +0900 + +groonga-storage-engine (0.5-2) unstable; urgency=low + + * hook script fix. + + -- Kouhei Sutou Tue, 30 Mar 2011 00:58:00 +0900 + +groonga-storage-engine (0.5-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Tue, 29 Mar 2011 00:00:00 +0900 + +groonga-storage-engine (0.4-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Mon, 29 Nov 2010 00:00:00 +0900 + +groonga-storage-engine (0.3-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Fri, 29 Oct 2010 16:34:04 +0900 + +groonga-storage-engine (0.2-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Sat, 25 Sep 2010 14:52:49 +0900 + +groonga-storage-engine (0.1-4) unstable; urgency=low + + * follow configure option changes. + + -- Kouhei Sutou Fri, 10 Sep 2010 08:45:53 +0900 + +groonga-storage-engine (0.1-3) unstable; urgency=low + + * Use HEAD. + + -- Kouhei Sutou Thu, 02 Sep 2010 12:03:46 +0900 + +groonga-storage-engine (0.1-2) unstable; urgency=low + + * Built with groonga 1.0.0. + + -- Kouhei Sutou Mon, 30 Aug 2010 13:26:25 +0900 + +groonga-storage-engine (0.1-1) unstable; urgency=low + + * New upstream release. + + -- Kouhei Sutou Mon, 23 Aug 2010 13:52:01 +0900 diff --git a/storage/mroonga/packages/debian/compat b/storage/mroonga/packages/debian/compat new file mode 100644 index 00000000000..ec635144f60 --- /dev/null +++ b/storage/mroonga/packages/debian/compat @@ -0,0 +1 @@ +9 diff --git a/storage/mroonga/packages/debian/control.in b/storage/mroonga/packages/debian/control.in new file mode 100644 index 00000000000..d6d03fa9a4e --- /dev/null +++ b/storage/mroonga/packages/debian/control.in @@ -0,0 +1,51 @@ +Source: mroonga +Section: database +Priority: optional +Maintainer: Kouhei Sutou +Build-Depends: + debhelper (>= 7.0.50), + autotools-dev, + pkg-config, + libgroonga-dev (>= @REQUIRED_GROONGA_VERSION@), + groonga-normalizer-mysql, + libmysqlclient-dev, + libmysqld-dev, + libssl-dev, + wget, + lsb-release +Standards-Version: 3.9.1 +Homepage: http://mroonga.org/ + +Package: mysql-server-mroonga +Section: database +Architecture: any +Replaces: mysql-server-groonga (<< 1.10-1) +Breaks: mysql-server-groonga (<< 1.10-1) +Depends: + ${misc:Depends}, + ${shlibs:Depends}, + libgroonga0 (>= @REQUIRED_GROONGA_VERSION@), + mysql-server (= MYSQL_VERSION), + groonga-normalizer-mysql +Description: A fast fulltext searchable storage engine for MySQL. + Mroonga is a fast fulltext searchable storage engine for MySQL. + It is based on Groonga, a fast fulltext search engine and column store. + Groonga is good at real time update. + . + This package provides a MySQL storage engine as a shared library. + This provides "mroonga" storage engine. It means you can use + "ENGINE = mroonga" in "CREATE TABLE". + +Package: mysql-server-mroonga-doc +Section: doc +Architecture: all +Replaces: mysql-server-groonga-doc (<< 1.10-1) +Breaks: mysql-server-groonga-doc (<< 1.10-1) +Depends: + ${misc:Depends} +Description: Documentation of Mroonga. + Mroonga is a fast fulltext searchable storage engine for MySQL. + It is based on Groonga, a fast fulltext search engine and column store. + Groonga is good at real time update. + . + This package provides documentation of Mroonga. diff --git a/storage/mroonga/packages/debian/copyright b/storage/mroonga/packages/debian/copyright new file mode 100644 index 00000000000..bb41984e8e4 --- /dev/null +++ b/storage/mroonga/packages/debian/copyright @@ -0,0 +1,27 @@ +This work was packaged for Debian by: + + Kouhei Sutou on Thu, 02 Sep 2010 13:51:56 +0900. + +It was downloaded: + + + +Upstream Author(s): + + Tetsuro IKEDA + Daijiro MORI + Tasuku SUENAGA + Kouhei Sutou + +Copyright: + + Copyright(C) 2009-2010 Tetsuro IKEDA + +License: + + LGPLv2.1 + + See `/usr/share/common-licenses/LGPL-2.1'. + +The Debian packaging is done by Kouhei Sutou in 2010, +and put into public domain, anyone can use it for any purpose. diff --git a/storage/mroonga/packages/debian/mysql-server-mroonga-doc.install b/storage/mroonga/packages/debian/mysql-server-mroonga-doc.install new file mode 100644 index 00000000000..ad2e27ef7dd --- /dev/null +++ b/storage/mroonga/packages/debian/mysql-server-mroonga-doc.install @@ -0,0 +1 @@ +usr/share/doc/mysql-server-mroonga-doc/ diff --git a/storage/mroonga/packages/debian/mysql-server-mroonga.install b/storage/mroonga/packages/debian/mysql-server-mroonga.install new file mode 100644 index 00000000000..03f64cfedb4 --- /dev/null +++ b/storage/mroonga/packages/debian/mysql-server-mroonga.install @@ -0,0 +1,3 @@ +usr/lib/mysql/plugin/ha_mroonga.so* +usr/share/mroonga/* +debian/apparmor/mysql-server-mroonga etc/apparmor.d/abstractions/ diff --git a/storage/mroonga/packages/debian/mysql-server-mroonga.postinst b/storage/mroonga/packages/debian/mysql-server-mroonga.postinst new file mode 100755 index 00000000000..9a3db8784a2 --- /dev/null +++ b/storage/mroonga/packages/debian/mysql-server-mroonga.postinst @@ -0,0 +1,72 @@ +#! /bin/sh + +set -e + +prevver="$2" + +install_plugin() { + cat /usr/share/mroonga/install.sql | \ + mysql --defaults-file=/etc/mysql/debian.cnf || true +} + +install_apparmor() { + mysql_apparmor_profile_name=usr.sbin.mysqld + mysql_apparmor_profile=/etc/apparmor.d/${mysql_apparmor_profile_name} + mysql_local_apparmor_profile=/etc/apparmor.d/local/${mysql_apparmor_profile_name} + apparmor_profile_name=mysql-server-mroonga + include_profile="#include " + local_apparmor_profile=/etc/apparmor.d/local/${apparmor_profile_name} + if test -f "${mysql_local_apparmor_profile}"; then + if ! grep -q "${include_profile}" "${mysql_local_apparmor_profile}"; then + echo >> "${mysql_local_apparmor_profile}" + echo "${include_profile}" >> "${mysql_local_apparmor_profile}" + fi + else + mysql_abstraction_apparmor_profile=/etc/apparmor.d/abstractions/mysql + mysql_plugin_dir=/usr/lib/mysql/plugin + if test -f "${mysql_abstraction_apparmor_profile}" && \ + ! grep -q "${mysql_plugin_dir}" \ + "${mysql_abstraction_apparmor_profile}"; then + # For Lucid. + cat <> "${mysql_abstraction_apparmor_profile}" + +# ${apparmor_profile_name}: START +# Added by mysql-server-mroonga. +${mysql_plugin_dir}/ r, +${mysql_plugin_dir}/*.so* mr, +${include_profile} +# ${apparmor_profile_name}: END +EOF + fi + fi + + if ! test -e "$local_apparmor_profile"; then + mkdir -p $(dirname "$local_apparmor_profile") + cat < "$local_apparmor_profile" +# Site-specific additions and overrides for ${apparmor_profile_name}. +# For more details, please see /etc/apparmor.d/local/README. +EOF + fi + + if aa-status --enabled 2>/dev/null; then + apparmor_parser -r -T -W "${mysql_apparmor_profile}" || true + fi + + true +} + +case "$1" in + configure) + install_apparmor + install_plugin + ;; + abort-upgrade|abort-deconfigure|abort-remove) + : + ;; + *) + echo "Called with unknown argument $1, bailing out." + exit 1 + ;; +esac + +#DEBHELPER# diff --git a/storage/mroonga/packages/debian/mysql-server-mroonga.postrm b/storage/mroonga/packages/debian/mysql-server-mroonga.postrm new file mode 100755 index 00000000000..84d7f1ef4ab --- /dev/null +++ b/storage/mroonga/packages/debian/mysql-server-mroonga.postrm @@ -0,0 +1,38 @@ +#! /bin/sh + +set -e + +if [ "$1" = "purge" ]; then + mysql_apparmor_profile_name=usr.sbin.mysqld + mysql_apparmor_profile=/etc/apparmor.d/${mysql_apparmor_profile_name} + mysql_local_apparmor_profile=/etc/apparmor.d/local/${mysql_apparmor_profile_name} + mysql_abstraction_apparmor_profile=/etc/apparmor.d/abstractions/mysql + apparmor_profile_name=mysql-server-mroonga + if test -f "${mysql_local_apparmor_profile}"; then + include_profile="#include " + if grep -q "${include_profile}" "${mysql_local_apparmor_profile}"; then + sed -i'' -e "s,${include_profile},," \ + "${mysql_local_apparmor_profile}" + fi + else + start_marker_re="^# ${apparmor_profile_name}: START$" + end_marker_re="^# ${apparmor_profile_name}: END$" + if test -f "${mysql_abstraction_apparmor_profile}" && \ + grep -q "${start_marker_re}" \ + "${mysql_abstraction_apparmor_profile}"; then + sed -i'' -e "/${start_marker_re}/,/${end_marker_re}/d" \ + "${mysql_abstraction_apparmor_profile}" + fi + fi + + rm -f "/etc/apparmor.d/local/${apparmor_profile_name}" || true + rmdir /etc/apparmor.d/local 2>/dev/null || true + + if aa-status --enabled 2>/dev/null; then + apparmor_parser -r -T -W "${mysql_apparmor_profile}" || true + fi +fi + +#DEBHELPER# + +exit 0 diff --git a/storage/mroonga/packages/debian/mysql-server-mroonga.prerm b/storage/mroonga/packages/debian/mysql-server-mroonga.prerm new file mode 100755 index 00000000000..7fad990d75f --- /dev/null +++ b/storage/mroonga/packages/debian/mysql-server-mroonga.prerm @@ -0,0 +1,10 @@ +#! /bin/sh + +set -e + +cat /usr/share/mroonga/uninstall.sql | \ + mysql --defaults-file=/etc/mysql/debian.cnf || true + +#DEBHELPER# + +exit 0 diff --git a/storage/mroonga/packages/debian/rules b/storage/mroonga/packages/debian/rules new file mode 100755 index 00000000000..2a397b333e1 --- /dev/null +++ b/storage/mroonga/packages/debian/rules @@ -0,0 +1,39 @@ +#!/usr/bin/make -f +# -*- makefile-gmake -*- +# +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 +# This has to be exported to make some magic below work. +export DH_OPTIONS + +export MYSQL_VERSION := $(shell apt-cache show mysql-server-5.5 | grep Version | head -n 1 | awk '{print $$2}' | awk -F '-' '{print $$1}') + +%: + dh $@ + +override_dh_auto_configure: + path=main/m/mysql-5.5/mysql-5.5_$(MYSQL_VERSION).orig.tar.gz; \ + if [ "$$(lsb_release --id --short)" = "Ubuntu" ]; then \ + base_url=http://archive.ubuntu.com/ubuntu/pool; \ + security_base_url=http://security.ubuntu.com/ubuntu/pool; \ + else \ + base_url=http://ftp.debian.org/debian/pool; \ + security_base_url=http://security.debian.org/pool/updates; \ + fi; \ + wget $${security_base_url}/$${path} || \ + wget $${base_url}/$${path} + tar xf mysql-5.5_$(MYSQL_VERSION).orig.tar.gz + dh_auto_configure -- --with-mysql-source=./mysql-$(MYSQL_VERSION) + +# disable 'make check'. +override_dh_auto_test: + +override_dh_install: + mv debian/tmp/usr/share/doc/mroonga/ \ + debian/tmp/usr/share/doc/mysql-server-mroonga-doc/ + dh_install +# if test -x /usr/bin/dh_apparmor; then \ +# dh_apparmor \ +# -pmysql-server-mroonga \ +# --profile-name=usr.lib.mysql.plugin.ha_mroonga; \ +# fi diff --git a/storage/mroonga/packages/rpm/Makefile.am b/storage/mroonga/packages/rpm/Makefile.am new file mode 100644 index 00000000000..aa1ba3ad9c6 --- /dev/null +++ b/storage/mroonga/packages/rpm/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = \ + centos diff --git a/storage/mroonga/packages/rpm/centos/Makefile.am b/storage/mroonga/packages/rpm/centos/Makefile.am new file mode 100644 index 00000000000..e7b22cfa025 --- /dev/null +++ b/storage/mroonga/packages/rpm/centos/Makefile.am @@ -0,0 +1,9 @@ +EXTRA_DIST = \ + mysql55-mroonga.spec.in \ + mysql56-community-mroonga.spec.in \ + mariadb-mroonga.spec.in + +noinst_DATA = \ + mysql55-mroonga.spec \ + mysql56-community-mroonga.spec \ + mariadb-mroonga.spec diff --git a/storage/mroonga/packages/rpm/centos/mariadb-mroonga.spec.in b/storage/mroonga/packages/rpm/centos/mariadb-mroonga.spec.in new file mode 100644 index 00000000000..337eeccb1cf --- /dev/null +++ b/storage/mroonga/packages/rpm/centos/mariadb-mroonga.spec.in @@ -0,0 +1,396 @@ +%define mariadb_epoch_default 1 +%define mariadb_version_default 5.5.41 +%define mariadb_release_default 1 +%define mariadb_dist_default .el7_0 +%define mariadb_download_base_url_default http://vault.centos.org/7.0.1406/updates/Source/SPackages +%define mariadb_spec_file_default mariadb.spec + +%{!?mariadb_epoch:%define mariadb_epoch %{mariadb_epoch_default}} +%{!?mariadb_version:%define mariadb_version %{mariadb_version_default}} +%{!?mariadb_release:%define mariadb_release %{mariadb_release_default}} +%{!?mariadb_dist:%define mariadb_dist %{mariadb_dist_default}} +%{!?mariadb_download_base_url:%define mariadb_download_base_url %{mariadb_download_base_url_default}} +%{!?mariadb_spec_file:%define mariadb_spec_file %{mariadb_spec_file_default}} + +%define mariadb_package_version %{mariadb_epoch}:%{mariadb_version}-%{mariadb_release}%{mariadb_dist} + +%define groonga_required_version @REQUIRED_GROONGA_VERSION@ + +Name: mariadb-mroonga +Version: @VERSION@ +Release: 1%{?dist} +Summary: A fast fulltext searchable storage engine for MariaDB + +Group: Applications/Databases +License: LGPLv2.1 +URL: http://mroonga.org/ +Source0: http://packages.groonga.org/source/mroonga/mroonga-%{version}.tar.gz + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n) +BuildRequires: groonga-devel >= %{groonga_required_version} +BuildRequires: groonga-normalizer-mysql-devel +BuildRequires: wget +BuildRequires: mariadb-devel +Requires: mariadb-server = %{mariadb_package_version} +Requires: mariadb = %{mariadb_package_version} +Requires: groonga-libs >= %{groonga_required_version} +Requires: groonga-normalizer-mysql + +%description +Mroonga is a fast fulltext searchable storage plugin for MariaDB. +It is based on Groonga that is a fast fulltext search engine and +column store. Groonga is good at real-time update. + +%package doc +Summary: Documentation for Mroonga +Group: Documentation +License: LGPLv2.1 + +%description doc +Documentation for Mroonga + + +%prep +%setup -q -n mroonga-%{version} + +mariadb_full_version=%{mariadb_version}-%{mariadb_release}%{mariadb_dist} +srpm=mariadb-${mariadb_full_version}.src.rpm +if [ ! -f ../../SRPMS/$srpm ]; then + wget --continue -O ../../SRPMS/$srpm %{mariadb_download_base_url}/$srpm + rpm -Uvh ../../SRPMS/$srpm + rm ../../SRPMS/$srpm +fi + +%build +mariadb_source=../mariadb-%{mariadb_version} +if [ ! -d ${mariadb_source} ]; then + rpmbuild -bc \ + --define 'runselftest 0' \ + --define 'optflags -O0' \ + ../../SPECS/%{mariadb_spec_file} +fi +%configure \ + --disable-static \ + --with-mysql-source=${mariadb_source} \ + %{?mroonga_configure_options} +make %{?_smp_mflags} + + +%install +rm -rf $RPM_BUILD_ROOT +make install DESTDIR=$RPM_BUILD_ROOT +rm $RPM_BUILD_ROOT%{_libdir}/mysql/plugin/*.la +mv $RPM_BUILD_ROOT%{_datadir}/doc/mroonga/ mysql-mroonga-doc/ + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +if /usr/bin/mysql -u root -e "quit"; then + password_option="" +else + password_option="-p" +fi +current_version=0 +version=$(echo %{groonga_required_version} | sed -e 's/\.//g') +required_version=$(expr $version) +version=$(/usr/bin/mysql -e "SHOW VARIABLES LIKE 'mroonga_libgroonga_version'" | \ + grep mroonga | cut -f 2 | sed -e 's/\.//g') +if [ -n "$version" ]; then + current_version=$(expr $version) +fi +install_sql=%{_datadir}/mroonga/install.sql +uninstall_sql=%{_datadir}/mroonga/uninstall.sql + +if [ "$1" = 2 ] ; then + if [ $current_version -lt $required_version ]; then + command="/usr/bin/mysql -u root $password_option" + echo "run the following command after restarting MySQL server:"; + echo " $command < ${uninstall_sql}" + echo " $command < ${install_sql}" + exit 0 + else + command="/usr/bin/mysql -u root $password_option" + command="${command} < ${uninstall_sql}" + echo $command + eval $command || \ + (echo "run the following command to unregister Mroonga:"; \ + echo " $command") + fi +fi + +command="/usr/bin/mysql -u root $password_option < ${install_sql}" +echo $command +eval $command || \ + (echo "run the following command to register Mroonga:"; \ + echo " $command") + +%preun +uninstall_sql=%{_datadir}/mroonga/uninstall.sql + +if mysql -u root -e "quit"; then + password_option="" +else + password_option="-p" +fi +if [ "$1" = 0 ]; then + command="/usr/bin/mysql -u root $password_option < ${uninstall_sql}" + echo $command + eval $command || \ + (echo "run the following command to unregister Mroonga:"; \ + echo " $command") +fi + +%files +%defattr(-,root,root,-) +%{_libdir}/mysql/plugin/ +%{_datadir}/mroonga/* +%{_datadir}/man/man1/* +%{_datadir}/man/*/man1/* + +%files doc +%defattr(-,root,root,-) +%doc README COPYING +%doc mysql-mroonga-doc/* + +%changelog +* Mon Feb 09 2015 - 5.00-1 +- new upstream release. + +* Thu Jan 29 2015 HAYASHI Kentaro - 4.10-1 +- new upstream release. + +* Wed Jan 14 2015 HAYASHI Kentaro - 4.09-2 +- build against mariadb-5.5.40-2.el7_0. + +* Mon Dec 29 2014 Kouhei Sutou - 4.09-1 +- new upstream release. + +* Sat Nov 29 2014 HAYASHI Kentaro - 4.08-1 +- new upstream release. + +* Wed Oct 29 2014 Kouhei Sutou - 4.07-1 +- new upstream release. + +* Mon Sep 29 2014 Kouhei Sutou - 4.06-1 +- new upstream release. + +* Fri Aug 29 2014 Kouhei Sutou - 4.05-1 +- new upstream release. + +* Thu Aug 14 2014 Kouhei Sutou - 4.04-4 +- build MariaDB for libmysqlservices.a. + +* Thu Aug 14 2014 Kouhei Sutou - 4.04-3 +- support epoch in MariaDB. + +* Wed Aug 13 2014 Kouhei Sutou - 4.04-2 +- build against mariadb-5.5.37-1.el7_0. + +* Sun Aug 10 2014 Kouhei Sutou - 4.04-1 +- initial packaging for CentOS 7 based on mysql-mroogna package. + +* Tue Jul 29 2014 HAYASHI Kentaro - 4.04-1 +- new upstream release. + +* Thu May 29 2014 Kouhei Sutou - 4.03-1 +- new upstream release. + +* Tue Apr 29 2014 Kouhei Sutou - 4.02-1 +- new upstream release. + +* Sat Mar 29 2014 HAYASHI Kentaro - 4.01-1 +- new upstream release. + +* Thu Feb 13 2014 HAYASHI Kentaro - 4.00-2 +- use MySQL 5.1.73-3 on CentOS 6. + +* Sun Feb 09 2014 HAYASHI Kentaro - 4.00-1 +- new upstream release. + +* Wed Jan 29 2014 HAYASHI Kentaro - 3.12-1 +- new upstream release. + +* Sun Dec 29 2013 HAYASHI Kentaro - 3.11-1 +- new upstream release. + +* Sat Dec 7 2013 HAYASHI Kentaro - 3.10-2 +- use MySQL 5.1.71-1 on CentOS 6. + +* Fri Nov 29 2013 HAYASHI Kentaro - 3.10-1 +- new upstream release. + +* Tue Oct 29 2013 HAYASHI Kentaro - 3.09-1 +- new upstream release. + +* Sun Sep 29 2013 HAYASHI Kentaro - 3.08-1 +- new upstream release. +- use MySQL 5.6.14-1 on CentOS 5. + +* Wed Sep 4 2013 HAYASHI Kentaro - 3.07-2 +- fix a bug that mroonga is removed accidentally on upgrade #1918. + Reported by @ceekz. Thanks!!! + +* Thu Aug 29 2013 HAYASHI Kentaro - 3.07-1 +- new upstream release. +- use MySQL 5.6.13-1 on CentOS 5. + +* Mon Jul 29 2013 HAYASHI Kentaro - 3.06-1 +- new upstream release. +- use MySQL 5.6.12-2 on CentOS 5. + +* Sat Jun 29 2013 HAYASHI Kentaro - 3.05-1 +- new upstream release. +- use MySQL 5.6.12 on CentOS 5. + +* Wed May 29 2013 HAYASHI Kentaro - 3.04-1 +- new upstream release. + +* Fri May 10 2013 HAYASHI Kentaro - 3.03-2 +- use MySQL 5.6.11-2 on CentOS 5. see http://bugs.mysql.com/bug.php?id=69027 + Reported by Y.Kentaro. Thanks!!! + +* Mon Apr 29 2013 HAYASHI Kentaro - 3.03-1 +- new upstream release. + +* Fri Mar 29 2013 HAYASHI Kentaro - 3.02-0 +- new upstream release. + +* Thu Feb 28 2013 HAYASHI Kentaro - 3.01-0 +- new upstream release. + +* Sat Feb 09 2013 HAYASHI Kentaro - 3.00-0 +- new upstream release. +- require groonga 3.0.0 or later + +* Tue Feb 05 2013 HAYASHI Kentaro - 2.10-2 +- use MySQL 5.1.67-1 on CentOS 6. + Reported by wakisuke.ua. Thanks!!! + +* Sat Dec 29 2012 HAYASHI Kentaro - 2.10-0 +- new upstream release. + +* Mon Dec 10 2012 HAYASHI Kentaro - 2.09-1 +- use MySQL 5.1.66-2 on CentOS 6. + Reported by wakisuke.ua. Thanks!!! + +* Thu Nov 29 2012 HAYASHI Kentaro - 2.09-0 +- new upstream release. +- use MySQL 5.5.28 on CentOS 5. +- use MySQL 5.1.66 on CentOS 6. + +* Mon Oct 29 2012 HAYASHI Kentaro - 2.08-0 +- new upstream release. +- add missing "DROP FUNCTION mroonga_snippet". + Reported by @tokuhy. Thanks!!! + +* Sat Sep 29 2012 HAYASHI Kentaro - 2.07-0 +- new upstream release. + +* Wed Aug 29 2012 Kouhei Sutou - 2.06-0 +- new upstream release. +- make MySQL spec file name customizable. +- make mroonga configure options customizable. +- add missing mysql-devel BuildRequires. Reported by wing. Thanks!!! +- use MySQL 5.5.27. + +* Sun Jul 29 2012 HAYASHI Kentaro - 2.05-0 +- new upstream release. +- use MySQL 5.5.25a. + +* Fri Jun 29 2012 Kouhei Sutou - 2.04-0 +- new upstream release. +- ensure deleting mroonga plugin before install. + Suggested by Kazuhiro Isobe. Thanks!!! +- use MySQL 5.5.25. + +* Tue May 29 2012 Kouhei Sutou - 2.03-0 +- new upstream release. +- use MySQL 5.5.24. +- make mysql_* variables customizable +- require groonga 2.0.3 or later. + +* Sun Apr 29 2012 Kouhei Sutou - 2.02-0 +- new upstream release. +- use MySQL 5.5.23. +- require groonga 2.0.2 or later. + +* Thu Mar 29 2012 Kouhei Sutou - 2.01-0 +- new upstream release. +- ensure plugin is uninstalled by closing all tables use mroonga. + +* Wed Feb 29 2012 Kouhei Sutou - 2.00-0 +- new upstream release. +- always install/uninstall plugin. +- use MySQL 5.1.61 and 5.5.21. +- require groonga 2.0.0 or later. + +* Sun Jan 29 2012 Kouhei Sutou - 1.20-0 +- new upstream release. +- require groonga 1.3.0. +- groonga -> mroonga. +- use MySQL 5.5.20. + +* Thu Dec 29 2011 Kouhei Sutou - 1.11-0 +- new upstream release. + +* Sat Oct 29 2011 Kouhei Sutou - 1.10-0 +- new upstream release. +- groonga storage engine -> mroonga. + +* Thu Sep 29 2011 Kouhei Sutou - 1.0.0-0 +- new upstream release. + +* Mon Aug 29 2011 Kouhei Sutou - 0.9-0 +- new upstream release. + +* Fri Jul 29 2011 Kouhei Sutou - 0.8-0 +- new upstream release. + +* Wed Jun 29 2011 Kouhei Sutou - 0.7-0 +- new upstream release. + +* Sun May 29 2011 Kouhei Sutou - 0.6-0 +- new upstream release. + +* Tue May 17 2011 Kouhei Sutou - 0.5-2 +- use MySQL 5.5.12. + +* Tue Mar 29 2011 Kouhei Sutou - 0.5-1 +- new upstream release. + +* Sat Jan 29 2011 Kouhei Sutou - 0.4-4 +- do not remove plugin on upgrade. + +* Wed Jan 12 2011 Kouhei Sutou - 0.4-3 +- rebuild without debug symbol. + +* Thu Dec 30 2010 Kouhei Sutou - 0.4-2 +- use MySQL 5.5.8-1. +- fix SQL literal notation. + +* Mon Nov 29 2010 Kouhei Sutou - 0.4-1 +- use the latest MySQL. +- new upstream release. + +* Sun Nov 21 2010 Kouhei Sutou - 0.3-2 +- install user define function. + +* Fri Oct 29 2010 Kouhei Sutou - 0.3-1 +- new upstream release. + +* Fri Oct 08 2010 Kouhei Sutou - 0.2-2 +- specify target MySQL version. +- use %{version}. + +* Wed Sep 29 2010 Kouhei Sutou - 0.2-1 +- new upstream release. + +* Sun Sep 12 2010 Kouhei Sutou - 0.1-3 +- require MySQL-client-community. + +* Fri Sep 10 2010 Kouhei Sutou - 0.1-2 +- use MySQL-devel-community. + +* Fri Sep 03 2010 Kouhei Sutou - 0.1-1 +- initial packaging for CentOS. diff --git a/storage/mroonga/packages/rpm/centos/mysql55-mroonga.spec.in b/storage/mroonga/packages/rpm/centos/mysql55-mroonga.spec.in new file mode 100644 index 00000000000..f1f5b2f4692 --- /dev/null +++ b/storage/mroonga/packages/rpm/centos/mysql55-mroonga.spec.in @@ -0,0 +1,218 @@ +%{?scl:%scl_package mroonga} +%{!?scl:%global pkg_name %{name}} +%{!?centos_ver:%define centos_ver 5} + +%if %{centos_ver} == 6 +%define mysql_version_default 5.5.41 +%define mysql_release_default 2 +%define mysql_dist_default el6.centos.alt +%define mysql_download_base_url_default http://vault.centos.org/6.6/SCL/Source/SPackages +%define mysql_spec_file_default mysql.spec +%else +%define mysql_version_default 5.5.40 +%define mysql_release_default 2 +%define mysql_dist_default el5 +%define mysql_download_base_url_default http://vault.centos.org/5.11/updates/SRPMS +%define mysql_spec_file_default mysql.spec +%endif + +%{!?mysql_version:%define mysql_version %{mysql_version_default}} +%{!?mysql_release:%define mysql_release %{mysql_release_default}} +%{!?mysql_dist:%define mysql_dist %{mysql_dist_default}} +%{!?mysql_download_base_url:%define mysql_download_base_url %{mysql_download_base_url_default}} +%{!?mysql_spec_file:%define mysql_spec_file %{mysql_spec_file_default}} + +%define groonga_required_version @REQUIRED_GROONGA_VERSION@ + +Name: %{?scl_prefix}mroonga +Version: @VERSION@ +Release: 1%{?dist} +Summary: A fast fulltext searchable storage engine for MySQL + +Group: Applications/Databases +License: LGPLv2.1 +URL: http://mroonga.org/ +Source0: http://packages.groonga.org/source/mroonga/mroonga-%{version}.tar.gz + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n) +BuildRequires: groonga-devel >= %{groonga_required_version} +BuildRequires: groonga-normalizer-mysql-devel +BuildRequires: wget +BuildRequires: which +BuildRequires: mysql55-mysql-devel +BuildRequires: mysql55-build +Requires: mysql55-mysql-server = %{mysql_version}-%{mysql_release}.%{mysql_dist} +Requires: mysql55-mysql = %{mysql_version}-%{mysql_release}.%{mysql_dist} +Requires: groonga-libs >= %{groonga_required_version} +Requires: groonga-normalizer-mysql +%{?scl:Requires: %scl_runtime} + +%description +Mroonga is a fast fulltext searchable storage plugin for MySQL. +It is based on Groonga that is a fast fulltext search engine and +column store. Groonga is good at real-time update. + +%package doc +Summary: Documentation for Mroonga +Group: Documentation +License: LGPLv2.1 + +%description doc +Documentation for Mroonga + + +%prep +%setup -q -n %{pkg_name}-%{version} + +mysql_full_version=%{mysql_version}-%{mysql_release}.%{mysql_dist} +srpm=mysql55-mysql-${mysql_full_version}.src.rpm +if [ ! -f ../../SRPMS/$srpm ]; then + wget --continue -O ../../SRPMS/$srpm %{mysql_download_base_url}/$srpm + rpm -Uvh ../../SRPMS/$srpm +fi + +%build +mysql_source=../mysql-%{mysql_version} +if [ ! -d ${mysql_source} ]; then + specs_dir= + MYSQL_RPMBUILD_TEST=no rpmbuild -bp \ + --define 'runselftest 0' \ + --define 'optflags -O0' \ + ../../SPECS/%{mysql_spec_file} +fi +%configure --disable-static --with-mysql-source=${mysql_source} \ + --disable-fast-mutexes \ + --with-mysql-config=`scl enable mysql55 'which mysql_config'` \ + %{?mroonga_configure_options} +make %{?_smp_mflags} + +%install +rm -rf $RPM_BUILD_ROOT +make install DESTDIR=$RPM_BUILD_ROOT +rm $RPM_BUILD_ROOT%{_libdir}/mysql/plugin/*.la +mv $RPM_BUILD_ROOT%{_datadir}/doc/mroonga/ mysql-mroonga-doc/ + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +mysql_command=`scl enable mysql55 'which mysql'` +password_option="" +$mysql_command -u root -e "quit" +if [ $? -ne 0 ]; then + password_option="-p" +fi +current_version=0 +version=`echo %{groonga_required_version} | sed -e 's/\.//g'` +required_version=`expr $version` +version=`$mysql_command -e "SHOW VARIABLES LIKE 'mroonga_libgroonga_version'" | \ + grep mroonga | cut -f 2 | sed -e 's/\.//g'` +if [ -n "$version" ]; then + current_version=`expr $version` +fi +install_sql=%{_datadir}/mroonga/install.sql +uninstall_sql=%{_datadir}/mroonga/uninstall.sql + +if [ "$1" = 2 ] ; then + if [ $current_version -lt $required_version ]; then + command="$mysql_command -u root $password_option" + echo "run the following command after restarting MySQL server:"; + echo " $command < ${uninstall_sql}" + echo " $command < ${install_sql}" + exit 0 + else + command="$mysql_command -u root $password_option < ${uninstall_sql}" + echo $command + eval $command || \ + (echo "run the following command to unregister Mroonga:"; \ + echo " $command") + fi +fi +command="$mysql_command -u root $password_option < ${install_sql}" +echo $command +eval $command || \ + (echo "run the following command to register Mroonga:"; \ + echo " $command") + +%preun +uninstall_sql=%{_datadir}/mroonga/uninstall.sql +mysql_command=`scl enable mysql55 'which mysql'` +if $mysql_command -u root -e "quit"; then + password_option="" +else + password_option="-p" +fi +if [ "$1" = 0 ]; then + command="$mysql_command -u root $password_option < ${uninstall_sql}" + echo $command + eval $command || \ + (echo "run the following command to unregister Mroonga:"; \ + echo " $command") +fi + +%files +%defattr(-,root,root,-) +%{_libdir}/mysql/plugin/ +%{_datadir}/mroonga/* +%{_datadir}/man/man1/* +%{_datadir}/man/*/man1/* + +%files doc +%defattr(-,root,root,-) +%doc README COPYING +%doc mysql-mroonga-doc/* + +%changelog +* Mon Feb 09 2015 - 5.00-1 +- new upstream release. + +* Thu Jan 29 2015 HAYASHI Kentaro - 4.10-1 +- new upstream release. + +* Mon Dec 29 2014 Kouhei Sutou - 4.09-1 +- new upstream release. + +* Sat Nov 29 2014 HAYASHI Kentaro - 4.08-1 +- new upstream release. + +* Wed Oct 29 2014 Kouhei Sutou - 4.07-1 +- new upstream release. + +* Mon Sep 29 2014 Kouhei Sutou - 4.06-1 +- new upstream release. + +* Fri Aug 29 2014 Kouhei Sutou - 4.05-1 +- new upstream release. + +* Tue Jul 29 2014 HAYASHI Kentaro - 4.04-1 +- new upstream release. + +* Thu May 29 2014 Kouhei Sutou - 4.03-2 +- build against MySQL 5.6.37. Reported by YOSHIDA Mitsuo. Thanks!!! + +* Thu May 29 2014 Kouhei Sutou - 4.03-1 +- new upstream release. + +* Tue Apr 29 2014 Kouhei Sutou - 4.02-1 +- new upstream release. + +* Sat Mar 29 2014 HAYASHI Kentaro - 4.01-1 +- new upstream release. + +* Thu Mar 06 2014 HAYASHI Kentaro - 4.00-2 +- use MySQL 5.5.36 on CentOS 5. + +* Sun Feb 09 2014 HAYASHI Kentaro - 4.00-1 +- new upstream release. + +* Wed Jan 29 2014 HAYASHI Kentaro - 3.12-1 +- new upstream release. + +* Sun Dec 29 2013 HAYASHI Kentaro - 3.11-1 +- new upstream release. + +* Fri Nov 29 2013 HAYASHI Kentaro - 3.10-1 +- new upstream release. + +* Tue Oct 29 2013 HAYASHI Kentaro - 3.09-1 +- initial packaging for MySQL 5.5 on CentOS 5. diff --git a/storage/mroonga/packages/rpm/centos/mysql56-community-mroonga.spec.in b/storage/mroonga/packages/rpm/centos/mysql56-community-mroonga.spec.in new file mode 100644 index 00000000000..37ae5d41b2f --- /dev/null +++ b/storage/mroonga/packages/rpm/centos/mysql56-community-mroonga.spec.in @@ -0,0 +1,222 @@ +%{!?centos_ver:%define centos_ver 6} + +%if %{centos_ver} == 7 +%define mysql_version_default 5.6.23 +%define mysql_release_default 2 +%define mysql_dist_default el7 +%define mysql_download_base_url_default http://repo.mysql.com/yum/mysql-5.6-community/el/7/SRPMS +%define mysql_spec_file_default mysql.spec +%else +%define mysql_version_default 5.6.23 +%define mysql_release_default 2 +%define mysql_dist_default el6 +%define mysql_download_base_url_default http://repo.mysql.com/yum/mysql-5.6-community/el/6/SRPMS +%define mysql_spec_file_default mysql.spec +%endif + +%{!?mysql_version:%define mysql_version %{mysql_version_default}} +%{!?mysql_release:%define mysql_release %{mysql_release_default}} +%{!?mysql_dist:%define mysql_dist %{mysql_dist_default}} +%{!?mysql_download_base_url:%define mysql_download_base_url %{mysql_download_base_url_default}} +%{!?mysql_spec_file:%define mysql_spec_file %{mysql_spec_file_default}} + +%define groonga_required_version @REQUIRED_GROONGA_VERSION@ + +Name: mysql-community-mroonga +Version: @VERSION@ +Release: 1%{?dist} +Summary: A fast fulltext searchable storage engine for MySQL + +Group: Applications/Databases +License: LGPLv2.1 +URL: http://mroonga.org/ +Source0: http://packages.groonga.org/source/mroonga/mroonga-%{version}.tar.gz + +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n) +BuildRequires: groonga-devel >= %{groonga_required_version} +BuildRequires: groonga-normalizer-mysql-devel +BuildRequires: wget +BuildRequires: which +BuildRequires: gcc, gcc-c++ +BuildRequires: mysql-community-devel +Requires: mysql-community-server = %{mysql_version}-%{mysql_release}.%{mysql_dist} +Requires: mysql-community-client = %{mysql_version}-%{mysql_release}.%{mysql_dist} +Requires: groonga-libs >= %{groonga_required_version} +Requires: groonga-normalizer-mysql + +%description +Mroonga is a fast fulltext searchable storage plugin for MySQL. +It is based on Groonga that is a fast fulltext search engine and +column store. Groonga is good at real-time update. + +%package doc +Summary: Documentation for Mroonga +Group: Documentation +License: LGPLv2.1 + +%description doc +Documentation for Mroonga + + +%prep +%setup -q -n mroonga-%{version} + +mysql_full_version=%{mysql_version}-%{mysql_release}.%{mysql_dist} +srpm=mysql-community-${mysql_full_version}.src.rpm +if [ ! -f ../../SRPMS/$srpm ]; then + wget --continue -O ../../SRPMS/$srpm %{mysql_download_base_url}/$srpm + rpm -Uvh ../../SRPMS/$srpm +fi + +%build +mysql_source=../mysql-%{mysql_version}/mysql-%{mysql_version} +if [ ! -d ${mysql_source} ]; then + specs_dir= + MYSQL_RPMBUILD_TEST=no rpmbuild -bp \ + --define 'runselftest 0' \ + --define 'optflags -O0' \ + ../../SPECS/%{mysql_spec_file} +fi +%configure --disable-static --with-mysql-source=${mysql_source} \ + %{?mroonga_configure_options} +make %{?_smp_mflags} + +%install +rm -rf $RPM_BUILD_ROOT +make install DESTDIR=$RPM_BUILD_ROOT +rm $RPM_BUILD_ROOT%{_libdir}/mysql/plugin/*.la +mv $RPM_BUILD_ROOT%{_datadir}/doc/mroonga/ mysql-mroonga-doc/ + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +mysql_command=`which mysql` +password_option="" +$mysql_command -u root -e "quit" +if [ $? -ne 0 ]; then + password_option="-p" +fi +current_version=0 +version=`echo %{groonga_required_version} | sed -e 's/\.//g'` +required_version=`expr $version` +version=`$mysql_command -e "SHOW VARIABLES LIKE 'mroonga_libgroonga_version'" | \ + grep mroonga | cut -f 2 | sed -e 's/\.//g'` +if [ -n "$version" ]; then + current_version=`expr $version` +fi +install_sql=%{_datadir}/mroonga/install.sql +uninstall_sql=%{_datadir}/mroonga/uninstall.sql + +if [ "$1" = 2 ] ; then + if [ $current_version -lt $required_version ]; then + command="$mysql_command -u root $password_option" + echo "run the following command after restarting MySQL server:"; + echo " $command < ${uninstall_sql}" + echo " $command < ${install_sql}" + exit 0 + else + command="$mysql_command -u root $password_option < ${uninstall_sql}" + echo $command + eval $command || \ + (echo "run the following command to unregister Mroonga:"; \ + echo " $command") + fi +fi +command="$mysql_command -u root $password_option < ${install_sql}" +echo $command +eval $command || \ + (echo "run the following command to register Mroonga:"; \ + echo " $command") + +%preun +uninstall_sql=%{_datadir}/mroonga/uninstall.sql +mysql_command=`which mysql` +if $mysql_command -u root -e "quit"; then + password_option="" +else + password_option="-p" +fi +if [ "$1" = 0 ]; then + command="$mysql_command -u root $password_option < ${uninstall_sql}" + echo $command + eval $command || \ + (echo "run the following command to unregister Mroonga:"; \ + echo " $command") +fi + +%files +%defattr(-,root,root,-) +%{_libdir}/mysql/plugin/ +%{_datadir}/mroonga/* +%{_datadir}/man/man1/* +%{_datadir}/man/*/man1/* + +%files doc +%defattr(-,root,root,-) +%doc README COPYING +%doc mysql-mroonga-doc/* + +%changelog +* Mon Feb 09 2015 - 5.00-1 +- new upstream release. + +* Wed Feb 04 2015 HAYASHI Kentaro - 4.10-2 +- build against MySQL 5.6.23-2 on MySQL yum repository. + +* Thu Jan 29 2015 HAYASHI Kentaro - 4.10-1 +- new upstream release. + +* Mon Dec 29 2014 Kouhei Sutou - 4.09-1 +- new upstream release. + +* Sat Nov 29 2014 HAYASHI Kentaro - 4.08-1 +- new upstream release. + +* Wed Oct 29 2014 Kouhei Sutou - 4.07-1 +- new upstream release. + +* Mon Sep 29 2014 Kouhei Sutou - 4.06-1 +- new upstream release. + +* Sat Sep 27 2014 Eiichi Sato - 4.05-2 +- build against MySQL 5.6.21-2 on MySQL yum repository. + +* Fri Aug 29 2014 Kouhei Sutou - 4.05-1 +- new upstream release. + +* Sat Aug 09 2014 Eiichi Sato - 4.04-2 +- build against MySQL 5.6.20-4 on MySQL yum repository. + +* Tue Jul 29 2014 HAYASHI Kentaro - 4.04-1 +- new upstream release. + +* Thu May 29 2014 Kouhei Sutou - 4.03-2 +- build against MySQL 5.6.37. Reported by YOSHIDA Mitsuo. Thanks!!! + +* Thu May 29 2014 Kouhei Sutou - 4.03-1 +- new upstream release. + +* Tue Apr 29 2014 Kouhei Sutou - 4.02-1 +- new upstream release. + +* Sat Mar 29 2014 HAYASHI Kentaro - 4.01-1 +- new upstream release. + +* Thu Mar 06 2014 HAYASHI Kentaro - 4.00-2 +- use MySQL 5.5.36 on CentOS 5. + +* Sun Feb 09 2014 HAYASHI Kentaro - 4.00-1 +- new upstream release. + +* Wed Jan 29 2014 HAYASHI Kentaro - 3.12-1 +- new upstream release. + +* Sun Dec 29 2013 HAYASHI Kentaro - 3.11-1 +- new upstream release. + +* Fri Nov 29 2013 HAYASHI Kentaro - 3.10-1 +- new upstream release. + +* Tue Oct 29 2013 HAYASHI Kentaro - 3.09-1 +- initial packaging for MySQL 5.5 on CentOS 5. diff --git a/storage/mroonga/packages/source/Makefile.am b/storage/mroonga/packages/source/Makefile.am new file mode 100644 index 00000000000..30721406f0b --- /dev/null +++ b/storage/mroonga/packages/source/Makefile.am @@ -0,0 +1,123 @@ +MROONGA_BASE = $(PACKAGE)-$(VERSION) +MROONGA_TAR_GZ = $(MROONGA_BASE).tar.gz + +GROONGA_VERSION = 5.0.0 +GROONGA_BASE = groonga-$(GROONGA_VERSION) +GROONGA_TAR_GZ = $(GROONGA_BASE).tar.gz + +GROONGA_NORMALIZER_MYSQL_VERSION = 1.0.8 +GROONGA_NORMALIZER_MYSQL_BASE = \ + groonga-normalizer-mysql-$(GROONGA_NORMALIZER_MYSQL_VERSION) +GROONGA_NORMALIZER_MYSQL_TAR_GZ = \ + $(GROONGA_NORMALIZER_MYSQL_BASE).tar.gz + +MARIADB_VERSION = 10.0.16 +MARIADB_BASE = mariadb-$(MARIADB_VERSION) +MARIADB_TAR_GZ = $(MARIADB_BASE).tar.gz + +MARIADB_WITH_MROONGA_BASE = $(MARIADB_BASE)-with-$(MROONGA_BASE) +MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE = $(MARIADB_WITH_MROONGA_BASE)-for-windows + +GROONGA_PROJECT_DOWNLOAD_BASE = http://packages.groonga.org/source +GROONGA_DOWNLOAD_BASE = $(GROONGA_PROJECT_DOWNLOAD_BASE)/groonga +GROONGA_NORMALIZER_MYSQL_DOWNLOAD_BASE = \ + $(GROONGA_PROJECT_DOWNLOAD_BASE)/groonga-normalizer-mysql +MARIADB_DOWNLOAD_BASE = http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb + + +CURL = curl --fail --silent --show-error + +all: + +release: archive upload + +ensure-rsync-path: + @if test -z "$(RSYNC_PATH)"; then \ + echo "--with-rsync-path configure option must be specified."; \ + false; \ + fi + +download: ensure-rsync-path + rsync -avz --progress --delete $(RSYNC_PATH)/source/mroonga/ files + +ARCHIVES = \ + files/$(MROONGA_TAR_GZ) \ + files/$(MARIADB_WITH_MROONGA_BASE).tar.gz \ + files/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE).zip + +archive: $(ARCHIVES) + +upload: ensure-rsync-path + rsync -avz --progress --delete files/ $(RSYNC_PATH)/source/mroonga + +files/$(MROONGA_TAR_GZ): $(top_builddir)/$(MROONGA_TAR_GZ) + mkdir -p files + cp -p $< $@ + +tmp/$(GROONGA_TAR_GZ): + mkdir -p tmp + $(CURL) --output $@ $(GROONGA_DOWNLOAD_BASE)/$(GROONGA_TAR_GZ) + +tmp/$(GROONGA_NORMALIZER_MYSQL_TAR_GZ): + mkdir -p tmp + $(CURL) --output $@ $(GROONGA_NORMALIZER_MYSQL_DOWNLOAD_BASE)/$(GROONGA_NORMALIZER_MYSQL_TAR_GZ) + +tmp/$(MARIADB_TAR_GZ): + mkdir -p tmp + $(CURL) --output $@ $(MARIADB_DOWNLOAD_BASE)/mariadb-$(MARIADB_VERSION)/source/$(MARIADB_TAR_GZ) + +MARIADB_WITH_MROONGA_ARCHIVES = \ + tmp/$(GROONGA_TAR_GZ) \ + tmp/$(GROONGA_NORMALIZER_MYSQL_TAR_GZ) \ + tmp/$(MARIADB_TAR_GZ) \ + $(top_builddir)/$(MROONGA_TAR_GZ) + +BUNDLED_MROONGA_PATH = $(MARIADB_BASE)/storage/$(PACKAGE) +BUNDLED_GROONGA_PATH = $(BUNDLED_MROONGA_PATH)/vendor/groonga +BUNDLED_GROONGA_NORMALIZER_MYSQL_PATH = \ + $(BUNDLED_GROONGA_PATH)/vendor/plugins/groonga-normalizer-mysql + +tmp/$(MARIADB_WITH_MROONGA_BASE).stamp: $(MARIADB_WITH_MROONGA_ARCHIVES) + rm -rf $(MARIADB_BASE) + tar xf tmp/$(MARIADB_TAR_GZ) + + rm -fr $(MARIADB_BASE)/storage/mroonga + tar xf $(top_builddir)/$(MROONGA_TAR_GZ) + mv $(MROONGA_BASE) $(BUNDLED_MROONGA_PATH) + + mkdir -p $$(dirname $(BUNDLED_GROONGA_PATH)) + tar xf tmp/$(GROONGA_TAR_GZ) + rm -rf $(GROONGA_BASE)/test + mv $(GROONGA_BASE) $(BUNDLED_GROONGA_PATH) + + tar xf tmp/$(GROONGA_NORMALIZER_MYSQL_TAR_GZ) + rm -rf $(GROONGA_NORMALIZER_MYSQL_BASE)/test + mv $(GROONGA_NORMALIZER_MYSQL_BASE) $(BUNDLED_GROONGA_NORMALIZER_MYSQL_PATH) + + rm -rf tmp/$(MARIADB_WITH_MROONGA_BASE) + mv $(MARIADB_BASE) tmp/$(MARIADB_WITH_MROONGA_BASE) + + touch $@ + +files/$(MARIADB_WITH_MROONGA_BASE).tar.gz: tmp/$(MARIADB_WITH_MROONGA_BASE).stamp + mkdir -p files/ + (cd tmp && tar czf ../$@ $(MARIADB_WITH_MROONGA_BASE)) + +PATCHES = \ + patches/mariadb-10.0.3-windows-build.diff + +tmp/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE).stamp: tmp/$(MARIADB_WITH_MROONGA_BASE).stamp $(PATCHES) + rm -rf tmp/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE) + cp -a \ + tmp/$(MARIADB_WITH_MROONGA_BASE) \ + tmp/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE) + for patch in $(PATCHES); do \ + (cd tmp/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE) && \ + patch -p1 < $(abs_srcdir)/$${patch}); \ + done + + touch $@ + +files/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE).zip: tmp/$(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE).stamp + mkdir -p files/ + (cd tmp && zip -q -r ../$@ $(MARIADB_WITH_MROONGA_FOR_WINDOWS_BASE)) diff --git a/storage/mroonga/packages/source/patches/mariadb-10.0.3-windows-build.diff b/storage/mroonga/packages/source/patches/mariadb-10.0.3-windows-build.diff new file mode 100644 index 00000000000..c135088b8cc --- /dev/null +++ b/storage/mroonga/packages/source/patches/mariadb-10.0.3-windows-build.diff @@ -0,0 +1,9 @@ +diff -ur mariadb-10.0.2.orig/sql/sql_locale.cc mariadb-10.0.2/sql/sql_locale.cc +--- mariadb-10.0.2.orig/sql/sql_locale.cc 2013-04-23 13:13:59.000000000 +0900 ++++ mariadb-10.0.2/sql/sql_locale.cc 2013-05-19 12:55:27.590366542 +0900 +@@ -1,4 +1,4 @@ +-/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. ++/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by diff --git a/storage/mroonga/packages/ubuntu/Makefile.am b/storage/mroonga/packages/ubuntu/Makefile.am new file mode 100644 index 00000000000..493419275b3 --- /dev/null +++ b/storage/mroonga/packages/ubuntu/Makefile.am @@ -0,0 +1,24 @@ +CODE_NAMES = precise,trusty,utopic +SOURCE = ../$(PACKAGE)-$(VERSION).tar.gz + +all: + +ensure-launchpad-configuration: + @if test -z "$(LAUNCHPAD_UPLOADER_PGP_KEY)"; then \ + echo "--with-launchpad-uploader-pgp-key configure option must be specified."; \ + false; \ + fi + +upload: source ensure-launchpad-configuration + ./upload.rb \ + --package '$(PACKAGE)' \ + --version '$(VERSION)' \ + --source-archive '$(SOURCE)' \ + --code-names '$(CODE_NAMES)' \ + --debian-directory '$(srcdir)/../debian/' \ + --pgp-sign-key '$(LAUNCHPAD_UPLOADER_PGP_KEY)' + +source: $(SOURCE) + +$(SOURCE): + ln -s $(abs_top_builddir)/$(PACKAGE)-$(VERSION).tar.gz $(SOURCE) diff --git a/storage/mroonga/packages/ubuntu/upload.rb b/storage/mroonga/packages/ubuntu/upload.rb new file mode 100755 index 00000000000..3331de6d5eb --- /dev/null +++ b/storage/mroonga/packages/ubuntu/upload.rb @@ -0,0 +1,168 @@ +#!/usr/bin/env ruby +# +# Copyright(C) 2014 Kouhei Sutou +# Copyright(C) 2014 HAYASHI Kentaro +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require "optparse" +require "fileutils" +require "pathname" +require "open-uri" + +class Uploader + def initialize + @dput_configuration_name = "groonga-ppa" + end + + def run + ensure_dput_configuration + + parse_command_line! + + ensure_mysql_version + + @required_groonga_version = required_groonga_version + + @code_names.each do |code_name| + upload(code_name) + end + end + + private + def ensure_dput_configuration + dput_cf_path = Pathname.new("~/.dput.cf").expand_path + if dput_cf_path.exist? + dput_cf_content = dput_cf_path.read + else + dput_cf_content = "" + end + dput_cf_content.each_line do |line| + return if line.chomp == "[#{@dput_configuration_name}]" + end + + dput_cf_path.open("w") do |dput_cf| + dput_cf.puts(dput_cf_content) + dput_cf.puts(<<-CONFIGURATION) +[#{@dput_configuration_name}] +fqdn = ppa.launchpad.net +method = ftp +incoming = ~groonga/ppa/ubuntu/ +login = anonymous +allow_unsigned_uploads = 0 + CONFIGURATION + end + end + + def ensure_mysql_version + @mysql_version = {} + @code_names.each do |code_name| + open("http://packages.ubuntu.com/#{code_name}/allpackages?format=txt.gz") do |file| + file.each_line do |line| + @mysql_version[code_name] = $1 if line =~ /\Amysql-server \((.+?)\).+/ + end + end + end + end + + def parse_command_line! + + parser = OptionParser.new + parser.on("--package=NAME", + "The package name") do |name| + @package = name + end + parser.on("--version=VERSION", + "The version") do |version| + @version = version + end + parser.on("--source-archive=ARCHIVE", + "The source archive") do |source_archive| + @source_archive = Pathname.new(source_archive).expand_path + end + parser.on("--code-names=CODE_NAME1,CODE_NAME2,CODE_NAME3,...", Array, + "The target code names") do |code_names| + @code_names = code_names + end + parser.on("--debian-directory=DIRECTORY", + "The debian/ directory") do |debian_directory| + @debian_directory = Pathname.new(debian_directory).expand_path + end + parser.on("--pgp-sign-key=KEY", + "The PGP key to sign .changes and .dsc") do |pgp_sign_key| + @pgp_sign_key = pgp_sign_key + end + parser.on("--pbuilder", + "Use pbuilder for build check") do |pbuilder| + @use_pbuilder = pbuilder + end + + parser.parse! + end + + def upload(code_name) + in_temporary_directory do + FileUtils.cp(@source_archive.to_s, + "#{@package}_#{@version}.orig.tar.gz") + run_command("tar", "xf", @source_archive.to_s) + directory_name = "#{@package}-#{@version}" + Dir.chdir(directory_name) do + FileUtils.cp_r(@debian_directory.to_s, "debian") + deb_version = "#{current_deb_version.succ}~#{code_name}1" + run_command("dch", + "--distribution", code_name, + "--newversion", deb_version, + "Build for #{code_name}.") + run_command("sed", + "-i", "-e", "s,MYSQL_VERSION,#{@mysql_version[code_name]},", + "debian/control") + run_command("debuild", "-S", "-sa", "-pgpg2", "-k#{@pgp_sign_key}") + if @use_pbuilder + run_command("pbuilder-dist", code_name, "build", + "../#{@package}_#{deb_version}.dsc") + else + run_command("dput", @dput_configuration_name, + "../#{@package}_#{deb_version}_source.changes") + end + end + end + end + + def required_groonga_version + File.read("../../required_groonga_version").lines.first.chomp + end + + def current_deb_version + /\((.+)\)/ =~ File.read("debian/changelog").lines.first + $1 + end + + def in_temporary_directory + name = "tmp" + FileUtils.rm_rf(name) + FileUtils.mkdir_p(name) + Dir.chdir(name) do + yield + end + end + + def run_command(*command_line) + unless system(*command_line) + raise "failed to run command: #{command_line.join(' ')}" + end + end +end + +uploader = Uploader.new +uploader.run diff --git a/storage/mroonga/packages/windows/Makefile.am b/storage/mroonga/packages/windows/Makefile.am new file mode 100644 index 00000000000..a2ff8f59792 --- /dev/null +++ b/storage/mroonga/packages/windows/Makefile.am @@ -0,0 +1,12 @@ +EXTRA_DIST = \ + README.md \ + build-vc2010.bat \ + build-vc2010-zip-32.bat \ + build-vc2010-zip-64.bat \ + build-vc2010-msi-32.bat \ + build-vc2010-msi-64.bat \ + build-vc2013.bat \ + build-vc2013-zip-32.bat \ + build-vc2013-zip-64.bat \ + build-vc2013-msi-32.bat \ + build-vc2013-msi-64.bat diff --git a/storage/mroonga/packages/windows/README.md b/storage/mroonga/packages/windows/README.md new file mode 100644 index 00000000000..f7788ffe26b --- /dev/null +++ b/storage/mroonga/packages/windows/README.md @@ -0,0 +1,20 @@ +# How to build Windows binaries + +## Preparation + +TODO... + +## Build with Visual C++ Express + +You need to use Visual C++ 2012 or later to build Mroonga with Express +edition. `build-vc2013.bat` is a build batch script to build with +Visual C++ Express 2013. + +Note that you can't build MSI file with Express edition. You need to +use Professional edition or upper editions to build MSI file. + +## Build with Visual C++ Professional + +You can build both zip file MSI file with Professional edition. +`build-vc2010.bat` is a build batch script to build with Visual C++ +Professional 2010. diff --git a/storage/mroonga/packages/windows/build-vc2010-msi-32.bat b/storage/mroonga/packages/windows/build-vc2010-msi-32.bat new file mode 100644 index 00000000000..15185eaba92 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2010-msi-32.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2010-msi-32 +mkdir build-vc2010-msi-32 +cd build-vc2010-msi-32 +cmake ..\source -G "Visual Studio 10" > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target msi > msi.log +move *.msi ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2010-msi-64.bat b/storage/mroonga/packages/windows/build-vc2010-msi-64.bat new file mode 100644 index 00000000000..ea0b7f07eb3 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2010-msi-64.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2010-msi-64 +mkdir build-vc2010-msi-64 +cd build-vc2010-msi-64 +cmake ..\source -G "Visual Studio 10 Win64" > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target msi > msi.log +move *.msi ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2010-zip-32.bat b/storage/mroonga/packages/windows/build-vc2010-zip-32.bat new file mode 100644 index 00000000000..013080755d4 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2010-zip-32.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2010-zip-32 +mkdir build-vc2010-zip-32 +cd build-vc2010-zip-32 +cmake ..\source -G "Visual Studio 10" -DMRN_GROONGA_EMBED=OFF -DMRN_GROONGA_NORMALIZER_MYSQL_EMBED=OFF > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target package > zip.log +move *.zip ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2010-zip-64.bat b/storage/mroonga/packages/windows/build-vc2010-zip-64.bat new file mode 100644 index 00000000000..040c921fcef --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2010-zip-64.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2010-zip-64 +mkdir build-vc2010-zip-64 +cd build-vc2010-zip-64 +cmake ..\source -G "Visual Studio 10 Win64" -DMRN_GROONGA_EMBED=OFF -DMRN_GROONGA_NORMALIZER_MYSQL_EMBED=OFF > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target package > zip.log +move *.zip ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2010.bat b/storage/mroonga/packages/windows/build-vc2010.bat new file mode 100644 index 00000000000..5fcf0639412 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2010.bat @@ -0,0 +1,4 @@ +build-vc2010-zip-32.bat +build-vc2010-zip-64.bat +build-vc2010-msi-32.bat +build-vc2010-msi-64.bat diff --git a/storage/mroonga/packages/windows/build-vc2013-msi-32.bat b/storage/mroonga/packages/windows/build-vc2013-msi-32.bat new file mode 100644 index 00000000000..22b29972885 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2013-msi-32.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2013-msi-32 +mkdir build-vc2013-msi-32 +cd build-vc2013-msi-32 +cmake ..\source -G "Visual Studio 12" > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target msi > msi.log +move *.msi ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2013-msi-64.bat b/storage/mroonga/packages/windows/build-vc2013-msi-64.bat new file mode 100644 index 00000000000..c83a376cdb9 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2013-msi-64.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2013-msi-64 +mkdir build-vc2013-msi-64 +cd build-vc2013-msi-64 +cmake ..\source -G "Visual Studio 12 Win64" > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target msi > msi.log +move *.msi ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2013-zip-32.bat b/storage/mroonga/packages/windows/build-vc2013-zip-32.bat new file mode 100644 index 00000000000..d3e0e4f8b8e --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2013-zip-32.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2013-zip-32 +mkdir build-vc2013-zip-32 +cd build-vc2013-zip-32 +cmake ..\source -G "Visual Studio 12" -DMRN_GROONGA_EMBED=OFF -DMRN_GROONGA_NORMALIZER_MYSQL_EMBED=OFF > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target package > zip.log +move *.zip ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2013-zip-64.bat b/storage/mroonga/packages/windows/build-vc2013-zip-64.bat new file mode 100644 index 00000000000..6ca288b6a8b --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2013-zip-64.bat @@ -0,0 +1,8 @@ +rmdir /S /Q build-vc2013-zip-64 +mkdir build-vc2013-zip-64 +cd build-vc2013-zip-64 +cmake ..\source -G "Visual Studio 12 Win64" -DMRN_GROONGA_EMBED=OFF -DMRN_GROONGA_NORMALIZER_MYSQL_EMBED=OFF > config.log +cmake --build . --config RelWithDebInfo > build.log +cmake --build . --config RelWithDebInfo --target package > zip.log +move *.zip ..\ +cd .. diff --git a/storage/mroonga/packages/windows/build-vc2013.bat b/storage/mroonga/packages/windows/build-vc2013.bat new file mode 100644 index 00000000000..99d7e4042c5 --- /dev/null +++ b/storage/mroonga/packages/windows/build-vc2013.bat @@ -0,0 +1,4 @@ +build-vc2013-zip-32.bat +build-vc2013-zip-64.bat +REM build-vc2013-msi-32.bat +REM build-vc2013-msi-64.bat diff --git a/storage/mroonga/packages/yum/Makefile.am b/storage/mroonga/packages/yum/Makefile.am new file mode 100644 index 00000000000..b110b478a14 --- /dev/null +++ b/storage/mroonga/packages/yum/Makefile.am @@ -0,0 +1,63 @@ +REPOSITORIES_PATH = repositories +DISTRIBUTIONS = centos +ARCHITECTURES = i386 x86_64 +MYSQL_VARIANTS = mysql55 mysql56-community mariadb +SPEC_DIR = $(builddir)/../rpm/centos + +all: + +release: download build sign-packages update-repository upload + +remove-existing-packages: + for distribution in $(DISTRIBUTIONS); do \ + find $${distribution} -name "*.rpm" -delete; \ + done + +ensure-rsync-path: + @if test -z "$(RSYNC_PATH)"; then \ + echo "--with-rsync-path configure option must be specified."; \ + false; \ + fi + +sign-packages: + ./sign-rpm.sh '$(GPG_UID)' '$(REPOSITORIES_PATH)/' '$(DISTRIBUTIONS)' + +update-repository: + ./update-repository.sh '$(REPOSITORIES_PATH)/' '$(DISTRIBUTIONS)' + +upload: ensure-rsync-path + for distribution in $(DISTRIBUTIONS); do \ + rsync -avz --progress --delete --exclude .gitignore \ + $(REPOSITORIES_PATH)/$${distribution}/ \ + $(RSYNC_PATH)/$${distribution}; \ + done + +download: ensure-rsync-path + mkdir -p $(REPOSITORIES_PATH) + for distribution in $(DISTRIBUTIONS); do \ + rsync -avz --progress --delete \ + $(RSYNC_PATH)/$${distribution}/ \ + $(REPOSITORIES_PATH)/$${distribution}; \ + done + +build: build-in-vm + +build-in-vm: source specs env.sh + ./build-in-vm.sh \ + "$(PACKAGE)" \ + "$(SPEC_DIR)" \ + "$(MYSQL_VARIANTS)" \ + "$(ARCHITECTURES)" + +source: tmp/$(PACKAGE)-$(VERSION).tar.gz + +tmp/$(PACKAGE)-$(VERSION).tar.gz: $(abs_top_builddir)/$(PACKAGE)-$(VERSION).tar.gz + mkdir -p tmp/ + cp $(abs_top_builddir)/$(PACKAGE)-$(VERSION).tar.gz tmp/ + +$(abs_top_builddir)/$(PACKAGE)-$(VERSION).tar.gz: + cd $(abs_top_builddir) && $(MAKE) dist + +specs: $(SPEC_DIR)/mysql55-$(PACKAGE).spec +specs: $(SPEC_DIR)/mysql56-community-$(PACKAGE).spec +specs: $(SPEC_DIR)/mariadb-$(PACKAGE).spec diff --git a/storage/mroonga/packages/yum/Vagrantfile b/storage/mroonga/packages/yum/Vagrantfile new file mode 100644 index 00000000000..1a9e4584ee4 --- /dev/null +++ b/storage/mroonga/packages/yum/Vagrantfile @@ -0,0 +1,50 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + vms = [ + { + :id => "centos-5-i386", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-5.11-i386_chef-provisionerless.box", + }, + { + :id => "centos-5-x86_64", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-5.11_chef-provisionerless.box", + }, + { + :id => "centos-6-i386", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.6-i386_chef-provisionerless.box", + }, + { + :id => "centos-6-x86_64", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.6_chef-provisionerless.box", + }, + { + :id => "centos-7-x86_64", + :box_url => "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.0_chef-provisionerless.box", + }, + ] + + vms.each do |vm| + config.vm.define(vm[:id]) do |node| + node.vm.box = vm[:id] + node.vm.box_url = vm[:box_url] + node.vm.provision(:shell, :path => "build-rpm.sh") + node.vm.provider("virtualbox") do |virtual_box| + system_n_cpus = 1 + if File.exist?("/proc/cpuinfo") + system_n_cpus = File.readlines("/proc/cpuinfo").grep(/^processor/).size + end + if system_n_cpus > 1 + vm_n_cpus = system_n_cpus / 2 + else + vm_n_cpus = 1 + end + virtual_box.cpus = vm_n_cpus + end + end + end +end diff --git a/storage/mroonga/packages/yum/build-in-vm.sh b/storage/mroonga/packages/yum/build-in-vm.sh new file mode 100755 index 00000000000..5dc27ec38dd --- /dev/null +++ b/storage/mroonga/packages/yum/build-in-vm.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +if [ $# != 4 ]; then + echo "Usage: $0 PACKAGE SPEC_DIR MYSQL_VARIANTS ARCHITECTURES" + echo " e.g.: $0 mroonga ../rpm/centos 'mysql55 mariadb' 'i386 x86_64'" + exit 1 +fi + +PACKAGE="$1" +SPEC_DIR="$2" +MYSQL_VARIANTS="$3" +ARCHITECTURES="$4" + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +run vagrant destroy --force + +for mysql_variant in ${MYSQL_VARIANTS}; do + rm -rf tmp/centos/ + mkdir -p tmp/centos/ + cp ${SPEC_DIR}/${mysql_variant}-${PACKAGE}.spec tmp/centos/ + + architectures="${ARCHITECTURES}" + case ${mysql_variant} in + mysql55) + centos_versions="5 6" + ;; + mysql56-community) + centos_versions="6 7" + ;; + mariadb) + centos_versions="7" + ;; + esac + + for architecture in ${architectures}; do + for centos_version in ${centos_versions}; do + if [ ${mysql_variant} = mysql55 -a ${centos_version} = 6 -a ${architecture} = i386 ]; then + continue + fi + if [ ${centos_version} = 7 -a ${architecture} = i386 ]; then + continue + fi + id=centos-${centos_version}-${architecture} + vagrant up ${id} + build_status=$? + if [ $build_status -ne 0 ]; then + exit $build_status + fi + vagrant destroy --force ${id} + done + done +done diff --git a/storage/mroonga/packages/yum/build-rpm.sh b/storage/mroonga/packages/yum/build-rpm.sh new file mode 100755 index 00000000000..6eaa2cce02a --- /dev/null +++ b/storage/mroonga/packages/yum/build-rpm.sh @@ -0,0 +1,108 @@ +#!/bin/sh + +LANG=C + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +rpmbuild_options= + +. /vagrant/env.sh + +distribution=$(cut -d " " -f 1 /etc/redhat-release | tr "A-Z" "a-z") +if grep -q Linux /etc/redhat-release; then + distribution_version=$(cut -d " " -f 4 /etc/redhat-release) +else + distribution_version=$(cut -d " " -f 3 /etc/redhat-release) +fi +distribution_version=$(echo ${distribution_version} | sed -e 's/\..*$//g') + +architecture="$(arch)" +case "${architecture}" in + i*86) + architecture=i386 + ;; +esac + +run yum groupinstall -y "Development Tools" +run yum install -y rpm-build rpmdevtools tar wget + +if [ -x /usr/bin/rpmdev-setuptree ]; then + rm -rf .rpmmacros + run rpmdev-setuptree +else + run cat < ~/.rpmmacros +%_topdir ${HOME}/rpmbuild +EOM + run mkdir -p ~/rpmbuild/SOURCES + run mkdir -p ~/rpmbuild/SPECS + run mkdir -p ~/rpmbuild/BUILD + run mkdir -p ~/rpmbuild/RPMS + run mkdir -p ~/rpmbuild/SRPMS +fi + +repository="/vagrant/repositories/${distribution}/${distribution_version}" +rpm_dir="${repository}/${architecture}/Packages" +srpm_dir="${repository}/source/SRPMS" +run mkdir -p "${rpm_dir}" "${srpm_dir}" + +rpmbuild_options="" + +# for debug +# rpmbuild_options="${rpmbuild_options} --define 'optflags -O0 -g3'" + +cd + +run cp /vagrant/tmp/${PACKAGE}-${VERSION}.* rpmbuild/SOURCES/ +run cp /vagrant/tmp/${distribution}/*.spec rpmbuild/SPECS/ + +package_name=$(cd rpmbuild/SPECS; echo *.spec | sed -e 's/\.spec$//g') + +case ${distribution} in + fedora) + USE_MYSQLSERVICES_COMPAT=yes + run yum install -y mariadb-devel + ;; + centos) + case ${package_name} in + mysql55-${PACKAGE}) + USE_MYSQLSERVICES_COMPAT=yes + run yum install -y scl-utils-build + if [ ${distribution_version} = 6 ]; then + run yum install -y centos-release-SCL + fi + run yum install -y mysql55-mysql-devel mysql55-build + ;; + mysql56-community-${PACKAGE}) + release_rpm=mysql-community-release-el${distribution_version}-5.noarch.rpm + run yum -y install http://repo.mysql.com/${release_rpm} + run yum -y install mysql-community-devel + ;; + mariadb-${PACKAGE}) + run yum -y install mariadb-devel + ;; + esac + + release_rpm=groonga-release-1.1.0-1.noarch.rpm + wget http://packages.groonga.org/${distribution}/${release_rpm} + run rpm -U ${release_rpm} + rm -f ${release_rpm} + run yum makecache + ;; +esac +run yum install -y ${DEPENDED_PACKAGES} + +if [ "${USE_MYSQLSERVICES_COMPAT}" = "yes" ]; then + rpmbuild_options="$rpmbuild_options --define 'mroonga_configure_options --with-libmysqlservices-compat'" +fi + +run eval rpmbuild -ba ${rpmbuild_options} rpmbuild/SPECS/${package_name}.spec + +run mv rpmbuild/RPMS/*/* "${rpm_dir}/" +run mv rpmbuild/SRPMS/* "${srpm_dir}/" diff --git a/storage/mroonga/packages/yum/env.sh.in b/storage/mroonga/packages/yum/env.sh.in new file mode 100644 index 00000000000..90e701ec89e --- /dev/null +++ b/storage/mroonga/packages/yum/env.sh.in @@ -0,0 +1,27 @@ +PACKAGE=@PACKAGE@ +VERSION=@VERSION@ +DEPENDED_PACKAGES=" +intltool +libtool +gcc +gcc-c++ +make +gperf +readline-devel +openssl-devel +time +wget +ncurses-devel +sudo +pkgconfig +tar +cmake +libaio-devel +systemtap-sdt-devel +perl-Time-HiRes +perl-Env +perl-Test-Simple +pam-devel +groonga-devel +groonga-normalizer-mysql-devel +" diff --git a/storage/mroonga/packages/yum/sign-rpm.sh b/storage/mroonga/packages/yum/sign-rpm.sh new file mode 100755 index 00000000000..b3a45afe7f5 --- /dev/null +++ b/storage/mroonga/packages/yum/sign-rpm.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +script_base_dir=`dirname $0` + +if [ $# != 3 ]; then + echo "Usage: $0 GPG_UID DESTINATION DISTRIBUTIONS" + echo " e.g.: $0 'F10399C0' repositories/ 'fedora centos'" + exit 1 +fi + +GPG_UID=$1 +DESTINATION=$2 +DISTRIBUTIONS=$3 + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +unsigned_rpms() +{ + while read rpm; do + rpm --checksig "$rpm" | grep -v 'gpg OK' | cut -d":" -f1 + done +} + +if ! gpg --list-keys "${GPG_UID}" > /dev/null 2>&1; then + run gpg --keyserver keyserver.ubuntu.com --recv-key "${GPG_UID}" +fi +run mkdir -p tmp +run gpg --armor --export "${GPG_UID}" > tmp/sign-key +run rpm --import tmp/sign-key +run rm -rf tmp/sign-key + +rpms="" +for distribution in ${DISTRIBUTIONS}; do + rpms="${rpms} $(find ${DESTINATION}${distribution} -name '*.rpm' | unsigned_rpms)" +done + +echo "NOTE: YOU JUST ENTER! YOU DON'T NEED TO INPUT PASSWORD!" +echo " IT'S JUST FOR rpm COMMAND RESTRICTION!" +run echo $rpms | xargs rpm \ + -D "_gpg_name ${GPG_UID}" \ + -D "_gpg_digest_algo sha1" \ + -D "__gpg /usr/bin/gpg2" \ + -D "__gpg_check_password_cmd /bin/true true" \ + -D "__gpg_sign_cmd %{__gpg} gpg --batch --no-verbose --no-armor %{?_gpg_digest_algo:--digest-algo %{_gpg_digest_algo}} --no-secmem-warning -u \"%{_gpg_name}\" -sbo %{__signature_filename} %{__plaintext_filename}" \ + --resign diff --git a/storage/mroonga/packages/yum/update-repository.sh b/storage/mroonga/packages/yum/update-repository.sh new file mode 100755 index 00000000000..630b6c87422 --- /dev/null +++ b/storage/mroonga/packages/yum/update-repository.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +script_base_dir=`dirname $0` + +if [ $# != 2 ]; then + echo "Usage: $0 DESTINATION DISTRIBUTIONS" + echo " e.g.: $0 repositories/ 'fedora centos'" + exit 1 +fi + +DESTINATION=$1 +DISTRIBUTIONS=$2 + +run() +{ + "$@" + if test $? -ne 0; then + echo "Failed $@" + exit 1 + fi +} + +for distribution in ${DISTRIBUTIONS}; do + for dir in ${DESTINATION}${distribution}/*/*; do + # "--checksum sha" is for CentOS 5. If we drop CentOS 5 support, + # we can remove the option. + test -d $dir && run createrepo --checksum sha $dir + done; +done diff --git a/storage/mroonga/plugin_version b/storage/mroonga/plugin_version index be9fc83102e..6e636605163 100644 --- a/storage/mroonga/plugin_version +++ b/storage/mroonga/plugin_version @@ -1 +1 @@ -4.6 \ No newline at end of file +5.0 \ No newline at end of file diff --git a/storage/mroonga/required_groonga_version b/storage/mroonga/required_groonga_version index fcdb2e109f6..43beb4001b8 100644 --- a/storage/mroonga/required_groonga_version +++ b/storage/mroonga/required_groonga_version @@ -1 +1 @@ -4.0.0 +4.0.7 diff --git a/storage/mroonga/tools/travis/install.sh b/storage/mroonga/tools/travis/install.sh index fd3d2187914..95b8b23ba19 100755 --- a/storage/mroonga/tools/travis/install.sh +++ b/storage/mroonga/tools/travis/install.sh @@ -21,8 +21,8 @@ set -e mariadb_download_base=http://mirror.jmu.edu/pub/mariadb -export GROONGA_MASTER=yes -export GROONGA_NORMALIZER_MYSQL_MASTER=yes +# export GROONGA_MASTER=yes +# export GROONGA_NORMALIZER_MYSQL_MASTER=yes curl --silent --location https://github.com/groonga/groonga/raw/master/data/travis/setup.sh | sh curl --silent --location https://github.com/groonga/groonga-normalizer-mysql/raw/master/data/travis/setup.sh | sh @@ -43,6 +43,7 @@ if [ "${MROONGA_BUNDLED}" = "yes" ]; then curl -O ${download_base}/source/${tar_gz} tar xzf $tar_gz mv ${MYSQL_VERSION}/* ./ + rm -rf storage/mroonga mv .mroonga storage/mroonga rm -rf ${MYSQL_VERSION} else @@ -57,7 +58,8 @@ else sudo apt-get -qq -y build-dep mysql-server if [ "$version" = "system" ]; then sudo apt-get -qq -y install \ - mysql-server mysql-testsuite libmysqld-dev + mysql-server mysql-server-5.5 mysql-server-core-5.5 \ + mysql-testsuite libmysqld-dev apt-get -qq source mysql-server ln -s $(find . -maxdepth 1 -type d | sort | tail -1) mysql else diff --git a/storage/mroonga/udf/mrn_udf_command.cpp b/storage/mroonga/udf/mrn_udf_command.cpp index ba92e8daa26..172f64896a2 100644 --- a/storage/mroonga/udf/mrn_udf_command.cpp +++ b/storage/mroonga/udf/mrn_udf_command.cpp @@ -26,10 +26,10 @@ #include #include -extern mrn::DatabaseManager *mrn_db_manager; - MRN_BEGIN_DECLS +extern mrn::DatabaseManager *mrn_db_manager; + struct CommandInfo { grn_ctx ctx; @@ -100,7 +100,7 @@ error: grn_obj_close(&(info->ctx), info->db); } grn_ctx_fin(&(info->ctx)); - my_free(info, MYF(0)); + my_free(info); } return TRUE; } @@ -164,7 +164,7 @@ MRN_API void mroonga_command_deinit(UDF_INIT *initid) } grn_ctx_fin(&(info->ctx)); info->result.free(); - my_free(info, MYF(0)); + my_free(info); } } diff --git a/storage/mroonga/udf/mrn_udf_escape.cpp b/storage/mroonga/udf/mrn_udf_escape.cpp index ff997e7581f..36179788596 100644 --- a/storage/mroonga/udf/mrn_udf_escape.cpp +++ b/storage/mroonga/udf/mrn_udf_escape.cpp @@ -81,7 +81,7 @@ MRN_API my_bool mroonga_escape_init(UDF_INIT *initid, UDF_ARGS *args, error: if (info) { grn_ctx_fin(&(info->ctx)); - my_free(info, MYF(0)); + my_free(info); } return TRUE; } @@ -147,7 +147,7 @@ MRN_API void mroonga_escape_deinit(UDF_INIT *initid) grn_obj_unlink(&(info->ctx), &(info->target_characters)); grn_obj_unlink(&(info->ctx), &(info->escaped_query)); grn_ctx_fin(&(info->ctx)); - my_free(info, MYF(0)); + my_free(info); } } diff --git a/storage/mroonga/udf/mrn_udf_snippet.cpp b/storage/mroonga/udf/mrn_udf_snippet.cpp index 84166a36f16..3eaf05eed95 100644 --- a/storage/mroonga/udf/mrn_udf_snippet.cpp +++ b/storage/mroonga/udf/mrn_udf_snippet.cpp @@ -198,7 +198,7 @@ error: if (snip_info) { grn_obj_close(&snip_info->ctx, grn_ctx_db(&snip_info->ctx)); grn_ctx_fin(&snip_info->ctx); - my_free(snip_info, MYF(0)); + my_free(snip_info); } return TRUE; } @@ -295,7 +295,7 @@ MRN_API void mroonga_snippet_deinit(UDF_INIT *initid) snip_info->result_str.free(); grn_obj_close(&snip_info->ctx, grn_ctx_db(&snip_info->ctx)); grn_ctx_fin(&snip_info->ctx); - my_free(snip_info, MYF(0)); + my_free(snip_info); } } diff --git a/storage/mroonga/vendor/groonga/CMakeLists.txt b/storage/mroonga/vendor/groonga/CMakeLists.txt index abaa9911fd6..cddb3df28f6 100644 --- a/storage/mroonga/vendor/groonga/CMakeLists.txt +++ b/storage/mroonga/vendor/groonga/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright(C) 2012-2014 Brazil +# Copyright(C) 2012-2015 Brazil # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,12 +20,19 @@ cmake_minimum_required(VERSION 2.6.2) set(GRN_PROJECT_NAME "groonga") project("${GRN_PROJECT_NAME}") +if(CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(CMAKE_COMPILER_IS_CLANGC ON) +endif() +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_COMPILER_IS_CLANGCXX ON) +endif() + file(READ "${CMAKE_CURRENT_SOURCE_DIR}/base_version" VERSION) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/version.sh") file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.sh" GRN_VERSION) else() if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/version.sh") - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND EXISTS "/bin/sh") execute_process(COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/version-gen.sh") file(READ "${CMAKE_CURRENT_BINARY_DIR}/version.sh" GRN_VERSION) else() @@ -44,6 +51,15 @@ include(CheckCXXCompilerFlag) include(FindPkgConfig) include(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake_modules/ReadFileList.cmake) +if(DEFINED GRN_EMBED) + set(GRN_EMBED_DEFAULT ${GRN_EMBED}) +else() + set(GRN_EMBED_DEFAULT OFF) +endif() +option(GRN_EMBED + "Build as a static library to embed into an application" + ${GRN_EMBED_DEFAULT}) + set(BIN_DIR "bin") set(SBIN_DIR "sbin") set(LIB_DIR "lib") @@ -53,10 +69,14 @@ set(DATA_DIR "share") set(GRN_DATA_DIR "${DATA_DIR}/${GRN_PROJECT_NAME}") set(CONFIG_DIR "etc") set(GRN_CONFIG_DIR "${CONFIG_DIR}/${GRN_PROJECT_NAME}") +set(GRN_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${GRN_CONFIG_DIR}/groonga.conf") set(GRN_LOG_PATH "${CMAKE_INSTALL_PREFIX}/var/log/${GRN_PROJECT_NAME}/${GRN_PROJECT_NAME}.log" CACHE FILEPATH "log file path") +set(GRN_DEFAULT_ENCODING + "utf8" + CACHE STRING "Groonga's default encoding") set(GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD 0 CACHE STRING "groonga default match escalation threshold") @@ -69,6 +89,9 @@ set(GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT set(GRN_DEFAULT_DOCUMENT_ROOT "${CMAKE_INSTALL_PREFIX}/${GRN_DATA_DIR}/${GRN_DEFAULT_DOCUMENT_ROOT_BASE}" CACHE PATH "groonga default document root") +set(GRN_DEFAULT_DB_KEY + "auto" + CACHE STRING "Groonga's default DB key management algorithm") set(GRN_STACK_SIZE 1024 CACHE STRING @@ -97,15 +120,21 @@ set(GRN_RUBY_SCRIPTS_DIR "${CMAKE_INSTALL_PREFIX}/${GRN_RELATIVE_RUBY_SCRIPTS_DIR}") macro(check_cflag flag) - check_c_compiler_flag(${flag} "HAVE_C_${flag}") - if(HAVE_C_${flag}) + string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag}) + string(TOUPPER "${temporary_variable_name}" temporary_variable_name) + set(temporary_variable_name "CFLAG${temporary_variable_name}") + check_c_compiler_flag(${flag} ${temporary_variable_name}) + if(${temporary_variable_name}) set(GRN_C_COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS} ${flag}") endif() endmacro() macro(check_cxxflag flag) - check_cxx_compiler_flag(${flag} "HAVE_CXX_${flag}") - if(HAVE_CXX_${flag}) + string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag}) + string(TOUPPER "${temporary_variable_name}" temporary_variable_name) + set(temporary_variable_name "CXXFLAG${temporary_variable_name}") + check_cxx_compiler_flag(${flag} ${temporary_variable_name}) + if(${temporary_variable_name}) set(GRN_CXX_COMPILE_FLAGS "${GRN_CXX_COMPILE_FLAGS} ${flag}") endif() endmacro() @@ -137,7 +166,10 @@ if(CMAKE_COMPILER_IS_GNUCXX) check_cxxflag("-fexceptions") check_cxxflag("-fimplicit-templates") check_build_flag("-Wno-clobbered") - if(MRN_GROONGA_BUNDLED) +endif() + +if(GRN_EMBED) + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX) check_build_flag("-fPIC") endif() endif() @@ -154,17 +186,15 @@ add_definitions( -DHAVE_CONFIG_H ) -if(CMAKE_COMPILER_IS_GNUC OR - CMAKE_COMPILER_IS_GNUCXX OR - CMAKE_C_COMPILER_ID STREQUAL "Clang") +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX) set(_GNU_SOURCE TRUE) endif() include_directories( BEFORE ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/lib ) macro(ac_check_headers header) @@ -202,6 +232,7 @@ include(build/ac_macros/check_headers.m4) include(build/ac_macros/check_functions.m4) ac_check_symbols(fpclassify math.h) +ac_check_lib(m fpclassify) ac_check_lib(dl dlopen) ac_check_lib(execinfo backtrace) @@ -214,8 +245,7 @@ ac_check_lib(rt clock_gettime) if(HAVE_LIBRT) set(HAVE_CLOCK_GETTIME TRUE) endif() -if(MRN_GROONGA_BUNDLED) - ac_check_lib(m sincos) +if(GRN_EMBED) check_library_exists(stdc++ __cxa_begin_catch "${ARG2}" STDCPP) if(STDCPP) @@ -293,19 +323,29 @@ else() endif() endif() -option(GRN_WITH_ZLIB "use zlib for data compression." OFF) -if(GRN_WITH_ZLIB) +set(GRN_WITH_ZLIB "auto" + CACHE STRING "Support data compression by zlib.") +if(NOT ${GRN_WITH_ZLIB} STREQUAL "no") ac_check_lib(z compress) if(NOT HAVE_LIBZ) - message(FATAL_ERROR "No libz found") + if(${GRN_WITH_ZLIB} STREQUAL "yes") + message(FATAL_ERROR "No libz found") + endif() + set(GRN_WITH_ZLIB "no") endif() endif() -option(GRN_WITH_LZO "use LZO for data compression." OFF) -if(GRN_WITH_LZO) - ac_check_lib(lzo2 lzo1_compress) - if(NOT HAVE_LIBLZO2) - message(FATAL_ERROR "No liblzo2 found") +set(GRN_WITH_LZ4 "auto" + CACHE STRING "Support data compression by LZ4.") +if(NOT ${GRN_WITH_LZ4} STREQUAL "no") + pkg_check_modules(LIBLZ4 liblz4) + if(LIBLZ4_FOUND) + set(GRN_WITH_LZ4 TRUE) + else() + if(${GRN_WITH_LZ4} STREQUAL "yes") + message(FATAL_ERROR "No LZ4 found") + endif() + set(GRN_WITH_LZ4 FALSE) endif() endif() @@ -362,6 +402,38 @@ else() set(GRN_WITH_KYTEA FALSE) endif() +set(GRN_WITH_LIBSTEMMER "auto" + CACHE STRING "use libstemmer for stemming token filter") +if(NOT ${GRN_WITH_LIBSTEMMER} STREQUAL "no") + if(NOT ("${GRN_WITH_LIBSTEMMER}" STREQUAL "yes" OR + "${GRN_WITH_LIBSTEMMER}" STREQUAL "auto")) + if("${LIBSTEMMER_INCLUDE_DIRS}" STREQUAL "") + set(LIBSTEMMER_INCLUDE_DIRS "${GRN_WITH_LIBSTEMMER}/include") + endif() + if("${LIBSTEMMER_LIBRARY_DIRS}" STREQUAL "") + set(LIBSTEMMER_LIBRARY_DIRS "${GRN_WITH_LIBSTEMMER}/lib") + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES}) + set(CMAKE_REQUIRED_INCLUDES + ${CMAKE_REQUIRED_INCLUDES} + ${LIBSTEMMER_INCLUDE_DIRS}) + ac_check_headers(libstemmer.h) + ac_check_lib(stemmer sb_stemmer_list "${LIBSTEMMER_LIBRARY_DIRS}") + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE}) + if(HAVE_LIBSTEMMER_H AND HAVE_LIBSTEMMER) + set(LIBSTEMMER_LIBRARIES "stemmer") + set(GRN_WITH_LIBSTEMMER TRUE) + else() + if(${GRN_WITH_LIBSTEMMER} STREQUAL "yes") + message(FATAL_ERROR "No libstemmer found") + endif() + set(GRN_WITH_LIBSTEMMER FALSE) + endif() +else() + set(GRN_WITH_LIBSTEMMER FALSE) +endif() + set(GRN_WITH_ZEROMQ "auto" CACHE STRING "use ZeroMQ for suggestion") if(NOT ${GRN_WITH_ZEROMQ} STREQUAL "no") @@ -447,12 +519,16 @@ else() set(MRUBY_LIBS "") endif() -#add_subdirectory(vendor) +if(NOT GRN_EMBED) + add_subdirectory(vendor) +endif() add_subdirectory(lib) -add_subdirectory(src) -#add_subdirectory(plugins) -add_subdirectory(include) -#add_subdirectory(data) +if(NOT GRN_EMBED) + add_subdirectory(src) + add_subdirectory(plugins) + add_subdirectory(include) + add_subdirectory(data) +endif() configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) @@ -476,10 +552,10 @@ set(GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT "${GRN_DEFAULT_DOCUMENT_ROOT}") set(EXEEXT "${CMAKE_EXECUTABLE_SUFFIX}") configure_file(groonga.pc.in "${CMAKE_CURRENT_BINARY_DIR}/groonga.pc" @ONLY) -if(NOT MRN_GROONGA_BUNDLED) +if(NOT GRN_EMBED) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/groonga.pc" DESTINATION "${LIB_DIR}/pkgconfig/") endif() -#add_subdirectory(vendor/plugins) +add_subdirectory(vendor/plugins) diff --git a/storage/mroonga/vendor/groonga/Makefile.am b/storage/mroonga/vendor/groonga/Makefile.am index a5bf404d471..65b7c928770 100644 --- a/storage/mroonga/vendor/groonga/Makefile.am +++ b/storage/mroonga/vendor/groonga/Makefile.am @@ -69,7 +69,6 @@ update-latest-release: misc misc/update-latest-release.rb \ $(PACKAGE) $(OLD_RELEASE) $(OLD_RELEASE_DATE) \ $(VERSION) $(NEW_RELEASE_DATE) \ - packages/rpm/fedora/groonga.spec.in \ packages/rpm/centos/groonga.spec.in \ packages/debian/changelog \ doc/source/install.rst \ diff --git a/storage/mroonga/vendor/groonga/appveyor.yml b/storage/mroonga/vendor/groonga/appveyor.yml new file mode 100644 index 00000000000..aa4b65fb24e --- /dev/null +++ b/storage/mroonga/vendor/groonga/appveyor.yml @@ -0,0 +1,17 @@ +version: "{build}" +clone_depth: 10 +build_script: + - cmake . -G "Visual Studio 12 Win64" + - cmake --build . --config RelWithDebInfo + +notifications: + - provider: Email + to: + - kou@clear-code.com + - groonga-commit@lists.sourceforge.jp + on_build_status_changed: true + +before_test: + - gem install grntest +test_script: + - grntest --groonga src\groonga.exe --base-directory test\command test\command\suite diff --git a/storage/mroonga/vendor/groonga/autogen.sh b/storage/mroonga/vendor/groonga/autogen.sh index 9b3a98eab5d..66184bf13be 100755 --- a/storage/mroonga/vendor/groonga/autogen.sh +++ b/storage/mroonga/vendor/groonga/autogen.sh @@ -18,4 +18,9 @@ FreeBSD) ;; esac +if [ ! -e vendor/mruby-source/.git ]; then + rm -rf vendor/mruby-source +fi +git submodule update --init + ${AUTORECONF:-autoreconf} --force --install diff --git a/storage/mroonga/vendor/groonga/base_version b/storage/mroonga/vendor/groonga/base_version index 9eefef7bd65..28cbf7c0aae 100644 --- a/storage/mroonga/vendor/groonga/base_version +++ b/storage/mroonga/vendor/groonga/base_version @@ -1 +1 @@ -4.0.6 \ No newline at end of file +5.0.0 \ No newline at end of file diff --git a/storage/mroonga/vendor/groonga/benchmark/bench-geo-distance.c b/storage/mroonga/vendor/groonga/benchmark/bench-geo-distance.c index 8e1d819538b..72d1d79b73f 100644 --- a/storage/mroonga/vendor/groonga/benchmark/bench-geo-distance.c +++ b/storage/mroonga/vendor/groonga/benchmark/bench-geo-distance.c @@ -49,7 +49,7 @@ #include -#include +#include #include #include "lib/benchmark.h" diff --git a/storage/mroonga/vendor/groonga/benchmark/bench-geo-select.c b/storage/mroonga/vendor/groonga/benchmark/bench-geo-select.c index b934f225330..7b57eaaffdc 100644 --- a/storage/mroonga/vendor/groonga/benchmark/bench-geo-select.c +++ b/storage/mroonga/vendor/groonga/benchmark/bench-geo-select.c @@ -58,7 +58,7 @@ #include -#include +#include #include #include "lib/benchmark.h" diff --git a/storage/mroonga/vendor/groonga/benchmark/bench-range-select.c b/storage/mroonga/vendor/groonga/benchmark/bench-range-select.c index 4c0b500aae2..d45d453cba6 100644 --- a/storage/mroonga/vendor/groonga/benchmark/bench-range-select.c +++ b/storage/mroonga/vendor/groonga/benchmark/bench-range-select.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include "lib/benchmark.h" diff --git a/storage/mroonga/vendor/groonga/build/ac_macros/check_functions.m4 b/storage/mroonga/vendor/groonga/build/ac_macros/check_functions.m4 index 5046e8ce6ab..72e3a9a545d 100644 --- a/storage/mroonga/vendor/groonga/build/ac_macros/check_functions.m4 +++ b/storage/mroonga/vendor/groonga/build/ac_macros/check_functions.m4 @@ -1,5 +1,8 @@ # -*- autoconf -*- +AC_CHECK_FUNCS(_gmtime64_s) +AC_CHECK_FUNCS(_localtime64_s) +AC_CHECK_FUNCS(_stricmp) AC_CHECK_FUNCS(_strnicmp) AC_CHECK_FUNCS(_strtoui64) AC_CHECK_FUNCS(close) @@ -8,6 +11,8 @@ AC_CHECK_FUNCS(localtime_r) AC_CHECK_FUNCS(mkostemp) AC_CHECK_FUNCS(open) AC_CHECK_FUNCS(read) +AC_CHECK_FUNCS(strcasecmp) AC_CHECK_FUNCS(strncasecmp) AC_CHECK_FUNCS(strtoull) +AC_CHECK_FUNCS(unlink) AC_CHECK_FUNCS(write) diff --git a/storage/mroonga/vendor/groonga/build/ac_macros/check_headers.m4 b/storage/mroonga/vendor/groonga/build/ac_macros/check_headers.m4 index 513f61afac4..17de74c11a5 100644 --- a/storage/mroonga/vendor/groonga/build/ac_macros/check_headers.m4 +++ b/storage/mroonga/vendor/groonga/build/ac_macros/check_headers.m4 @@ -1,9 +1,11 @@ # -*- autoconf -*- +AC_CHECK_HEADERS(dirent.h) AC_CHECK_HEADERS(dlfcn.h) AC_CHECK_HEADERS(errno.h) AC_CHECK_HEADERS(execinfo.h) AC_CHECK_HEADERS(inttypes.h) +AC_CHECK_HEADERS(io.h) AC_CHECK_HEADERS(netdb.h) AC_CHECK_HEADERS(netinet/in.h) AC_CHECK_HEADERS(netinet/tcp.h) diff --git a/storage/mroonga/vendor/groonga/config.h.cmake b/storage/mroonga/vendor/groonga/config.h.cmake index d172bc36dba..e6482f070c7 100644 --- a/storage/mroonga/vendor/groonga/config.h.cmake +++ b/storage/mroonga/vendor/groonga/config.h.cmake @@ -83,8 +83,7 @@ #cmakedefine GRN_WITH_BENCHMARK #cmakedefine GRN_WITH_CUTTER #cmakedefine GRN_WITH_KYTEA -#cmakedefine GRN_WITH_LIBMEMCACHED -#cmakedefine GRN_WITH_LZO +#cmakedefine GRN_WITH_LZ4 #cmakedefine GRN_WITH_MECAB #cmakedefine GRN_WITH_MESSAGE_PACK #cmakedefine GRN_WITH_MRUBY @@ -93,10 +92,12 @@ #cmakedefine GRN_WITH_ZLIB /* headers */ +#cmakedefine HAVE_DIRENT_H #cmakedefine HAVE_DLFCN_H #cmakedefine HAVE_ERRNO_H #cmakedefine HAVE_EXECINFO_H #cmakedefine HAVE_INTTYPES_H +#cmakedefine HAVE_IO_H #cmakedefine HAVE_LINUX_FUTEX_H #cmakedefine HAVE_MEMORY_H #cmakedefine HAVE_NETDB_H @@ -133,6 +134,9 @@ #cmakedefine HAVE_MECAB_DICTIONARY_INFO_T /* functions */ +#cmakedefine HAVE__GMTIME64_S +#cmakedefine HAVE__LOCALTIME64_S +#cmakedefine HAVE__STRICMP #cmakedefine HAVE__STRNICMP #cmakedefine HAVE__STRTOUI64 #cmakedefine HAVE_BACKTRACE @@ -145,8 +149,10 @@ #cmakedefine HAVE_MKOSTEMP #cmakedefine HAVE_OPEN #cmakedefine HAVE_READ +#cmakedefine HAVE_STRCASECMP #cmakedefine HAVE_STRNCASECMP #cmakedefine HAVE_STRTOULL +#cmakedefine HAVE_UNLINK #cmakedefine HAVE_WRITE #cmakedefine HAVE_PTHREAD_MUTEXATTR_SETPSHARED #cmakedefine HAVE_PTHREAD_CONDATTR_SETPSHARED diff --git a/storage/mroonga/vendor/groonga/config.sh.in b/storage/mroonga/vendor/groonga/config.sh.in index b4cec3caba1..d15e5e366e7 100644 --- a/storage/mroonga/vendor/groonga/config.sh.in +++ b/storage/mroonga/vendor/groonga/config.sh.in @@ -4,3 +4,4 @@ export GROONGA="@GROONGA@" export GROONGA_HTTPD="@GROONGA_HTTPD@" export GROONGA_SUGGEST_CREATE_DATASET="@GROONGA_SUGGEST_CREATE_DATASET@" export GROONGA_BENCHMARK="@GROONGA_BENCHMARK@" +export GROONGA_MRUBY="@GROONGA_MRUBY@" diff --git a/storage/mroonga/vendor/groonga/configure.ac b/storage/mroonga/vendor/groonga/configure.ac index 2be82a165e2..1d74bac30f4 100644 --- a/storage/mroonga/vendor/groonga/configure.ac +++ b/storage/mroonga/vendor/groonga/configure.ac @@ -75,7 +75,8 @@ AC_MSG_RESULT([$solaris]) AC_C_BIGENDIAN AC_PROG_CXX AC_PROG_CC -AC_PROG_CC_C99 +m4_ifdef([AC_PROG_CC_C99], + [AC_PROG_CC_C99]) AM_PROG_CC_C_O m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG([0.19]) @@ -160,7 +161,6 @@ if test "$GCC" = "yes"; then CHECK_BUILD_FLAG([-Wdisabled-optimization]) CHECK_BUILD_FLAG([-Wfloat-equal]) CHECK_BUILD_FLAG([-Wpointer-arith]) - CHECK_CFLAG([-Wdeclaration-after-statement]) CHECK_CFLAG([-Wbad-function-cast]) if test "$CLANG" = "no"; then CHECK_BUILD_FLAG([-Wcast-align]) @@ -235,6 +235,7 @@ AC_CONFIG_FILES([ plugins/query_expanders/Makefile plugins/ruby/Makefile plugins/token_filters/Makefile + plugins/sharding/Makefile examples/Makefile examples/dictionary/Makefile examples/dictionary/edict/Makefile @@ -246,7 +247,6 @@ AC_CONFIG_FILES([ packages/ubuntu/Makefile packages/rpm/Makefile packages/rpm/centos/Makefile - packages/rpm/fedora/Makefile packages/yum/Makefile packages/source/Makefile packages/windows/Makefile @@ -684,6 +684,10 @@ AC_SUBST(GROONGA_BENCHMARK) GROONGA_SUGGEST_CREATE_DATASET="${ac_pwd}/src/suggest/groonga-suggest-create-dataset" AC_SUBST(GROONGA_SUGGEST_CREATE_DATASET) +# groonga-mruby binary path +GROONGA_MRUBY="${ac_pwd}/src/groonga-mruby" +AC_SUBST(GROONGA_MRUBY) + # check Cutter with GLib support if available REQUIRED_MINIMUM_CUTTER_VERSION=1.1.6 REQUIRED_MINIMUM_CPPCUTTER_VERSION=1.2.0 @@ -867,28 +871,64 @@ fi # zlib AC_ARG_WITH(zlib, [AS_HELP_STRING([--with-zlib], - [use zlib for data compression. [default=no]])], + [Support data compression by zlib. [default=auto]])], [with_zlib="$withval"], - [with_zlib="no"]) + [with_zlib="auto"]) GRN_WITH_ZLIB=no -if test "x$with_zlib" = "xyes"; then - AC_DEFINE(GRN_WITH_ZLIB, [1], [with zlib]) - AC_SEARCH_LIBS(compress, z, [GRN_WITH_ZLIB=yes], - [AC_MSG_ERROR("No libz found")]) -else - AC_SEARCH_LIBS(compress, z, [GRN_WITH_ZLIB=yes], []) +if test "x$with_zlib" != "xno"; then + # TODO: Support custom zlib include and lib directory by --with-zlib. + AC_SEARCH_LIBS(compress, z, + [ + GRN_WITH_ZLIB=yes + AC_DEFINE(GRN_WITH_ZLIB, [1], + [Support data compression by zlib.]) + ], + [ + if test "x$with_zlib" != "xauto"; then + AC_MSG_ERROR("No libz found") + fi + ]) fi AC_SUBST(GRN_WITH_ZLIB) -# LZO -AC_ARG_WITH(lzo, - [AS_HELP_STRING([--with-lzo], - [use LZO for data compression. [default=no]])], - [with_lzo="$withval"], - [with_lzo="no"]) -if test "x$with_lzo" = "xyes"; then - AC_DEFINE(GRN_WITH_LZO, [1], [with lzo]) - AC_SEARCH_LIBS(lzo1_compress, lzo2, [], [AC_MSG_ERROR("No liblzo2 found")]) +# LZ4 +AC_ARG_WITH(lz4, + [AS_HELP_STRING([--with-lz4], + [Support data compression by LZ4. [default=auto]])], + [with_lz4="$withval"], + [with_lz4="auto"]) +if test "x$with_lz4" != "xno"; then + m4_ifdef([PKG_CHECK_MODULES], [ + PKG_CHECK_MODULES([LIBLZ4], + [liblz4], + [GRN_WITH_LZ4=yes], + [GRN_WITH_LZ4=no]) + ], + [GRN_WITH_LZ4=no]) + if test "$GRN_WITH_LZ4" = "yes"; then + AC_DEFINE(GRN_WITH_LZ4, [1], + [Support data compression by LZ4.]) + else + if test "x$with_lz4" != "xauto"; then + AC_MSG_ERROR("No liblz4 found") + fi + fi +fi + +# jemalloc +AC_ARG_WITH(jemalloc, + [AS_HELP_STRING([--with-jemalloc], + [Use jemalloc for memory allocation. [default=no]])], + [with_jemalloc="$withval"], + [with_jemalloc="no"]) +jemalloc_available="no" +if test "x$with_jemalloc" != "xno"; then + if test "x$with_jemalloc" != "xyes"; then + LDFLAGS="-L$with_jemalloc $LDFLAGS" + fi + AC_SEARCH_LIBS(malloc_conf, jemalloc, + [jemalloc_available="yes"], + [AC_MSG_ERROR("No libjemalloc found")]) fi # MeCab @@ -973,6 +1013,63 @@ if test "x$with_kytea" = "xyes"; then fi AM_CONDITIONAL(WITH_KYTEA, test "x$with_kytea" = "xyes") +# libstemmer +AC_ARG_WITH(libstemmer, + [AS_HELP_STRING([--with-libstemmer], + [use libstemmer for stemming. [default=auto]])], + [with_libstemmer="$withval"], + [with_libstemmer="auto"]) +AC_ARG_WITH(libstemmer-include, + [AS_HELP_STRING([--with-libstemmer-include], + [path to libstemmer.h. [default=auto]])]) +AC_ARG_WITH(libstemmer-lib, + [AS_HELP_STRING([--with-libstemmer-lib], + [path to libstemmer.so. [default=auto]])]) +AC_MSG_CHECKING([whether enable libstemmer]) +AC_MSG_RESULT($with_libstemmer) +if test "x$with_libstemmer" != "xno"; then + LIBSTEMMER_CFLAGS="" + LIBSTEMMER_LDFLAGS="" + LIBSTEMMER_LIBS="" + + CFLAGS_save="${CFLAGS}" + LDFLAGS_save="${LDFLAGS}" + if test "x$with_libstemmer" != "xauto"; then + if test -z "${with_libstemmer_include}"; then + with_libstemmer_include="${with_libstemmer}/include" + fi + LIBSTEMMER_CFLAGS="-I${with_libstemmer_include}" + if test -z "${with_libstemmer_lib}"; then + with_libstemmer_lib="${with_libstemmer}/lib" + fi + LIBSTEMMER_LDFLAGS="-L${with_libstemmer_lib}" + CFLAGS="${CFLAGS} ${LIBSTEMMER_CFLAGS}" + LDFLAGS="${LDFLAGS} ${LIBSTEMMER_LDFLAGS}" + fi + AC_CHECK_HEADERS(libstemmer.h, + [libstemmer_exists=yes], + [libstemmer_exists=no]) + if test "$libstemmer_exists" = "yes"; then + AC_CHECK_LIB(stemmer, sb_stemmer_list, + [LIBSTEMMER_LIBS="-lstemmer"], + [libstemmer_exists=no]) + fi + CFLAGS="${CFLAGS_save}" + LDFLAGS="${LDFLAGS_save}" + + if test "$libstemmer_exists" = "no" -a "x$with_libstemmer" != "xauto"; then + AC_MSG_ERROR("No libstemmer found at ${with_libstemmer_include} and ${with_libstemmer_lib}.") + fi + with_libstemmer="$libstemmer_exists" +fi +if test "x$with_libstemmer" = "xyes"; then + AC_SUBST(LIBSTEMMER_CFLAGS) + AC_SUBST(LIBSTEMMER_LDFLAGS) + AC_SUBST(LIBSTEMMER_LIBS) + AC_DEFINE(GRN_WITH_LIBSTEMMER, [1], [use libstemmer]) +fi +AM_CONDITIONAL(WITH_LIBSTEMMER, test "x$with_libstemmer" = "xyes") + # futex check AC_ARG_ENABLE(futex, [AS_HELP_STRING([--enable-futex], @@ -1136,15 +1233,15 @@ Install it and try again. How to install sphinx-build: For Debian GNU/Linux based system like Ubuntu: - % sudo apt-get install -y python-pip - % sudo pip install sphinx + % sudo apt-get install -y python-sphinx For Red Hat based system like CentOS: % sudo yum install -y python-pip % sudo pip install sphinx For OS X with Homebrew: - % brew install pip + % brew install python + % brew install gettext % export PATH="`brew --prefix gettext`/bin:\$PATH" % pip install sphinx]) fi @@ -1247,6 +1344,9 @@ AC_SUBST(ruby_pluginsdir) token_filter_pluginsdir="\${pluginsdir}/token_filters" AC_SUBST(token_filter_pluginsdir) +sharding_pluginsdir="\${pluginsdir}/sharding" +AC_SUBST(sharding_pluginsdir) + AC_MSG_CHECKING(for the suffix of plugin shared libraries) shrext_cmds=$(./libtool --config | grep '^shrext_cmds=') eval $shrext_cmds @@ -1361,15 +1461,10 @@ if test "$enable_mruby" = "yes"; then fi AC_DEFINE(GRN_WITH_MRUBY, [1], [Define to 1 if mruby is enabled.]) MRUBY_CFLAGS="-I\$(top_srcdir)/vendor/mruby-source/include" - MRUBY_LIBS="\$(top_builddir)/vendor/mruby/libmruby.la" - MRUBY_LIBS="${MRUBY_LIBS} \$(top_builddir)/vendor/onigmo-source/libonig.la" - AC_CONFIG_SUBDIRS([vendor/onigmo]) else - MRUBY_CFLAGS= - MRUBY_LIBS= + MRUBY_CFLAGS="" fi AC_SUBST(MRUBY_CFLAGS) -AC_SUBST(MRUBY_LIBS) AM_CONDITIONAL(WITH_MRUBY, test "$enable_mruby" = "yes") # This option is used in vendor/onigmo/configure @@ -1380,12 +1475,20 @@ AC_ARG_ENABLE(shared-onigmo, [enable_shared_onigmo="no"]) AM_CONDITIONAL(WITH_SHARED_ONIGMO, test "$enable_shared_onigmo" = "yes") +AC_DEFINE(GRN_WITH_ONIGMO, [1], [Use Onigmo.]) +AC_CONFIG_SUBDIRS([vendor/onigmo]) + +ONIGMO_CFLAGS="-I\$(top_srcdir)/vendor/onigmo-source" +ONIGMO_LIBS="\$(top_builddir)/vendor/onigmo-source/libonig.la" +AC_SUBST(ONIGMO_CFLAGS) +AC_SUBST(ONIGMO_LIBS) + # PCRE GRN_WITH_PCRE=no AC_ARG_WITH(pcre, [AS_HELP_STRING([--without-pcre], - [use PCRE for groonga-httpd. [default=auto-detect]])], - [with_pcre="$witheval"], + [Don't use PCRE for groonga-httpd. [default=auto-detect]])], + [with_pcre="$withval"], [with_pcre="auto"]) if test "x$with_pcre" != "xno"; then m4_ifdef([PKG_CHECK_MODULES], [ @@ -1446,7 +1549,6 @@ AC_SUBST(GROONGA_HTTPD_DEFAULT_DATABASE_PATH) AC_OUTPUT([ packages/rpm/centos/groonga.spec - packages/rpm/fedora/groonga.spec packages/apt/debian/groonga-keyring.postrm packages/apt/env.sh packages/yum/env.sh @@ -1489,6 +1591,14 @@ if test "x$with_kytea" = "xyes"; then fi echo +echo "Token filters:" +echo " libstemmer: $with_libstemmer" +if test "x$with_libstemmer" = "xyes"; then + echo " CFLAGS: $LIBSTEMMER_CFLAGS" + echo " LIBS: $LIBSTEMMER_LIBS" +fi +echo + echo "Libraries:" echo " ZeroMQ: $zeromq_available" if test "x$zeromq_available" = "xyes"; then @@ -1506,6 +1616,7 @@ if test "x$message_pack_available" = "xyes"; then echo " LIBS: ${MESSAGE_PACK_LIBS}" fi echo " mruby: $enable_mruby" +echo " jemalloc: $jemalloc_available" echo echo "groonga-httpd:" diff --git a/storage/mroonga/vendor/groonga/examples/Makefile.am b/storage/mroonga/vendor/groonga/examples/Makefile.am new file mode 100644 index 00000000000..f436342d053 --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = dictionary diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/Makefile.am b/storage/mroonga/vendor/groonga/examples/dictionary/Makefile.am new file mode 100644 index 00000000000..ee618a213bd --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/Makefile.am @@ -0,0 +1,34 @@ +SUBDIRS = \ + edict \ + eijiro \ + gene95 \ + jmdict + +dist_examples_dictionary_SCRIPTS = \ + init-db.sh + +nobase_dist_examples_dictionary_DATA = \ + readme.txt \ + $(html_files) + +# find html -type f | sort | sed -e 's,^,\t,g' +html_files = \ + html/css/dictionary.css \ + html/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png \ + html/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png \ + html/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png \ + html/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png \ + html/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png \ + html/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png \ + html/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png \ + html/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png \ + html/css/smoothness/images/ui-icons_222222_256x240.png \ + html/css/smoothness/images/ui-icons_2e83ff_256x240.png \ + html/css/smoothness/images/ui-icons_454545_256x240.png \ + html/css/smoothness/images/ui-icons_888888_256x240.png \ + html/css/smoothness/images/ui-icons_cd0a0a_256x240.png \ + html/css/smoothness/jquery-ui-1.8.12.custom.css \ + html/index.html \ + html/js/dictionary.js \ + html/js/jquery-1.7.2.js \ + html/js/jquery-ui-1.8.18.custom.js diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/edict/Makefile.am b/storage/mroonga/vendor/groonga/examples/dictionary/edict/Makefile.am new file mode 100644 index 00000000000..376f9d520ab --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/edict/Makefile.am @@ -0,0 +1,4 @@ +edictdir = $(examples_dictionarydir)/edict +dist_edict_SCRIPTS = \ + edict2grn.rb \ + edict-import.sh diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/edict/edict-import.sh b/storage/mroonga/vendor/groonga/examples/dictionary/edict/edict-import.sh new file mode 100755 index 00000000000..b98397be05a --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/edict/edict-import.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +base_dir=$(dirname $0) + +if [ 1 != $# -a 2 != $# ]; then + echo "usage: $0 db_path [edict.gz_path]" + exit 1 +fi + +if [ -z $2 ]; then + edict_gz=edict.gz + if [ ! -f $edict_gz ]; then + wget -O $edict_gz http://ftp.monash.edu.au/pub/nihongo/edict.gz + fi +else + edict_gz=$2 +fi + +if zcat $edict_gz | ${base_dir}/edict2grn.rb | groonga $1 > /dev/null; then + echo "edict data loaded." +fi diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/edict/edict2grn.rb b/storage/mroonga/vendor/groonga/examples/dictionary/edict/edict2grn.rb new file mode 100755 index 00000000000..664b12c2148 --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/edict/edict2grn.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +$KCODE = 'u' + +require 'English' +require 'kconv' + +class String + def to_json + a = split(//).map {|char| + case char + when '"' then '\\"' + when '\\' then '\\\\' + when "\b" then '\b' + when "\f" then '\f' + when "\n" then '\n' + when "\r" then '' + when "\t" then '\t' + else char + end + } + "\"#{a.join('')}\"" + end +end + +class Array + def to_json + '[' + map {|element| + element.to_json + }.join(',') + ']' + end +end + +puts < /dev/null; then + echo "eijiro data loaded." +fi diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/eijiro/eijiro2grn.rb b/storage/mroonga/vendor/groonga/examples/dictionary/eijiro/eijiro2grn.rb new file mode 100755 index 00000000000..62c1e1309bf --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/eijiro/eijiro2grn.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +$KCODE = 'u' + +require 'rubygems' +require 'fastercsv' + +class String + def to_json + a = split(//).map {|char| + case char + when '"' then '\\"' + when '\\' then '\\\\' + when "\b" then '\b' + when "\f" then '\f' + when "\n" then '\n' + when "\r" then '' + when "\t" then '\t' + else char + end + } + "\"#{a.join('')}\"" + end +end + +class Array + def to_json + '[' + map {|element| + element.to_json + }.join(',') + ']' + end +end + +puts < "\r\n").each {|l| + if n > 0 + keyword,word,trans,exp,level,memory,modify,pron,filelink = l + kana = '' + if trans =~ /ã€ï¼ ã€‘(.*?)(ã€|$)/ + kana = $1.split("ã€") + end + puts [word,keyword,trans,exp,level,memory,modify,pron,filelink,kana].map{|e| e || ''}.to_json + end + n += 1 +} + +puts "]" diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/gene95/Makefile.am b/storage/mroonga/vendor/groonga/examples/dictionary/gene95/Makefile.am new file mode 100644 index 00000000000..e89f13f595c --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/gene95/Makefile.am @@ -0,0 +1,4 @@ +gene95dir = $(examples_dictionarydir)/gene95 +dist_gene95_SCRIPTS = \ + gene2grn.rb \ + gene-import.sh diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene-import.sh b/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene-import.sh new file mode 100755 index 00000000000..488d6c83adc --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene-import.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +base_dir=$(dirname $0) + +if [ 1 != $# -a 2 != $# ]; then + echo "usage: $0 db_path [gene.txt_path]" + exit 1 +fi + +if [ -z $2 ]; then + dictionary_dir=gene95-dictionary + gene_txt=${dictionary_dir}/gene.txt + if [ ! -f $gene_txt ]; then + gene95_tar_gz=gene95.tar.gz + wget -O $gene95_tar_gz \ + http://www.namazu.org/~tsuchiya/sdic/data/gene95.tar.gz + mkdir -p ${dictionary_dir} + tar xvzf ${gene95_tar_gz} -C ${dictionary_dir} + fi +else + gene_txt=$2 +fi + +if cat $gene_txt | ${base_dir}/gene2grn.rb | groonga $1 > /dev/null; then + echo "gene95 data loaded." +fi diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene2grn.rb b/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene2grn.rb new file mode 100755 index 00000000000..0d10cfd1085 --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/gene95/gene2grn.rb @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +$KCODE = 'u' + +require 'kconv' + +class String + def to_json + a = split(//).map {|char| + case char + when '"' then '\\"' + when '\\' then '\\\\' + when "\b" then '\b' + when "\f" then '\f' + when "\n" then '\n' + when "\r" then '' + when "\t" then '\t' + else char + end + } + "\"#{a.join('')}\"" + end +end + +class Array + def to_json + '[' + map {|element| + element.to_json + }.join(',') + ']' + end +end + +puts < + + + + + +groonga dictionary search + + + + + + + + + + + +
+ + diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/html/js/dictionary.js b/storage/mroonga/vendor/groonga/examples/dictionary/html/js/dictionary.js new file mode 100644 index 00000000000..850c64cc667 --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/html/js/dictionary.js @@ -0,0 +1,82 @@ +function dictionarySource(url) { + function displayItems(items) { + var results = $("
"); + $.each(items, + function(i, val) { + results.append($("
") + .append($("") + .text(val[0]) + .click(function() { + $(".search").val($(this).text()); + $("#search").submit(); + }))); + results.append($("
") + .append($("").text(val[1])) + .append($("").text(val[2])) + ); + }); + $("#result") + .empty() + .append(results); + }; + + var request_index = 0; + var columns = "_key,gene95_desc,edict_desc"; + var xhr; + function source(request, response) { + function onSuccess(data, status) { + if (this.autocomplete_request != request_index) { + return; + } + var completions = data[1]["complete"]; + var items = []; + if (completions && completions.length > 2) { + completions.shift(); + completions.shift(); + $.each(completions, + function(i, item) { + var key = item[0]; + items.push(key); + if (items.length >= 3) { + return false; + } + return true; + }); + } + if (completions.length > 0) { + displayItems(completions); + } + response(items); + } + + function onError() { + if (this.autocomplete_request != request_index) { + return; + } + response([]); + } + + if (xhr) { + xhr.abort(); + } + xhr = $.ajax(url, + { + data: { + query: request.term, + types: 'complete', + table: 'item_dictionary', + column: 'kana', + limit: 25, + output_columns: columns, + frequency_threshold: 1, + prefix_search: "yes" + }, + dataType: "jsonp", + autocomplete_request: ++request_index, + success: onSuccess, + error: onError + }); + }; + + return source; +} diff --git a/storage/mroonga/vendor/groonga/examples/dictionary/html/js/jquery-1.7.2.js b/storage/mroonga/vendor/groonga/examples/dictionary/html/js/jquery-1.7.2.js new file mode 100644 index 00000000000..3774ff98613 --- /dev/null +++ b/storage/mroonga/vendor/groonga/examples/dictionary/html/js/jquery-1.7.2.js @@ -0,0 +1,9404 @@ +/*! + * jQuery JavaScript Library v1.7.2 + * http://jquery.com/ + * + * Copyright 2011, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Wed Mar 21 12:46:34 2012 -0700 + */ +(function( window, undefined ) { + +// Use the correct document accordingly with window argument (sandbox) +var document = window.document, + navigator = window.navigator, + location = window.location; +var jQuery = (function() { + +// Define a local copy of jQuery +var jQuery = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + return new jQuery.fn.init( selector, context, rootjQuery ); + }, + + // Map over jQuery in case of overwrite + _jQuery = window.jQuery, + + // Map over the $ in case of overwrite + _$ = window.$, + + // A central reference to the root jQuery(document) + rootjQuery, + + // A simple way to check for HTML strings or ID strings + // Prioritize #id over to avoid XSS via location.hash (#9521) + quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/, + + // Check if a string has a non-whitespace character in it + rnotwhite = /\S/, + + // Used for trimming whitespace + trimLeft = /^\s+/, + trimRight = /\s+$/, + + // Match a standalone tag + rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, + + // JSON RegExp + rvalidchars = /^[\],:{}\s]*$/, + rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, + rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, + rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g, + + // Useragent RegExp + rwebkit = /(webkit)[ \/]([\w.]+)/, + ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/, + rmsie = /(msie) ([\w.]+)/, + rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/, + + // Matches dashed string for camelizing + rdashAlpha = /-([a-z]|[0-9])/ig, + rmsPrefix = /^-ms-/, + + // Used by jQuery.camelCase as callback to replace() + fcamelCase = function( all, letter ) { + return ( letter + "" ).toUpperCase(); + }, + + // Keep a UserAgent string for use with jQuery.browser + userAgent = navigator.userAgent, + + // For matching the engine and version of the browser + browserMatch, + + // The deferred used on DOM ready + readyList, + + // The ready event handler + DOMContentLoaded, + + // Save a reference to some core methods + toString = Object.prototype.toString, + hasOwn = Object.prototype.hasOwnProperty, + push = Array.prototype.push, + slice = Array.prototype.slice, + trim = String.prototype.trim, + indexOf = Array.prototype.indexOf, + + // [[Class]] -> type pairs + class2type = {}; + +jQuery.fn = jQuery.prototype = { + constructor: jQuery, + init: function( selector, context, rootjQuery ) { + var match, elem, ret, doc; + + // Handle $(""), $(null), or $(undefined) + if ( !selector ) { + return this; + } + + // Handle $(DOMElement) + if ( selector.nodeType ) { + this.context = this[0] = selector; + this.length = 1; + return this; + } + + // The body element only exists once, optimize finding it + if ( selector === "body" && !context && document.body ) { + this.context = document; + this[0] = document.body; + this.selector = selector; + this.length = 1; + return this; + } + + // Handle HTML strings + if ( typeof selector === "string" ) { + // Are we dealing with HTML string or an ID? + if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { + // Assume that strings that start and end with <> are HTML and skip the regex check + match = [ null, selector, null ]; + + } else { + match = quickExpr.exec( selector ); + } + + // Verify a match, and that no context was specified for #id + if ( match && (match[1] || !context) ) { + + // HANDLE: $(html) -> $(array) + if ( match[1] ) { + context = context instanceof jQuery ? context[0] : context; + doc = ( context ? context.ownerDocument || context : document ); + + // If a single string is passed in and it's a single tag + // just do a createElement and skip the rest + ret = rsingleTag.exec( selector ); + + if ( ret ) { + if ( jQuery.isPlainObject( context ) ) { + selector = [ document.createElement( ret[1] ) ]; + jQuery.fn.attr.call( selector, context, true ); + + } else { + selector = [ doc.createElement( ret[1] ) ]; + } + + } else { + ret = jQuery.buildFragment( [ match[1] ], [ doc ] ); + selector = ( ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment ).childNodes; + } + + return jQuery.merge( this, selector ); + + // HANDLE: $("#id") + } else { + elem = document.getElementById( match[2] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id !== match[2] ) { + return rootjQuery.find( selector ); + } + + // Otherwise, we inject the element directly into the jQuery object + this.length = 1; + this[0] = elem; + } + + this.context = document; + this.selector = selector; + return this; + } + + // HANDLE: $(expr, $(...)) + } else if ( !context || context.jquery ) { + return ( context || rootjQuery ).find( selector ); + + // HANDLE: $(expr, context) + // (which is just equivalent to: $(context).find(expr) + } else { + return this.constructor( context ).find( selector ); + } + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction( selector ) ) { + return rootjQuery.ready( selector ); + } + + if ( selector.selector !== undefined ) { + this.selector = selector.selector; + this.context = selector.context; + } + + return jQuery.makeArray( selector, this ); + }, + + // Start with an empty selector + selector: "", + + // The current version of jQuery being used + jquery: "1.7.2", + + // The default length of a jQuery object is 0 + length: 0, + + // The number of elements contained in the matched element set + size: function() { + return this.length; + }, + + toArray: function() { + return slice.call( this, 0 ); + }, + + // Get the Nth element in the matched element set OR + // Get the whole matched element set as a clean array + get: function( num ) { + return num == null ? + + // Return a 'clean' array + this.toArray() : + + // Return just the object + ( num < 0 ? this[ this.length + num ] : this[ num ] ); + }, + + // Take an array of elements and push it onto the stack + // (returning the new matched element set) + pushStack: function( elems, name, selector ) { + // Build a new jQuery matched element set + var ret = this.constructor(); + + if ( jQuery.isArray( elems ) ) { + push.apply( ret, elems ); + + } else { + jQuery.merge( ret, elems ); + } + + // Add the old object onto the stack (as a reference) + ret.prevObject = this; + + ret.context = this.context; + + if ( name === "find" ) { + ret.selector = this.selector + ( this.selector ? " " : "" ) + selector; + } else if ( name ) { + ret.selector = this.selector + "." + name + "(" + selector + ")"; + } + + // Return the newly-formed element set + return ret; + }, + + // Execute a callback for every element in the matched set. + // (You can seed the arguments with an array of args, but this is + // only used internally.) + each: function( callback, args ) { + return jQuery.each( this, callback, args ); + }, + + ready: function( fn ) { + // Attach the listeners + jQuery.bindReady(); + + // Add the callback + readyList.add( fn ); + + return this; + }, + + eq: function( i ) { + i = +i; + return i === -1 ? + this.slice( i ) : + this.slice( i, i + 1 ); + }, + + first: function() { + return this.eq( 0 ); + }, + + last: function() { + return this.eq( -1 ); + }, + + slice: function() { + return this.pushStack( slice.apply( this, arguments ), + "slice", slice.call(arguments).join(",") ); + }, + + map: function( callback ) { + return this.pushStack( jQuery.map(this, function( elem, i ) { + return callback.call( elem, i, elem ); + })); + }, + + end: function() { + return this.prevObject || this.constructor(null); + }, + + // For internal use only. + // Behaves like an Array's method, not like a jQuery method. + push: push, + sort: [].sort, + splice: [].splice +}; + +// Give the init function the jQuery prototype for later instantiation +jQuery.fn.init.prototype = jQuery.fn; + +jQuery.extend = jQuery.fn.extend = function() { + var options, name, src, copy, copyIsArray, clone, + target = arguments[0] || {}, + i = 1, + length = arguments.length, + deep = false; + + // Handle a deep copy situation + if ( typeof target === "boolean" ) { + deep = target; + target = arguments[1] || {}; + // skip the boolean and the target + i = 2; + } + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + target = {}; + } + + // extend jQuery itself if only one argument is passed + if ( length === i ) { + target = this; + --i; + } + + for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) { + // Extend the base object + for ( name in options ) { + src = target[ name ]; + copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) { + continue; + } + + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + clone = src && jQuery.isArray(src) ? src : []; + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } + + // Never move original objects, clone them + target[ name ] = jQuery.extend( deep, clone, copy ); + + // Don't bring in undefined values + } else if ( copy !== undefined ) { + target[ name ] = copy; + } + } + } + } + + // Return the modified object + return target; +}; + +jQuery.extend({ + noConflict: function( deep ) { + if ( window.$ === jQuery ) { + window.$ = _$; + } + + if ( deep && window.jQuery === jQuery ) { + window.jQuery = _jQuery; + } + + return jQuery; + }, + + // Is the DOM ready to be used? Set to true once it occurs. + isReady: false, + + // A counter to track how many items to wait for before + // the ready event fires. See #6781 + readyWait: 1, + + // Hold (or release) the ready event + holdReady: function( hold ) { + if ( hold ) { + jQuery.readyWait++; + } else { + jQuery.ready( true ); + } + }, + + // Handle when the DOM is ready + ready: function( wait ) { + // Either a released hold or an DOMready/load event and not yet ready + if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) { + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( !document.body ) { + return setTimeout( jQuery.ready, 1 ); + } + + // Remember that the DOM is ready + jQuery.isReady = true; + + // If a normal DOM Ready event fired, decrement, and wait if need be + if ( wait !== true && --jQuery.readyWait > 0 ) { + return; + } + + // If there are functions bound, to execute + readyList.fireWith( document, [ jQuery ] ); + + // Trigger any bound ready events + if ( jQuery.fn.trigger ) { + jQuery( document ).trigger( "ready" ).off( "ready" ); + } + } + }, + + bindReady: function() { + if ( readyList ) { + return; + } + + readyList = jQuery.Callbacks( "once memory" ); + + // Catch cases where $(document).ready() is called after the + // browser event has already occurred. + if ( document.readyState === "complete" ) { + // Handle it asynchronously to allow scripts the opportunity to delay ready + return setTimeout( jQuery.ready, 1 ); + } + + // Mozilla, Opera and webkit nightlies currently support this event + if ( document.addEventListener ) { + // Use the handy event callback + document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + + // A fallback to window.onload, that will always work + window.addEventListener( "load", jQuery.ready, false ); + + // If IE event model is used + } else if ( document.attachEvent ) { + // ensure firing before onload, + // maybe late but safe also for iframes + document.attachEvent( "onreadystatechange", DOMContentLoaded ); + + // A fallback to window.onload, that will always work + window.attachEvent( "onload", jQuery.ready ); + + // If IE and not a frame + // continually check to see if the document is ready + var toplevel = false; + + try { + toplevel = window.frameElement == null; + } catch(e) {} + + if ( document.documentElement.doScroll && toplevel ) { + doScrollCheck(); + } + } + }, + + // See test/unit/core.js for details concerning isFunction. + // Since version 1.3, DOM methods and functions like alert + // aren't supported. They return false on IE (#2968). + isFunction: function( obj ) { + return jQuery.type(obj) === "function"; + }, + + isArray: Array.isArray || function( obj ) { + return jQuery.type(obj) === "array"; + }, + + isWindow: function( obj ) { + return obj != null && obj == obj.window; + }, + + isNumeric: function( obj ) { + return !isNaN( parseFloat(obj) ) && isFinite( obj ); + }, + + type: function( obj ) { + return obj == null ? + String( obj ) : + class2type[ toString.call(obj) ] || "object"; + }, + + isPlainObject: function( obj ) { + // Must be an Object. + // Because of IE, we also have to check the presence of the constructor property. + // Make sure that DOM nodes and window objects don't pass through, as well + if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { + return false; + } + + try { + // Not own constructor property must be Object + if ( obj.constructor && + !hasOwn.call(obj, "constructor") && + !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { + return false; + } + } catch ( e ) { + // IE8,9 Will throw exceptions on certain host objects #9897 + return false; + } + + // Own properties are enumerated firstly, so to speed up, + // if last one is own, then all properties are own. + + var key; + for ( key in obj ) {} + + return key === undefined || hasOwn.call( obj, key ); + }, + + isEmptyObject: function( obj ) { + for ( var name in obj ) { + return false; + } + return true; + }, + + error: function( msg ) { + throw new Error( msg ); + }, + + parseJSON: function( data ) { + if ( typeof data !== "string" || !data ) { + return null; + } + + // Make sure leading/trailing whitespace is removed (IE can't handle it) + data = jQuery.trim( data ); + + // Attempt to parse using the native JSON parser first + if ( window.JSON && window.JSON.parse ) { + return window.JSON.parse( data ); + } + + // Make sure the incoming data is actual JSON + // Logic borrowed from http://json.org/json2.js + if ( rvalidchars.test( data.replace( rvalidescape, "@" ) + .replace( rvalidtokens, "]" ) + .replace( rvalidbraces, "")) ) { + + return ( new Function( "return " + data ) )(); + + } + jQuery.error( "Invalid JSON: " + data ); + }, + + // Cross-browser xml parsing + parseXML: function( data ) { + if ( typeof data !== "string" || !data ) { + return null; + } + var xml, tmp; + try { + if ( window.DOMParser ) { // Standard + tmp = new DOMParser(); + xml = tmp.parseFromString( data , "text/xml" ); + } else { // IE + xml = new ActiveXObject( "Microsoft.XMLDOM" ); + xml.async = "false"; + xml.loadXML( data ); + } + } catch( e ) { + xml = undefined; + } + if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) { + jQuery.error( "Invalid XML: " + data ); + } + return xml; + }, + + noop: function() {}, + + // Evaluates a script in a global context + // Workarounds based on findings by Jim Driscoll + // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context + globalEval: function( data ) { + if ( data && rnotwhite.test( data ) ) { + // We use execScript on Internet Explorer + // We use an anonymous function so that context is window + // rather than jQuery in Firefox + ( window.execScript || function( data ) { + window[ "eval" ].call( window, data ); + } )( data ); + } + }, + + // Convert dashed to camelCase; used by the css and data modules + // Microsoft forgot to hump their vendor prefix (#9572) + camelCase: function( string ) { + return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase(); + }, + + // args is for internal usage only + each: function( object, callback, args ) { + var name, i = 0, + length = object.length, + isObj = length === undefined || jQuery.isFunction( object ); + + if ( args ) { + if ( isObj ) { + for ( name in object ) { + if ( callback.apply( object[ name ], args ) === false ) { + break; + } + } + } else { + for ( ; i < length; ) { + if ( callback.apply( object[ i++ ], args ) === false ) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if ( isObj ) { + for ( name in object ) { + if ( callback.call( object[ name ], name, object[ name ] ) === false ) { + break; + } + } + } else { + for ( ; i < length; ) { + if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { + break; + } + } + } + } + + return object; + }, + + // Use native String.trim function wherever possible + trim: trim ? + function( text ) { + return text == null ? + "" : + trim.call( text ); + } : + + // Otherwise use our own trimming functionality + function( text ) { + return text == null ? + "" : + text.toString().replace( trimLeft, "" ).replace( trimRight, "" ); + }, + + // results is for internal usage only + makeArray: function( array, results ) { + var ret = results || []; + + if ( array != null ) { + // The window, strings (and functions) also have 'length' + // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930 + var type = jQuery.type( array ); + + if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) { + push.call( ret, array ); + } else { + jQuery.merge( ret, array ); + } + } + + return ret; + }, + + inArray: function( elem, array, i ) { + var len; + + if ( array ) { + if ( indexOf ) { + return indexOf.call( array, elem, i ); + } + + len = array.length; + i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; + + for ( ; i < len; i++ ) { + // Skip accessing in sparse arrays + if ( i in array && array[ i ] === elem ) { + return i; + } + } + } + + return -1; + }, + + merge: function( first, second ) { + var i = first.length, + j = 0; + + if ( typeof second.length === "number" ) { + for ( var l = second.length; j < l; j++ ) { + first[ i++ ] = second[ j ]; + } + + } else { + while ( second[j] !== undefined ) { + first[ i++ ] = second[ j++ ]; + } + } + + first.length = i; + + return first; + }, + + grep: function( elems, callback, inv ) { + var ret = [], retVal; + inv = !!inv; + + // Go through the array, only saving the items + // that pass the validator function + for ( var i = 0, length = elems.length; i < length; i++ ) { + retVal = !!callback( elems[ i ], i ); + if ( inv !== retVal ) { + ret.push( elems[ i ] ); + } + } + + return ret; + }, + + // arg is for internal usage only + map: function( elems, callback, arg ) { + var value, key, ret = [], + i = 0, + length = elems.length, + // jquery objects are treated as arrays + isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ; + + // Go through the array, translating each of the items to their + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } + } + + // Go through every key on the object, + } else { + for ( key in elems ) { + value = callback( elems[ key ], key, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } + } + } + + // Flatten any nested arrays + return ret.concat.apply( [], ret ); + }, + + // A global GUID counter for objects + guid: 1, + + // Bind a function to a context, optionally partially applying any + // arguments. + proxy: function( fn, context ) { + if ( typeof context === "string" ) { + var tmp = fn[ context ]; + context = fn; + fn = tmp; + } + + // Quick check to determine if target is callable, in the spec + // this throws a TypeError, but we will just return undefined. + if ( !jQuery.isFunction( fn ) ) { + return undefined; + } + + // Simulated bind + var args = slice.call( arguments, 2 ), + proxy = function() { + return fn.apply( context, args.concat( slice.call( arguments ) ) ); + }; + + // Set the guid of unique handler to the same of original handler, so it can be removed + proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; + + return proxy; + }, + + // Mutifunctional method to get and set values to a collection + // The value/s can optionally be executed if it's a function + access: function( elems, fn, key, value, chainable, emptyGet, pass ) { + var exec, + bulk = key == null, + i = 0, + length = elems.length; + + // Sets many values + if ( key && typeof key === "object" ) { + for ( i in key ) { + jQuery.access( elems, fn, i, key[i], 1, emptyGet, value ); + } + chainable = 1; + + // Sets one value + } else if ( value !== undefined ) { + // Optionally, function values get executed if exec is true + exec = pass === undefined && jQuery.isFunction( value ); + + if ( bulk ) { + // Bulk operations only iterate when executing function values + if ( exec ) { + exec = fn; + fn = function( elem, key, value ) { + return exec.call( jQuery( elem ), value ); + }; + + // Otherwise they run against the entire set + } else { + fn.call( elems, value ); + fn = null; + } + } + + if ( fn ) { + for (; i < length; i++ ) { + fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); + } + } + + chainable = 1; + } + + return chainable ? + elems : + + // Gets + bulk ? + fn.call( elems ) : + length ? fn( elems[0], key ) : emptyGet; + }, + + now: function() { + return ( new Date() ).getTime(); + }, + + // Use of jQuery.browser is frowned upon. + // More details: http://docs.jquery.com/Utilities/jQuery.browser + uaMatch: function( ua ) { + ua = ua.toLowerCase(); + + var match = rwebkit.exec( ua ) || + ropera.exec( ua ) || + rmsie.exec( ua ) || + ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || + []; + + return { browser: match[1] || "", version: match[2] || "0" }; + }, + + sub: function() { + function jQuerySub( selector, context ) { + return new jQuerySub.fn.init( selector, context ); + } + jQuery.extend( true, jQuerySub, this ); + jQuerySub.superclass = this; + jQuerySub.fn = jQuerySub.prototype = this(); + jQuerySub.fn.constructor = jQuerySub; + jQuerySub.sub = this.sub; + jQuerySub.fn.init = function init( selector, context ) { + if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) { + context = jQuerySub( context ); + } + + return jQuery.fn.init.call( this, selector, context, rootjQuerySub ); + }; + jQuerySub.fn.init.prototype = jQuerySub.fn; + var rootjQuerySub = jQuerySub(document); + return jQuerySub; + }, + + browser: {} +}); + +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + +browserMatch = jQuery.uaMatch( userAgent ); +if ( browserMatch.browser ) { + jQuery.browser[ browserMatch.browser ] = true; + jQuery.browser.version = browserMatch.version; +} + +// Deprecated, use jQuery.browser.webkit instead +if ( jQuery.browser.webkit ) { + jQuery.browser.safari = true; +} + +// IE doesn't match non-breaking spaces with \s +if ( rnotwhite.test( "\xA0" ) ) { + trimLeft = /^[\s\xA0]+/; + trimRight = /[\s\xA0]+$/; +} + +// All jQuery objects should point back to these +rootjQuery = jQuery(document); + +// Cleanup functions for the document ready method +if ( document.addEventListener ) { + DOMContentLoaded = function() { + document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + jQuery.ready(); + }; + +} else if ( document.attachEvent ) { + DOMContentLoaded = function() { + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( document.readyState === "complete" ) { + document.detachEvent( "onreadystatechange", DOMContentLoaded ); + jQuery.ready(); + } + }; +} + +// The DOM ready check for Internet Explorer +function doScrollCheck() { + if ( jQuery.isReady ) { + return; + } + + try { + // If IE is used, use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + document.documentElement.doScroll("left"); + } catch(e) { + setTimeout( doScrollCheck, 1 ); + return; + } + + // and execute any waiting functions + jQuery.ready(); +} + +return jQuery; + +})(); + + +// String to Object flags format cache +var flagsCache = {}; + +// Convert String-formatted flags into Object-formatted ones and store in cache +function createFlags( flags ) { + var object = flagsCache[ flags ] = {}, + i, length; + flags = flags.split( /\s+/ ); + for ( i = 0, length = flags.length; i < length; i++ ) { + object[ flags[i] ] = true; + } + return object; +} + +/* + * Create a callback list using the following parameters: + * + * flags: an optional list of space-separated flags that will change how + * the callback list behaves + * + * By default a callback list will act like an event callback list and can be + * "fired" multiple times. + * + * Possible flags: + * + * once: will ensure the callback list can only be fired once (like a Deferred) + * + * memory: will keep track of previous values and will call any callback added + * after the list has been fired right away with the latest "memorized" + * values (like a Deferred) + * + * unique: will ensure a callback can only be added once (no duplicate in the list) + * + * stopOnFalse: interrupt callings when a callback returns false + * + */ +jQuery.Callbacks = function( flags ) { + + // Convert flags from String-formatted to Object-formatted + // (we check in cache first) + flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {}; + + var // Actual callback list + list = [], + // Stack of fire calls for repeatable lists + stack = [], + // Last fire value (for non-forgettable lists) + memory, + // Flag to know if list was already fired + fired, + // Flag to know if list is currently firing + firing, + // First callback to fire (used internally by add and fireWith) + firingStart, + // End of the loop when firing + firingLength, + // Index of currently firing callback (modified by remove if needed) + firingIndex, + // Add one or several callbacks to the list + add = function( args ) { + var i, + length, + elem, + type, + actual; + for ( i = 0, length = args.length; i < length; i++ ) { + elem = args[ i ]; + type = jQuery.type( elem ); + if ( type === "array" ) { + // Inspect recursively + add( elem ); + } else if ( type === "function" ) { + // Add if not in unique mode and callback is not in + if ( !flags.unique || !self.has( elem ) ) { + list.push( elem ); + } + } + } + }, + // Fire callbacks + fire = function( context, args ) { + args = args || []; + memory = !flags.memory || [ context, args ]; + fired = true; + firing = true; + firingIndex = firingStart || 0; + firingStart = 0; + firingLength = list.length; + for ( ; list && firingIndex < firingLength; firingIndex++ ) { + if ( list[ firingIndex ].apply( context, args ) === false && flags.stopOnFalse ) { + memory = true; // Mark as halted + break; + } + } + firing = false; + if ( list ) { + if ( !flags.once ) { + if ( stack && stack.length ) { + memory = stack.shift(); + self.fireWith( memory[ 0 ], memory[ 1 ] ); + } + } else if ( memory === true ) { + self.disable(); + } else { + list = []; + } + } + }, + // Actual Callbacks object + self = { + // Add a callback or a collection of callbacks to the list + add: function() { + if ( list ) { + var length = list.length; + add( arguments ); + // Do we need to add the callbacks to the + // current firing batch? + if ( firing ) { + firingLength = list.length; + // With memory, if we're not firing then + // we should call right away, unless previous + // firing was halted (stopOnFalse) + } else if ( memory && memory !== true ) { + firingStart = length; + fire( memory[ 0 ], memory[ 1 ] ); + } + } + return this; + }, + // Remove a callback from the list + remove: function() { + if ( list ) { + var args = arguments, + argIndex = 0, + argLength = args.length; + for ( ; argIndex < argLength ; argIndex++ ) { + for ( var i = 0; i < list.length; i++ ) { + if ( args[ argIndex ] === list[ i ] ) { + // Handle firingIndex and firingLength + if ( firing ) { + if ( i <= firingLength ) { + firingLength--; + if ( i <= firingIndex ) { + firingIndex--; + } + } + } + // Remove the element + list.splice( i--, 1 ); + // If we have some unicity property then + // we only need to do this once + if ( flags.unique ) { + break; + } + } + } + } + } + return this; + }, + // Control if a given callback is in the list + has: function( fn ) { + if ( list ) { + var i = 0, + length = list.length; + for ( ; i < length; i++ ) { + if ( fn === list[ i ] ) { + return true; + } + } + } + return false; + }, + // Remove all callbacks from the list + empty: function() { + list = []; + return this; + }, + // Have the list do nothing anymore + disable: function() { + list = stack = memory = undefined; + return this; + }, + // Is it disabled? + disabled: function() { + return !list; + }, + // Lock the list in its current state + lock: function() { + stack = undefined; + if ( !memory || memory === true ) { + self.disable(); + } + return this; + }, + // Is it locked? + locked: function() { + return !stack; + }, + // Call all callbacks with the given context and arguments + fireWith: function( context, args ) { + if ( stack ) { + if ( firing ) { + if ( !flags.once ) { + stack.push( [ context, args ] ); + } + } else if ( !( flags.once && memory ) ) { + fire( context, args ); + } + } + return this; + }, + // Call all the callbacks with the given arguments + fire: function() { + self.fireWith( this, arguments ); + return this; + }, + // To know if the callbacks have already been called at least once + fired: function() { + return !!fired; + } + }; + + return self; +}; + + + + +var // Static reference to slice + sliceDeferred = [].slice; + +jQuery.extend({ + + Deferred: function( func ) { + var doneList = jQuery.Callbacks( "once memory" ), + failList = jQuery.Callbacks( "once memory" ), + progressList = jQuery.Callbacks( "memory" ), + state = "pending", + lists = { + resolve: doneList, + reject: failList, + notify: progressList + }, + promise = { + done: doneList.add, + fail: failList.add, + progress: progressList.add, + + state: function() { + return state; + }, + + // Deprecated + isResolved: doneList.fired, + isRejected: failList.fired, + + then: function( doneCallbacks, failCallbacks, progressCallbacks ) { + deferred.done( doneCallbacks ).fail( failCallbacks ).progress( progressCallbacks ); + return this; + }, + always: function() { + deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments ); + return this; + }, + pipe: function( fnDone, fnFail, fnProgress ) { + return jQuery.Deferred(function( newDefer ) { + jQuery.each( { + done: [ fnDone, "resolve" ], + fail: [ fnFail, "reject" ], + progress: [ fnProgress, "notify" ] + }, function( handler, data ) { + var fn = data[ 0 ], + action = data[ 1 ], + returned; + if ( jQuery.isFunction( fn ) ) { + deferred[ handler ](function() { + returned = fn.apply( this, arguments ); + if ( returned && jQuery.isFunction( returned.promise ) ) { + returned.promise().then( newDefer.resolve, newDefer.reject, newDefer.notify ); + } else { + newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] ); + } + }); + } else { + deferred[ handler ]( newDefer[ action ] ); + } + }); + }).promise(); + }, + // Get a promise for this deferred + // If obj is provided, the promise aspect is added to the object + promise: function( obj ) { + if ( obj == null ) { + obj = promise; + } else { + for ( var key in promise ) { + obj[ key ] = promise[ key ]; + } + } + return obj; + } + }, + deferred = promise.promise({}), + key; + + for ( key in lists ) { + deferred[ key ] = lists[ key ].fire; + deferred[ key + "With" ] = lists[ key ].fireWith; + } + + // Handle state + deferred.done( function() { + state = "resolved"; + }, failList.disable, progressList.lock ).fail( function() { + state = "rejected"; + }, doneList.disable, progressList.lock ); + + // Call given func if any + if ( func ) { + func.call( deferred, deferred ); + } + + // All done! + return deferred; + }, + + // Deferred helper + when: function( firstParam ) { + var args = sliceDeferred.call( arguments, 0 ), + i = 0, + length = args.length, + pValues = new Array( length ), + count = length, + pCount = length, + deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ? + firstParam : + jQuery.Deferred(), + promise = deferred.promise(); + function resolveFunc( i ) { + return function( value ) { + args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value; + if ( !( --count ) ) { + deferred.resolveWith( deferred, args ); + } + }; + } + function progressFunc( i ) { + return function( value ) { + pValues[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value; + deferred.notifyWith( promise, pValues ); + }; + } + if ( length > 1 ) { + for ( ; i < length; i++ ) { + if ( args[ i ] && args[ i ].promise && jQuery.isFunction( args[ i ].promise ) ) { + args[ i ].promise().then( resolveFunc(i), deferred.reject, progressFunc(i) ); + } else { + --count; + } + } + if ( !count ) { + deferred.resolveWith( deferred, args ); + } + } else if ( deferred !== firstParam ) { + deferred.resolveWith( deferred, length ? [ firstParam ] : [] ); + } + return promise; + } +}); + + + + +jQuery.support = (function() { + + var support, + all, + a, + select, + opt, + input, + fragment, + tds, + events, + eventName, + i, + isSupported, + div = document.createElement( "div" ), + documentElement = document.documentElement; + + // Preliminary tests + div.setAttribute("className", "t"); + div.innerHTML = "
a"; + + all = div.getElementsByTagName( "*" ); + a = div.getElementsByTagName( "a" )[ 0 ]; + + // Can't get basic test support + if ( !all || !all.length || !a ) { + return {}; + } + + // First batch of supports tests + select = document.createElement( "select" ); + opt = select.appendChild( document.createElement("option") ); + input = div.getElementsByTagName( "input" )[ 0 ]; + + support = { + // IE strips leading whitespace when .innerHTML is used + leadingWhitespace: ( div.firstChild.nodeType === 3 ), + + // Make sure that tbody elements aren't automatically inserted + // IE will insert them into empty tables + tbody: !div.getElementsByTagName("tbody").length, + + // Make sure that link elements get serialized correctly by innerHTML + // This requires a wrapper element in IE + htmlSerialize: !!div.getElementsByTagName("link").length, + + // Get the style information from getAttribute + // (IE uses .cssText instead) + style: /top/.test( a.getAttribute("style") ), + + // Make sure that URLs aren't manipulated + // (IE normalizes it by default) + hrefNormalized: ( a.getAttribute("href") === "/a" ), + + // Make sure that element opacity exists + // (IE uses filter instead) + // Use a regex to work around a WebKit issue. See #5145 + opacity: /^0.55/.test( a.style.opacity ), + + // Verify style float existence + // (IE uses styleFloat instead of cssFloat) + cssFloat: !!a.style.cssFloat, + + // Make sure that if no value is specified for a checkbox + // that it defaults to "on". + // (WebKit defaults to "" instead) + checkOn: ( input.value === "on" ), + + // Make sure that a selected-by-default option has a working selected property. + // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) + optSelected: opt.selected, + + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) + getSetAttribute: div.className !== "t", + + // Tests for enctype support on a form(#6743) + enctype: !!document.createElement("form").enctype, + + // Makes sure cloning an html5 element does not cause problems + // Where outerHTML is undefined, this still works + html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav>", + + // Will be defined later + submitBubbles: true, + changeBubbles: true, + focusinBubbles: false, + deleteExpando: true, + noCloneEvent: true, + inlineBlockNeedsLayout: false, + shrinkWrapBlocks: false, + reliableMarginRight: true, + pixelMargin: true + }; + + // jQuery.boxModel DEPRECATED in 1.3, use jQuery.support.boxModel instead + jQuery.boxModel = support.boxModel = (document.compatMode === "CSS1Compat"); + + // Make sure checked status is properly cloned + input.checked = true; + support.noCloneChecked = input.cloneNode( true ).checked; + + // Make sure that the options inside disabled selects aren't marked as disabled + // (WebKit marks them as disabled) + select.disabled = true; + support.optDisabled = !opt.disabled; + + // Test to see if it's possible to delete an expando from an element + // Fails in Internet Explorer + try { + delete div.test; + } catch( e ) { + support.deleteExpando = false; + } + + if ( !div.addEventListener && div.attachEvent && div.fireEvent ) { + div.attachEvent( "onclick", function() { + // Cloning a node shouldn't copy over any + // bound event handlers (IE does this) + support.noCloneEvent = false; + }); + div.cloneNode( true ).fireEvent( "onclick" ); + } + + // Check if a radio maintains its value + // after being appended to the DOM + input = document.createElement("input"); + input.value = "t"; + input.setAttribute("type", "radio"); + support.radioValue = input.value === "t"; + + input.setAttribute("checked", "checked"); + + // #11217 - WebKit loses check when the name is after the checked attribute + input.setAttribute( "name", "t" ); + + div.appendChild( input ); + fragment = document.createDocumentFragment(); + fragment.appendChild( div.lastChild ); + + // WebKit doesn't clone checked state correctly in fragments + support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked; + + // Check if a disconnected checkbox will retain its checked + // value of true after appended to the DOM (IE6/7) + support.appendChecked = input.checked; + + fragment.removeChild( input ); + fragment.appendChild( div ); + + // Technique from Juriy Zaytsev + // http://perfectionkills.com/detecting-event-support-without-browser-sniffing/ + // We only care about the case where non-standard event systems + // are used, namely in IE. Short-circuiting here helps us to + // avoid an eval call (in setAttribute) which can cause CSP + // to go haywire. See: https://developer.mozilla.org/en/Security/CSP + if ( div.attachEvent ) { + for ( i in { + submit: 1, + change: 1, + focusin: 1 + }) { + eventName = "on" + i; + isSupported = ( eventName in div ); + if ( !isSupported ) { + div.setAttribute( eventName, "return;" ); + isSupported = ( typeof div[ eventName ] === "function" ); + } + support[ i + "Bubbles" ] = isSupported; + } + } + + fragment.removeChild( div ); + + // Null elements to avoid leaks in IE + fragment = select = opt = div = input = null; + + // Run tests that need a body at doc ready + jQuery(function() { + var container, outer, inner, table, td, offsetSupport, + marginDiv, conMarginTop, style, html, positionTopLeftWidthHeight, + paddingMarginBorderVisibility, paddingMarginBorder, + body = document.getElementsByTagName("body")[0]; + + if ( !body ) { + // Return for frameset docs that don't have a body + return; + } + + conMarginTop = 1; + paddingMarginBorder = "padding:0;margin:0;border:"; + positionTopLeftWidthHeight = "position:absolute;top:0;left:0;width:1px;height:1px;"; + paddingMarginBorderVisibility = paddingMarginBorder + "0;visibility:hidden;"; + style = "style='" + positionTopLeftWidthHeight + paddingMarginBorder + "5px solid #000;"; + html = "
" + + "" + + "
"; + + container = document.createElement("div"); + container.style.cssText = paddingMarginBorderVisibility + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px"; + body.insertBefore( container, body.firstChild ); + + // Construct the test element + div = document.createElement("div"); + container.appendChild( div ); + + // Check if table cells still have offsetWidth/Height when they are set + // to display:none and there are still other visible table cells in a + // table row; if so, offsetWidth/Height are not reliable for use when + // determining if an element has been hidden directly using + // display:none (it is still safe to use offsets if a parent element is + // hidden; don safety goggles and see bug #4512 for more information). + // (only IE 8 fails this test) + div.innerHTML = "
t
"; + tds = div.getElementsByTagName( "td" ); + isSupported = ( tds[ 0 ].offsetHeight === 0 ); + + tds[ 0 ].style.display = ""; + tds[ 1 ].style.display = "none"; + + // Check if empty table cells still have offsetWidth/Height + // (IE <= 8 fail this test) + support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 ); + + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. For more + // info see bug #3333 + // Fails in WebKit before Feb 2011 nightlies + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + if ( window.getComputedStyle ) { + div.innerHTML = ""; + marginDiv = document.createElement( "div" ); + marginDiv.style.width = "0"; + marginDiv.style.marginRight = "0"; + div.style.width = "2px"; + div.appendChild( marginDiv ); + support.reliableMarginRight = + ( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; + } + + if ( typeof div.style.zoom !== "undefined" ) { + // Check if natively block-level elements act like inline-block + // elements when setting their display to 'inline' and giving + // them layout + // (IE < 8 does this) + div.innerHTML = ""; + div.style.width = div.style.padding = "1px"; + div.style.border = 0; + div.style.overflow = "hidden"; + div.style.display = "inline"; + div.style.zoom = 1; + support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 ); + + // Check if elements with layout shrink-wrap their children + // (IE 6 does this) + div.style.display = "block"; + div.style.overflow = "visible"; + div.innerHTML = "
"; + support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); + } + + div.style.cssText = positionTopLeftWidthHeight + paddingMarginBorderVisibility; + div.innerHTML = html; + + outer = div.firstChild; + inner = outer.firstChild; + td = outer.nextSibling.firstChild.firstChild; + + offsetSupport = { + doesNotAddBorder: ( inner.offsetTop !== 5 ), + doesAddBorderForTableAndCells: ( td.offsetTop === 5 ) + }; + + inner.style.position = "fixed"; + inner.style.top = "20px"; + + // safari subtracts parent border width here which is 5px + offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 ); + inner.style.position = inner.style.top = ""; + + outer.style.overflow = "hidden"; + outer.style.position = "relative"; + + offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 ); + offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== conMarginTop ); + + if ( window.getComputedStyle ) { + div.style.marginTop = "1%"; + support.pixelMargin = ( window.getComputedStyle( div, null ) || { marginTop: 0 } ).marginTop !== "1%"; + } + + if ( typeof container.style.zoom !== "undefined" ) { + container.style.zoom = 1; + } + + body.removeChild( container ); + marginDiv = div = container = null; + + jQuery.extend( support, offsetSupport ); + }); + + return support; +})(); + + + + +var rbrace = /^(?:\{.*\}|\[.*\])$/, + rmultiDash = /([A-Z])/g; + +jQuery.extend({ + cache: {}, + + // Please use with caution + uuid: 0, + + // Unique for each copy of jQuery on the page + // Non-digits removed to match rinlinejQuery + expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ), + + // The following elements throw uncatchable exceptions if you + // attempt to add expando properties to them. + noData: { + "embed": true, + // Ban all objects except for Flash (which handle expandos) + "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000", + "applet": true + }, + + hasData: function( elem ) { + elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; + return !!elem && !isEmptyDataObject( elem ); + }, + + data: function( elem, name, data, pvt /* Internal Use Only */ ) { + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var privateCache, thisCache, ret, + internalKey = jQuery.expando, + getByName = typeof name === "string", + + // We have to handle DOM nodes and JS objects differently because IE6-7 + // can't GC object references properly across the DOM-JS boundary + isNode = elem.nodeType, + + // Only DOM nodes need the global jQuery cache; JS object data is + // attached directly to the object so GC can occur automatically + cache = isNode ? jQuery.cache : elem, + + // Only defining an ID for JS objects if its cache already exists allows + // the code to shortcut on the same path as a DOM node with no cache + id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey, + isEvents = name === "events"; + + // Avoid doing any more work than we need to when trying to get data on an + // object that has no data at all + if ( (!id || !cache[id] || (!isEvents && !pvt && !cache[id].data)) && getByName && data === undefined ) { + return; + } + + if ( !id ) { + // Only DOM nodes need a new unique ID for each element since their data + // ends up in the global cache + if ( isNode ) { + elem[ internalKey ] = id = ++jQuery.uuid; + } else { + id = internalKey; + } + } + + if ( !cache[ id ] ) { + cache[ id ] = {}; + + // Avoids exposing jQuery metadata on plain JS objects when the object + // is serialized using JSON.stringify + if ( !isNode ) { + cache[ id ].toJSON = jQuery.noop; + } + } + + // An object can be passed to jQuery.data instead of a key/value pair; this gets + // shallow copied over onto the existing cache + if ( typeof name === "object" || typeof name === "function" ) { + if ( pvt ) { + cache[ id ] = jQuery.extend( cache[ id ], name ); + } else { + cache[ id ].data = jQuery.extend( cache[ id ].data, name ); + } + } + + privateCache = thisCache = cache[ id ]; + + // jQuery data() is stored in a separate object inside the object's internal data + // cache in order to avoid key collisions between internal data and user-defined + // data. + if ( !pvt ) { + if ( !thisCache.data ) { + thisCache.data = {}; + } + + thisCache = thisCache.data; + } + + if ( data !== undefined ) { + thisCache[ jQuery.camelCase( name ) ] = data; + } + + // Users should not attempt to inspect the internal events object using jQuery.data, + // it is undocumented and subject to change. But does anyone listen? No. + if ( isEvents && !thisCache[ name ] ) { + return privateCache.events; + } + + // Check for both converted-to-camel and non-converted data property names + // If a data property was specified + if ( getByName ) { + + // First Try to find as-is property data + ret = thisCache[ name ]; + + // Test for null|undefined property data + if ( ret == null ) { + + // Try to find the camelCased property + ret = thisCache[ jQuery.camelCase( name ) ]; + } + } else { + ret = thisCache; + } + + return ret; + }, + + removeData: function( elem, name, pvt /* Internal Use Only */ ) { + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var thisCache, i, l, + + // Reference to internal data cache key + internalKey = jQuery.expando, + + isNode = elem.nodeType, + + // See jQuery.data for more information + cache = isNode ? jQuery.cache : elem, + + // See jQuery.data for more information + id = isNode ? elem[ internalKey ] : internalKey; + + // If there is already no cache entry for this object, there is no + // purpose in continuing + if ( !cache[ id ] ) { + return; + } + + if ( name ) { + + thisCache = pvt ? cache[ id ] : cache[ id ].data; + + if ( thisCache ) { + + // Support array or space separated string names for data keys + if ( !jQuery.isArray( name ) ) { + + // try the string as a key before any manipulation + if ( name in thisCache ) { + name = [ name ]; + } else { + + // split the camel cased version by spaces unless a key with the spaces exists + name = jQuery.camelCase( name ); + if ( name in thisCache ) { + name = [ name ]; + } else { + name = name.split( " " ); + } + } + } + + for ( i = 0, l = name.length; i < l; i++ ) { + delete thisCache[ name[i] ]; + } + + // If there is no data left in the cache, we want to continue + // and let the cache object itself get destroyed + if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) { + return; + } + } + } + + // See jQuery.data for more information + if ( !pvt ) { + delete cache[ id ].data; + + // Don't destroy the parent cache unless the internal data object + // had been the only thing left in it + if ( !isEmptyDataObject(cache[ id ]) ) { + return; + } + } + + // Browsers that fail expando deletion also refuse to delete expandos on + // the window, but it will allow it on all other JS objects; other browsers + // don't care + // Ensure that `cache` is not a window object #10080 + if ( jQuery.support.deleteExpando || !cache.setInterval ) { + delete cache[ id ]; + } else { + cache[ id ] = null; + } + + // We destroyed the cache and need to eliminate the expando on the node to avoid + // false lookups in the cache for entries that no longer exist + if ( isNode ) { + // IE does not allow us to delete expando properties from nodes, + // nor does it have a removeAttribute function on Document nodes; + // we must handle all of these cases + if ( jQuery.support.deleteExpando ) { + delete elem[ internalKey ]; + } else if ( elem.removeAttribute ) { + elem.removeAttribute( internalKey ); + } else { + elem[ internalKey ] = null; + } + } + }, + + // For internal use only. + _data: function( elem, name, data ) { + return jQuery.data( elem, name, data, true ); + }, + + // A method for determining if a DOM node can handle the data expando + acceptData: function( elem ) { + if ( elem.nodeName ) { + var match = jQuery.noData[ elem.nodeName.toLowerCase() ]; + + if ( match ) { + return !(match === true || elem.getAttribute("classid") !== match); + } + } + + return true; + } +}); + +jQuery.fn.extend({ + data: function( key, value ) { + var parts, part, attr, name, l, + elem = this[0], + i = 0, + data = null; + + // Gets all values + if ( key === undefined ) { + if ( this.length ) { + data = jQuery.data( elem ); + + if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) { + attr = elem.attributes; + for ( l = attr.length; i < l; i++ ) { + name = attr[i].name; + + if ( name.indexOf( "data-" ) === 0 ) { + name = jQuery.camelCase( name.substring(5) ); + + dataAttr( elem, name, data[ name ] ); + } + } + jQuery._data( elem, "parsedAttrs", true ); + } + } + + return data; + } + + // Sets multiple values + if ( typeof key === "object" ) { + return this.each(function() { + jQuery.data( this, key ); + }); + } + + parts = key.split( ".", 2 ); + parts[1] = parts[1] ? "." + parts[1] : ""; + part = parts[1] + "!"; + + return jQuery.access( this, function( value ) { + + if ( value === undefined ) { + data = this.triggerHandler( "getData" + part, [ parts[0] ] ); + + // Try to fetch any internally stored data first + if ( data === undefined && elem ) { + data = jQuery.data( elem, key ); + data = dataAttr( elem, key, data ); + } + + return data === undefined && parts[1] ? + this.data( parts[0] ) : + data; + } + + parts[1] = value; + this.each(function() { + var self = jQuery( this ); + + self.triggerHandler( "setData" + part, parts ); + jQuery.data( this, key, value ); + self.triggerHandler( "changeData" + part, parts ); + }); + }, null, value, arguments.length > 1, null, false ); + }, + + removeData: function( key ) { + return this.each(function() { + jQuery.removeData( this, key ); + }); + } +}); + +function dataAttr( elem, key, data ) { + // If nothing was found internally, try to fetch any + // data from the HTML5 data-* attribute + if ( data === undefined && elem.nodeType === 1 ) { + + var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); + + data = elem.getAttribute( name ); + + if ( typeof data === "string" ) { + try { + data = data === "true" ? true : + data === "false" ? false : + data === "null" ? null : + jQuery.isNumeric( data ) ? +data : + rbrace.test( data ) ? jQuery.parseJSON( data ) : + data; + } catch( e ) {} + + // Make sure we set the data so it isn't changed later + jQuery.data( elem, key, data ); + + } else { + data = undefined; + } + } + + return data; +} + +// checks a cache object for emptiness +function isEmptyDataObject( obj ) { + for ( var name in obj ) { + + // if the public data object is empty, the private is still empty + if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) { + continue; + } + if ( name !== "toJSON" ) { + return false; + } + } + + return true; +} + + + + +function handleQueueMarkDefer( elem, type, src ) { + var deferDataKey = type + "defer", + queueDataKey = type + "queue", + markDataKey = type + "mark", + defer = jQuery._data( elem, deferDataKey ); + if ( defer && + ( src === "queue" || !jQuery._data(elem, queueDataKey) ) && + ( src === "mark" || !jQuery._data(elem, markDataKey) ) ) { + // Give room for hard-coded callbacks to fire first + // and eventually mark/queue something else on the element + setTimeout( function() { + if ( !jQuery._data( elem, queueDataKey ) && + !jQuery._data( elem, markDataKey ) ) { + jQuery.removeData( elem, deferDataKey, true ); + defer.fire(); + } + }, 0 ); + } +} + +jQuery.extend({ + + _mark: function( elem, type ) { + if ( elem ) { + type = ( type || "fx" ) + "mark"; + jQuery._data( elem, type, (jQuery._data( elem, type ) || 0) + 1 ); + } + }, + + _unmark: function( force, elem, type ) { + if ( force !== true ) { + type = elem; + elem = force; + force = false; + } + if ( elem ) { + type = type || "fx"; + var key = type + "mark", + count = force ? 0 : ( (jQuery._data( elem, key ) || 1) - 1 ); + if ( count ) { + jQuery._data( elem, key, count ); + } else { + jQuery.removeData( elem, key, true ); + handleQueueMarkDefer( elem, type, "mark" ); + } + } + }, + + queue: function( elem, type, data ) { + var q; + if ( elem ) { + type = ( type || "fx" ) + "queue"; + q = jQuery._data( elem, type ); + + // Speed up dequeue by getting out quickly if this is just a lookup + if ( data ) { + if ( !q || jQuery.isArray(data) ) { + q = jQuery._data( elem, type, jQuery.makeArray(data) ); + } else { + q.push( data ); + } + } + return q || []; + } + }, + + dequeue: function( elem, type ) { + type = type || "fx"; + + var queue = jQuery.queue( elem, type ), + fn = queue.shift(), + hooks = {}; + + // If the fx queue is dequeued, always remove the progress sentinel + if ( fn === "inprogress" ) { + fn = queue.shift(); + } + + if ( fn ) { + // Add a progress sentinel to prevent the fx queue from being + // automatically dequeued + if ( type === "fx" ) { + queue.unshift( "inprogress" ); + } + + jQuery._data( elem, type + ".run", hooks ); + fn.call( elem, function() { + jQuery.dequeue( elem, type ); + }, hooks ); + } + + if ( !queue.length ) { + jQuery.removeData( elem, type + "queue " + type + ".run", true ); + handleQueueMarkDefer( elem, type, "queue" ); + } + } +}); + +jQuery.fn.extend({ + queue: function( type, data ) { + var setter = 2; + + if ( typeof type !== "string" ) { + data = type; + type = "fx"; + setter--; + } + + if ( arguments.length < setter ) { + return jQuery.queue( this[0], type ); + } + + return data === undefined ? + this : + this.each(function() { + var queue = jQuery.queue( this, type, data ); + + if ( type === "fx" && queue[0] !== "inprogress" ) { + jQuery.dequeue( this, type ); + } + }); + }, + dequeue: function( type ) { + return this.each(function() { + jQuery.dequeue( this, type ); + }); + }, + // Based off of the plugin by Clint Helfers, with permission. + // http://blindsignals.com/index.php/2009/07/jquery-delay/ + delay: function( time, type ) { + time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time; + type = type || "fx"; + + return this.queue( type, function( next, hooks ) { + var timeout = setTimeout( next, time ); + hooks.stop = function() { + clearTimeout( timeout ); + }; + }); + }, + clearQueue: function( type ) { + return this.queue( type || "fx", [] ); + }, + // Get a promise resolved when queues of a certain type + // are emptied (fx is the type by default) + promise: function( type, object ) { + if ( typeof type !== "string" ) { + object = type; + type = undefined; + } + type = type || "fx"; + var defer = jQuery.Deferred(), + elements = this, + i = elements.length, + count = 1, + deferDataKey = type + "defer", + queueDataKey = type + "queue", + markDataKey = type + "mark", + tmp; + function resolve() { + if ( !( --count ) ) { + defer.resolveWith( elements, [ elements ] ); + } + } + while( i-- ) { + if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) || + ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) || + jQuery.data( elements[ i ], markDataKey, undefined, true ) ) && + jQuery.data( elements[ i ], deferDataKey, jQuery.Callbacks( "once memory" ), true ) )) { + count++; + tmp.add( resolve ); + } + } + resolve(); + return defer.promise( object ); + } +}); + + + + +var rclass = /[\n\t\r]/g, + rspace = /\s+/, + rreturn = /\r/g, + rtype = /^(?:button|input)$/i, + rfocusable = /^(?:button|input|object|select|textarea)$/i, + rclickable = /^a(?:rea)?$/i, + rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i, + getSetAttribute = jQuery.support.getSetAttribute, + nodeHook, boolHook, fixSpecified; + +jQuery.fn.extend({ + attr: function( name, value ) { + return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 ); + }, + + removeAttr: function( name ) { + return this.each(function() { + jQuery.removeAttr( this, name ); + }); + }, + + prop: function( name, value ) { + return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 ); + }, + + removeProp: function( name ) { + name = jQuery.propFix[ name ] || name; + return this.each(function() { + // try/catch handles cases where IE balks (such as removing a property on window) + try { + this[ name ] = undefined; + delete this[ name ]; + } catch( e ) {} + }); + }, + + addClass: function( value ) { + var classNames, i, l, elem, + setClass, c, cl; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + jQuery( this ).addClass( value.call(this, j, this.className) ); + }); + } + + if ( value && typeof value === "string" ) { + classNames = value.split( rspace ); + + for ( i = 0, l = this.length; i < l; i++ ) { + elem = this[ i ]; + + if ( elem.nodeType === 1 ) { + if ( !elem.className && classNames.length === 1 ) { + elem.className = value; + + } else { + setClass = " " + elem.className + " "; + + for ( c = 0, cl = classNames.length; c < cl; c++ ) { + if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) { + setClass += classNames[ c ] + " "; + } + } + elem.className = jQuery.trim( setClass ); + } + } + } + } + + return this; + }, + + removeClass: function( value ) { + var classNames, i, l, elem, className, c, cl; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( j ) { + jQuery( this ).removeClass( value.call(this, j, this.className) ); + }); + } + + if ( (value && typeof value === "string") || value === undefined ) { + classNames = ( value || "" ).split( rspace ); + + for ( i = 0, l = this.length; i < l; i++ ) { + elem = this[ i ]; + + if ( elem.nodeType === 1 && elem.className ) { + if ( value ) { + className = (" " + elem.className + " ").replace( rclass, " " ); + for ( c = 0, cl = classNames.length; c < cl; c++ ) { + className = className.replace(" " + classNames[ c ] + " ", " "); + } + elem.className = jQuery.trim( className ); + + } else { + elem.className = ""; + } + } + } + } + + return this; + }, + + toggleClass: function( value, stateVal ) { + var type = typeof value, + isBool = typeof stateVal === "boolean"; + + if ( jQuery.isFunction( value ) ) { + return this.each(function( i ) { + jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal ); + }); + } + + return this.each(function() { + if ( type === "string" ) { + // toggle individual class names + var className, + i = 0, + self = jQuery( this ), + state = stateVal, + classNames = value.split( rspace ); + + while ( (className = classNames[ i++ ]) ) { + // check each className given, space seperated list + state = isBool ? state : !self.hasClass( className ); + self[ state ? "addClass" : "removeClass" ]( className ); + } + + } else if ( type === "undefined" || type === "boolean" ) { + if ( this.className ) { + // store className if set + jQuery._data( this, "__className__", this.className ); + } + + // toggle whole className + this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || ""; + } + }); + }, + + hasClass: function( selector ) { + var className = " " + selector + " ", + i = 0, + l = this.length; + for ( ; i < l; i++ ) { + if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) { + return true; + } + } + + return false; + }, + + val: function( value ) { + var hooks, ret, isFunction, + elem = this[0]; + + if ( !arguments.length ) { + if ( elem ) { + hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ]; + + if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) { + return ret; + } + + ret = elem.value; + + return typeof ret === "string" ? + // handle most common string cases + ret.replace(rreturn, "") : + // handle cases where value is null/undef or number + ret == null ? "" : ret; + } + + return; + } + + isFunction = jQuery.isFunction( value ); + + return this.each(function( i ) { + var self = jQuery(this), val; + + if ( this.nodeType !== 1 ) { + return; + } + + if ( isFunction ) { + val = value.call( this, i, self.val() ); + } else { + val = value; + } + + // Treat null/undefined as ""; convert numbers to string + if ( val == null ) { + val = ""; + } else if ( typeof val === "number" ) { + val += ""; + } else if ( jQuery.isArray( val ) ) { + val = jQuery.map(val, function ( value ) { + return value == null ? "" : value + ""; + }); + } + + hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; + + // If set returns undefined, fall back to normal setting + if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { + this.value = val; + } + }); + } +}); + +jQuery.extend({ + valHooks: { + option: { + get: function( elem ) { + // attributes.value is undefined in Blackberry 4.7 but + // uses .value. See #6932 + var val = elem.attributes.value; + return !val || val.specified ? elem.value : elem.text; + } + }, + select: { + get: function( elem ) { + var value, i, max, option, + index = elem.selectedIndex, + values = [], + options = elem.options, + one = elem.type === "select-one"; + + // Nothing was selected + if ( index < 0 ) { + return null; + } + + // Loop through all the selected options + i = one ? index : 0; + max = one ? index + 1 : options.length; + for ( ; i < max; i++ ) { + option = options[ i ]; + + // Don't return options that are disabled or in a disabled optgroup + if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) && + (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) { + + // Get the specific value for the option + value = jQuery( option ).val(); + + // We don't need an array for one selects + if ( one ) { + return value; + } + + // Multi-Selects return an array + values.push( value ); + } + } + + // Fixes Bug #2551 -- select.val() broken in IE after form.reset() + if ( one && !values.length && options.length ) { + return jQuery( options[ index ] ).val(); + } + + return values; + }, + + set: function( elem, value ) { + var values = jQuery.makeArray( value ); + + jQuery(elem).find("option").each(function() { + this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; + }); + + if ( !values.length ) { + elem.selectedIndex = -1; + } + return values; + } + } + }, + + attrFn: { + val: true, + css: true, + html: true, + text: true, + data: true, + width: true, + height: true, + offset: true + }, + + attr: function( elem, name, value, pass ) { + var ret, hooks, notxml, + nType = elem.nodeType; + + // don't get/set attributes on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return; + } + + if ( pass && name in jQuery.attrFn ) { + return jQuery( elem )[ name ]( value ); + } + + // Fallback to prop when attributes are not supported + if ( typeof elem.getAttribute === "undefined" ) { + return jQuery.prop( elem, name, value ); + } + + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + // All attributes are lowercase + // Grab necessary hook if one is defined + if ( notxml ) { + name = name.toLowerCase(); + hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook ); + } + + if ( value !== undefined ) { + + if ( value === null ) { + jQuery.removeAttr( elem, name ); + return; + + } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) { + return ret; + + } else { + elem.setAttribute( name, "" + value ); + return value; + } + + } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) { + return ret; + + } else { + + ret = elem.getAttribute( name ); + + // Non-existent attributes return null, we normalize to undefined + return ret === null ? + undefined : + ret; + } + }, + + removeAttr: function( elem, value ) { + var propName, attrNames, name, l, isBool, + i = 0; + + if ( value && elem.nodeType === 1 ) { + attrNames = value.toLowerCase().split( rspace ); + l = attrNames.length; + + for ( ; i < l; i++ ) { + name = attrNames[ i ]; + + if ( name ) { + propName = jQuery.propFix[ name ] || name; + isBool = rboolean.test( name ); + + // See #9699 for explanation of this approach (setting first, then removal) + // Do not do this for boolean attributes (see #10870) + if ( !isBool ) { + jQuery.attr( elem, name, "" ); + } + elem.removeAttribute( getSetAttribute ? name : propName ); + + // Set corresponding property to false for boolean attributes + if ( isBool && propName in elem ) { + elem[ propName ] = false; + } + } + } + } + }, + + attrHooks: { + type: { + set: function( elem, value ) { + // We can't allow the type property to be changed (since it causes problems in IE) + if ( rtype.test( elem.nodeName ) && elem.parentNode ) { + jQuery.error( "type property can't be changed" ); + } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { + // Setting the type on a radio button after the value resets the value in IE6-9 + // Reset value to it's default in case type is set after value + // This is for element creation + var val = elem.value; + elem.setAttribute( "type", value ); + if ( val ) { + elem.value = val; + } + return value; + } + } + }, + // Use the value property for back compat + // Use the nodeHook for button elements in IE6/7 (#1954) + value: { + get: function( elem, name ) { + if ( nodeHook && jQuery.nodeName( elem, "button" ) ) { + return nodeHook.get( elem, name ); + } + return name in elem ? + elem.value : + null; + }, + set: function( elem, value, name ) { + if ( nodeHook && jQuery.nodeName( elem, "button" ) ) { + return nodeHook.set( elem, value, name ); + } + // Does not return so that setAttribute is also used + elem.value = value; + } + } + }, + + propFix: { + tabindex: "tabIndex", + readonly: "readOnly", + "for": "htmlFor", + "class": "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + cellpadding: "cellPadding", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder", + contenteditable: "contentEditable" + }, + + prop: function( elem, name, value ) { + var ret, hooks, notxml, + nType = elem.nodeType; + + // don't get/set properties on text, comment and attribute nodes + if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { + return; + } + + notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); + + if ( notxml ) { + // Fix name and attach hooks + name = jQuery.propFix[ name ] || name; + hooks = jQuery.propHooks[ name ]; + } + + if ( value !== undefined ) { + if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + return ret; + + } else { + return ( elem[ name ] = value ); + } + + } else { + if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + return ret; + + } else { + return elem[ name ]; + } + } + }, + + propHooks: { + tabIndex: { + get: function( elem ) { + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set + // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ + var attributeNode = elem.getAttributeNode("tabindex"); + + return attributeNode && attributeNode.specified ? + parseInt( attributeNode.value, 10 ) : + rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? + 0 : + undefined; + } + } + } +}); + +// Add the tabIndex propHook to attrHooks for back-compat (different case is intentional) +jQuery.attrHooks.tabindex = jQuery.propHooks.tabIndex; + +// Hook for boolean attributes +boolHook = { + get: function( elem, name ) { + // Align boolean attributes with corresponding properties + // Fall back to attribute presence where some booleans are not supported + var attrNode, + property = jQuery.prop( elem, name ); + return property === true || typeof property !== "boolean" && ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ? + name.toLowerCase() : + undefined; + }, + set: function( elem, value, name ) { + var propName; + if ( value === false ) { + // Remove boolean attributes when set to false + jQuery.removeAttr( elem, name ); + } else { + // value is true since we know at this point it's type boolean and not false + // Set boolean attributes to the same name and set the DOM property + propName = jQuery.propFix[ name ] || name; + if ( propName in elem ) { + // Only set the IDL specifically if it already exists on the element + elem[ propName ] = true; + } + + elem.setAttribute( name, name.toLowerCase() ); + } + return name; + } +}; + +// IE6/7 do not support getting/setting some attributes with get/setAttribute +if ( !getSetAttribute ) { + + fixSpecified = { + name: true, + id: true, + coords: true + }; + + // Use this for any attribute in IE6/7 + // This fixes almost every IE6/7 issue + nodeHook = jQuery.valHooks.button = { + get: function( elem, name ) { + var ret; + ret = elem.getAttributeNode( name ); + return ret && ( fixSpecified[ name ] ? ret.nodeValue !== "" : ret.specified ) ? + ret.nodeValue : + undefined; + }, + set: function( elem, value, name ) { + // Set the existing or create a new attribute node + var ret = elem.getAttributeNode( name ); + if ( !ret ) { + ret = document.createAttribute( name ); + elem.setAttributeNode( ret ); + } + return ( ret.nodeValue = value + "" ); + } + }; + + // Apply the nodeHook to tabindex + jQuery.attrHooks.tabindex.set = nodeHook.set; + + // Set width and height to auto instead of 0 on empty string( Bug #8150 ) + // This is for removals + jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + set: function( elem, value ) { + if ( value === "" ) { + elem.setAttribute( name, "auto" ); + return value; + } + } + }); + }); + + // Set contenteditable to false on removals(#10429) + // Setting to empty string throws an error as an invalid value + jQuery.attrHooks.contenteditable = { + get: nodeHook.get, + set: function( elem, value, name ) { + if ( value === "" ) { + value = "false"; + } + nodeHook.set( elem, value, name ); + } + }; +} + + +// Some attributes require a special call on IE +if ( !jQuery.support.hrefNormalized ) { + jQuery.each([ "href", "src", "width", "height" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + get: function( elem ) { + var ret = elem.getAttribute( name, 2 ); + return ret === null ? undefined : ret; + } + }); + }); +} + +if ( !jQuery.support.style ) { + jQuery.attrHooks.style = { + get: function( elem ) { + // Return undefined in the case of empty string + // Normalize to lowercase since IE uppercases css property names + return elem.style.cssText.toLowerCase() || undefined; + }, + set: function( elem, value ) { + return ( elem.style.cssText = "" + value ); + } + }; +} + +// Safari mis-reports the default selected property of an option +// Accessing the parent's selectedIndex property fixes it +if ( !jQuery.support.optSelected ) { + jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, { + get: function( elem ) { + var parent = elem.parentNode; + + if ( parent ) { + parent.selectedIndex; + + // Make sure that it also works with optgroups, see #5701 + if ( parent.parentNode ) { + parent.parentNode.selectedIndex; + } + } + return null; + } + }); +} + +// IE6/7 call enctype encoding +if ( !jQuery.support.enctype ) { + jQuery.propFix.enctype = "encoding"; +} + +// Radios and checkboxes getter/setter +if ( !jQuery.support.checkOn ) { + jQuery.each([ "radio", "checkbox" ], function() { + jQuery.valHooks[ this ] = { + get: function( elem ) { + // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified + return elem.getAttribute("value") === null ? "on" : elem.value; + } + }; + }); +} +jQuery.each([ "radio", "checkbox" ], function() { + jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], { + set: function( elem, value ) { + if ( jQuery.isArray( value ) ) { + return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 ); + } + } + }); +}); + + + + +var rformElems = /^(?:textarea|input|select)$/i, + rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/, + rhoverHack = /(?:^|\s)hover(\.\S+)?\b/, + rkeyEvent = /^key/, + rmouseEvent = /^(?:mouse|contextmenu)|click/, + rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, + rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/, + quickParse = function( selector ) { + var quick = rquickIs.exec( selector ); + if ( quick ) { + // 0 1 2 3 + // [ _, tag, id, class ] + quick[1] = ( quick[1] || "" ).toLowerCase(); + quick[3] = quick[3] && new RegExp( "(?:^|\\s)" + quick[3] + "(?:\\s|$)" ); + } + return quick; + }, + quickIs = function( elem, m ) { + var attrs = elem.attributes || {}; + return ( + (!m[1] || elem.nodeName.toLowerCase() === m[1]) && + (!m[2] || (attrs.id || {}).value === m[2]) && + (!m[3] || m[3].test( (attrs[ "class" ] || {}).value )) + ); + }, + hoverHack = function( events ) { + return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" ); + }; + +/* + * Helper functions for managing events -- not part of the public interface. + * Props to Dean Edwards' addEvent library for many of the ideas. + */ +jQuery.event = { + + add: function( elem, types, handler, data, selector ) { + + var elemData, eventHandle, events, + t, tns, type, namespaces, handleObj, + handleObjIn, quick, handlers, special; + + // Don't attach events to noData or text/comment nodes (allow plain objects tho) + if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) { + return; + } + + // Caller can pass in an object of custom data in lieu of the handler + if ( handler.handler ) { + handleObjIn = handler; + handler = handleObjIn.handler; + selector = handleObjIn.selector; + } + + // Make sure that the handler has a unique ID, used to find/remove it later + if ( !handler.guid ) { + handler.guid = jQuery.guid++; + } + + // Init the element's event structure and main handler, if this is the first + events = elemData.events; + if ( !events ) { + elemData.events = events = {}; + } + eventHandle = elemData.handle; + if ( !eventHandle ) { + elemData.handle = eventHandle = function( e ) { + // Discard the second event of a jQuery.event.trigger() and + // when an event is called after a page has unloaded + return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ? + jQuery.event.dispatch.apply( eventHandle.elem, arguments ) : + undefined; + }; + // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events + eventHandle.elem = elem; + } + + // Handle multiple events separated by a space + // jQuery(...).bind("mouseover mouseout", fn); + types = jQuery.trim( hoverHack(types) ).split( " " ); + for ( t = 0; t < types.length; t++ ) { + + tns = rtypenamespace.exec( types[t] ) || []; + type = tns[1]; + namespaces = ( tns[2] || "" ).split( "." ).sort(); + + // If event changes its type, use the special event handlers for the changed type + special = jQuery.event.special[ type ] || {}; + + // If selector defined, determine special event api type, otherwise given type + type = ( selector ? special.delegateType : special.bindType ) || type; + + // Update special based on newly reset type + special = jQuery.event.special[ type ] || {}; + + // handleObj is passed to all event handlers + handleObj = jQuery.extend({ + type: type, + origType: tns[1], + data: data, + handler: handler, + guid: handler.guid, + selector: selector, + quick: selector && quickParse( selector ), + namespace: namespaces.join(".") + }, handleObjIn ); + + // Init the event handler queue if we're the first + handlers = events[ type ]; + if ( !handlers ) { + handlers = events[ type ] = []; + handlers.delegateCount = 0; + + // Only use addEventListener/attachEvent if the special events handler returns false + if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { + // Bind the global event handler to the element + if ( elem.addEventListener ) { + elem.addEventListener( type, eventHandle, false ); + + } else if ( elem.attachEvent ) { + elem.attachEvent( "on" + type, eventHandle ); + } + } + } + + if ( special.add ) { + special.add.call( elem, handleObj ); + + if ( !handleObj.handler.guid ) { + handleObj.handler.guid = handler.guid; + } + } + + // Add to the element's handler list, delegates in front + if ( selector ) { + handlers.splice( handlers.delegateCount++, 0, handleObj ); + } else { + handlers.push( handleObj ); + } + + // Keep track of which events have ever been used, for event optimization + jQuery.event.global[ type ] = true; + } + + // Nullify elem to prevent memory leaks in IE + elem = null; + }, + + global: {}, + + // Detach an event or set of events from an element + remove: function( elem, types, handler, selector, mappedTypes ) { + + var elemData = jQuery.hasData( elem ) && jQuery._data( elem ), + t, tns, type, origType, namespaces, origCount, + j, events, special, handle, eventType, handleObj; + + if ( !elemData || !(events = elemData.events) ) { + return; + } + + // Once for each type.namespace in types; type may be omitted + types = jQuery.trim( hoverHack( types || "" ) ).split(" "); + for ( t = 0; t < types.length; t++ ) { + tns = rtypenamespace.exec( types[t] ) || []; + type = origType = tns[1]; + namespaces = tns[2]; + + // Unbind all events (on this namespace, if provided) for the element + if ( !type ) { + for ( type in events ) { + jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); + } + continue; + } + + special = jQuery.event.special[ type ] || {}; + type = ( selector? special.delegateType : special.bindType ) || type; + eventType = events[ type ] || []; + origCount = eventType.length; + namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null; + + // Remove matching events + for ( j = 0; j < eventType.length; j++ ) { + handleObj = eventType[ j ]; + + if ( ( mappedTypes || origType === handleObj.origType ) && + ( !handler || handler.guid === handleObj.guid ) && + ( !namespaces || namespaces.test( handleObj.namespace ) ) && + ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) { + eventType.splice( j--, 1 ); + + if ( handleObj.selector ) { + eventType.delegateCount--; + } + if ( special.remove ) { + special.remove.call( elem, handleObj ); + } + } + } + + // Remove generic event handler if we removed something and no more handlers exist + // (avoids potential for endless recursion during removal of special event handlers) + if ( eventType.length === 0 && origCount !== eventType.length ) { + if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) { + jQuery.removeEvent( elem, type, elemData.handle ); + } + + delete events[ type ]; + } + } + + // Remove the expando if it's no longer used + if ( jQuery.isEmptyObject( events ) ) { + handle = elemData.handle; + if ( handle ) { + handle.elem = null; + } + + // removeData also checks for emptiness and clears the expando if empty + // so use it instead of delete + jQuery.removeData( elem, [ "events", "handle" ], true ); + } + }, + + // Events that are safe to short-circuit if no handlers are attached. + // Native DOM events should not be added, they may have inline handlers. + customEvent: { + "getData": true, + "setData": true, + "changeData": true + }, + + trigger: function( event, data, elem, onlyHandlers ) { + // Don't do events on text and comment nodes + if ( elem && (elem.nodeType === 3 || elem.nodeType === 8) ) { + return; + } + + // Event object or event type + var type = event.type || event, + namespaces = [], + cache, exclusive, i, cur, old, ontype, special, handle, eventPath, bubbleType; + + // focus/blur morphs to focusin/out; ensure we're not firing them right now + if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { + return; + } + + if ( type.indexOf( "!" ) >= 0 ) { + // Exclusive events trigger only for the exact event (no namespaces) + type = type.slice(0, -1); + exclusive = true; + } + + if ( type.indexOf( "." ) >= 0 ) { + // Namespaced trigger; create a regexp to match event type in handle() + namespaces = type.split("."); + type = namespaces.shift(); + namespaces.sort(); + } + + if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) { + // No jQuery handlers for this event type, and it can't have inline handlers + return; + } + + // Caller can pass in an Event, Object, or just an event type string + event = typeof event === "object" ? + // jQuery.Event object + event[ jQuery.expando ] ? event : + // Object literal + new jQuery.Event( type, event ) : + // Just the event type (string) + new jQuery.Event( type ); + + event.type = type; + event.isTrigger = true; + event.exclusive = exclusive; + event.namespace = namespaces.join( "." ); + event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null; + ontype = type.indexOf( ":" ) < 0 ? "on" + type : ""; + + // Handle a global trigger + if ( !elem ) { + + // TODO: Stop taunting the data cache; remove global events and always attach to document + cache = jQuery.cache; + for ( i in cache ) { + if ( cache[ i ].events && cache[ i ].events[ type ] ) { + jQuery.event.trigger( event, data, cache[ i ].handle.elem, true ); + } + } + return; + } + + // Clean up the event in case it is being reused + event.result = undefined; + if ( !event.target ) { + event.target = elem; + } + + // Clone any incoming data and prepend the event, creating the handler arg list + data = data != null ? jQuery.makeArray( data ) : []; + data.unshift( event ); + + // Allow special events to draw outside the lines + special = jQuery.event.special[ type ] || {}; + if ( special.trigger && special.trigger.apply( elem, data ) === false ) { + return; + } + + // Determine event propagation path in advance, per W3C events spec (#9951) + // Bubble up to document, then to window; watch for a global ownerDocument var (#9724) + eventPath = [[ elem, special.bindType || type ]]; + if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) { + + bubbleType = special.delegateType || type; + cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode; + old = null; + for ( ; cur; cur = cur.parentNode ) { + eventPath.push([ cur, bubbleType ]); + old = cur; + } + + // Only add window if we got to document (e.g., not plain obj or detached DOM) + if ( old && old === elem.ownerDocument ) { + eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]); + } + } + + // Fire handlers on the event path + for ( i = 0; i < eventPath.length && !event.isPropagationStopped(); i++ ) { + + cur = eventPath[i][0]; + event.type = eventPath[i][1]; + + handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" ); + if ( handle ) { + handle.apply( cur, data ); + } + // Note that this is a bare JS function and not a jQuery handler + handle = ontype && cur[ ontype ]; + if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) { + event.preventDefault(); + } + } + event.type = type; + + // If nobody prevented the default action, do it now + if ( !onlyHandlers && !event.isDefaultPrevented() ) { + + if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) && + !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) { + + // Call a native DOM method on the target with the same name name as the event. + // Can't use an .isFunction() check here because IE6/7 fails that test. + // Don't do default actions on window, that's where global variables be (#6170) + // IE<9 dies on focus/blur to hidden element (#1486) + if ( ontype && elem[ type ] && ((type !== "focus" && type !== "blur") || event.target.offsetWidth !== 0) && !jQuery.isWindow( elem ) ) { + + // Don't re-trigger an onFOO event when we call its FOO() method + old = elem[ ontype ]; + + if ( old ) { + elem[ ontype ] = null; + } + + // Prevent re-triggering of the same event, since we already bubbled it above + jQuery.event.triggered = type; + elem[ type ](); + jQuery.event.triggered = undefined; + + if ( old ) { + elem[ ontype ] = old; + } + } + } + } + + return event.result; + }, + + dispatch: function( event ) { + + // Make a writable jQuery.Event from the native event object + event = jQuery.event.fix( event || window.event ); + + var handlers = ( (jQuery._data( this, "events" ) || {} )[ event.type ] || []), + delegateCount = handlers.delegateCount, + args = [].slice.call( arguments, 0 ), + run_all = !event.exclusive && !event.namespace, + special = jQuery.event.special[ event.type ] || {}, + handlerQueue = [], + i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related; + + // Use the fix-ed jQuery.Event rather than the (read-only) native event + args[0] = event; + event.delegateTarget = this; + + // Call the preDispatch hook for the mapped type, and let it bail if desired + if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) { + return; + } + + // Determine handlers that should run if there are delegated events + // Avoid non-left-click bubbling in Firefox (#3861) + if ( delegateCount && !(event.button && event.type === "click") ) { + + // Pregenerate a single jQuery object for reuse with .is() + jqcur = jQuery(this); + jqcur.context = this.ownerDocument || this; + + for ( cur = event.target; cur != this; cur = cur.parentNode || this ) { + + // Don't process events on disabled elements (#6911, #8165) + if ( cur.disabled !== true ) { + selMatch = {}; + matches = []; + jqcur[0] = cur; + for ( i = 0; i < delegateCount; i++ ) { + handleObj = handlers[ i ]; + sel = handleObj.selector; + + if ( selMatch[ sel ] === undefined ) { + selMatch[ sel ] = ( + handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel ) + ); + } + if ( selMatch[ sel ] ) { + matches.push( handleObj ); + } + } + if ( matches.length ) { + handlerQueue.push({ elem: cur, matches: matches }); + } + } + } + } + + // Add the remaining (directly-bound) handlers + if ( handlers.length > delegateCount ) { + handlerQueue.push({ elem: this, matches: handlers.slice( delegateCount ) }); + } + + // Run delegates first; they may want to stop propagation beneath us + for ( i = 0; i < handlerQueue.length && !event.isPropagationStopped(); i++ ) { + matched = handlerQueue[ i ]; + event.currentTarget = matched.elem; + + for ( j = 0; j < matched.matches.length && !event.isImmediatePropagationStopped(); j++ ) { + handleObj = matched.matches[ j ]; + + // Triggered event must either 1) be non-exclusive and have no namespace, or + // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace). + if ( run_all || (!event.namespace && !handleObj.namespace) || event.namespace_re && event.namespace_re.test( handleObj.namespace ) ) { + + event.data = handleObj.data; + event.handleObj = handleObj; + + ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler ) + .apply( matched.elem, args ); + + if ( ret !== undefined ) { + event.result = ret; + if ( ret === false ) { + event.preventDefault(); + event.stopPropagation(); + } + } + } + } + } + + // Call the postDispatch hook for the mapped type + if ( special.postDispatch ) { + special.postDispatch.call( this, event ); + } + + return event.result; + }, + + // Includes some event props shared by KeyEvent and MouseEvent + // *** attrChange attrName relatedNode srcElement are not normalized, non-W3C, deprecated, will be removed in 1.8 *** + props: "attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "), + + fixHooks: {}, + + keyHooks: { + props: "char charCode key keyCode".split(" "), + filter: function( event, original ) { + + // Add which for key events + if ( event.which == null ) { + event.which = original.charCode != null ? original.charCode : original.keyCode; + } + + return event; + } + }, + + mouseHooks: { + props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "), + filter: function( event, original ) { + var eventDoc, doc, body, + button = original.button, + fromElement = original.fromElement; + + // Calculate pageX/Y if missing and clientX/Y available + if ( event.pageX == null && original.clientX != null ) { + eventDoc = event.target.ownerDocument || document; + doc = eventDoc.documentElement; + body = eventDoc.body; + + event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 ); + event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 ); + } + + // Add relatedTarget, if necessary + if ( !event.relatedTarget && fromElement ) { + event.relatedTarget = fromElement === event.target ? original.toElement : fromElement; + } + + // Add which for click: 1 === left; 2 === middle; 3 === right + // Note: button is not normalized, so don't use it + if ( !event.which && button !== undefined ) { + event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) ); + } + + return event; + } + }, + + fix: function( event ) { + if ( event[ jQuery.expando ] ) { + return event; + } + + // Create a writable copy of the event object and normalize some properties + var i, prop, + originalEvent = event, + fixHook = jQuery.event.fixHooks[ event.type ] || {}, + copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props; + + event = jQuery.Event( originalEvent ); + + for ( i = copy.length; i; ) { + prop = copy[ --i ]; + event[ prop ] = originalEvent[ prop ]; + } + + // Fix target property, if necessary (#1925, IE 6/7/8 & Safari2) + if ( !event.target ) { + event.target = originalEvent.srcElement || document; + } + + // Target should not be a text node (#504, Safari) + if ( event.target.nodeType === 3 ) { + event.target = event.target.parentNode; + } + + // For mouse/key events; add metaKey if it's not there (#3368, IE6/7/8) + if ( event.metaKey === undefined ) { + event.metaKey = event.ctrlKey; + } + + return fixHook.filter? fixHook.filter( event, originalEvent ) : event; + }, + + special: { + ready: { + // Make sure the ready event is setup + setup: jQuery.bindReady + }, + + load: { + // Prevent triggered image.load events from bubbling to window.load + noBubble: true + }, + + focus: { + delegateType: "focusin" + }, + blur: { + delegateType: "focusout" + }, + + beforeunload: { + setup: function( data, namespaces, eventHandle ) { + // We only want to do this special case on windows + if ( jQuery.isWindow( this ) ) { + this.onbeforeunload = eventHandle; + } + }, + + teardown: function( namespaces, eventHandle ) { + if ( this.onbeforeunload === eventHandle ) { + this.onbeforeunload = null; + } + } + } + }, + + simulate: function( type, elem, event, bubble ) { + // Piggyback on a donor event to simulate a different one. + // Fake originalEvent to avoid donor's stopPropagation, but if the + // simulated event prevents default then we do the same on the donor. + var e = jQuery.extend( + new jQuery.Event(), + event, + { type: type, + isSimulated: true, + originalEvent: {} + } + ); + if ( bubble ) { + jQuery.event.trigger( e, null, elem ); + } else { + jQuery.event.dispatch.call( elem, e ); + } + if ( e.isDefaultPrevented() ) { + event.preventDefault(); + } + } +}; + +// Some plugins are using, but it's undocumented/deprecated and will be removed. +// The 1.7 special event interface should provide all the hooks needed now. +jQuery.event.handle = jQuery.event.dispatch; + +jQuery.removeEvent = document.removeEventListener ? + function( elem, type, handle ) { + if ( elem.removeEventListener ) { + elem.removeEventListener( type, handle, false ); + } + } : + function( elem, type, handle ) { + if ( elem.detachEvent ) { + elem.detachEvent( "on" + type, handle ); + } + }; + +jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword + if ( !(this instanceof jQuery.Event) ) { + return new jQuery.Event( src, props ); + } + + // Event object + if ( src && src.type ) { + this.originalEvent = src; + this.type = src.type; + + // Events bubbling up the document may have been marked as prevented + // by a handler lower down the tree; reflect the correct value. + this.isDefaultPrevented = ( src.defaultPrevented || src.returnValue === false || + src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse; + + // Event type + } else { + this.type = src; + } + + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + + // Create a timestamp if incoming event doesn't have one + this.timeStamp = src && src.timeStamp || jQuery.now(); + + // Mark it as fixed + this[ jQuery.expando ] = true; +}; + +function returnFalse() { + return false; +} +function returnTrue() { + return true; +} + +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +jQuery.Event.prototype = { + preventDefault: function() { + this.isDefaultPrevented = returnTrue; + + var e = this.originalEvent; + if ( !e ) { + return; + } + + // if preventDefault exists run it on the original event + if ( e.preventDefault ) { + e.preventDefault(); + + // otherwise set the returnValue property of the original event to false (IE) + } else { + e.returnValue = false; + } + }, + stopPropagation: function() { + this.isPropagationStopped = returnTrue; + + var e = this.originalEvent; + if ( !e ) { + return; + } + // if stopPropagation exists run it on the original event + if ( e.stopPropagation ) { + e.stopPropagation(); + } + // otherwise set the cancelBubble property of the original event to true (IE) + e.cancelBubble = true; + }, + stopImmediatePropagation: function() { + this.isImmediatePropagationStopped = returnTrue; + this.stopPropagation(); + }, + isDefaultPrevented: returnFalse, + isPropagationStopped: returnFalse, + isImmediatePropagationStopped: returnFalse +}; + +// Create mouseenter/leave events using mouseover/out and event-time checks +jQuery.each({ + mouseenter: "mouseover", + mouseleave: "mouseout" +}, function( orig, fix ) { + jQuery.event.special[ orig ] = { + delegateType: fix, + bindType: fix, + + handle: function( event ) { + var target = this, + related = event.relatedTarget, + handleObj = event.handleObj, + selector = handleObj.selector, + ret; + + // For mousenter/leave call the handler if related is outside the target. + // NB: No relatedTarget if the mouse left/entered the browser window + if ( !related || (related !== target && !jQuery.contains( target, related )) ) { + event.type = handleObj.origType; + ret = handleObj.handler.apply( this, arguments ); + event.type = fix; + } + return ret; + } + }; +}); + +// IE submit delegation +if ( !jQuery.support.submitBubbles ) { + + jQuery.event.special.submit = { + setup: function() { + // Only need this for delegated form submit events + if ( jQuery.nodeName( this, "form" ) ) { + return false; + } + + // Lazy-add a submit handler when a descendant form may potentially be submitted + jQuery.event.add( this, "click._submit keypress._submit", function( e ) { + // Node name check avoids a VML-related crash in IE (#9807) + var elem = e.target, + form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined; + if ( form && !form._submit_attached ) { + jQuery.event.add( form, "submit._submit", function( event ) { + event._submit_bubble = true; + }); + form._submit_attached = true; + } + }); + // return undefined since we don't need an event listener + }, + + postDispatch: function( event ) { + // If form was submitted by the user, bubble the event up the tree + if ( event._submit_bubble ) { + delete event._submit_bubble; + if ( this.parentNode && !event.isTrigger ) { + jQuery.event.simulate( "submit", this.parentNode, event, true ); + } + } + }, + + teardown: function() { + // Only need this for delegated form submit events + if ( jQuery.nodeName( this, "form" ) ) { + return false; + } + + // Remove delegated handlers; cleanData eventually reaps submit handlers attached above + jQuery.event.remove( this, "._submit" ); + } + }; +} + +// IE change delegation and checkbox/radio fix +if ( !jQuery.support.changeBubbles ) { + + jQuery.event.special.change = { + + setup: function() { + + if ( rformElems.test( this.nodeName ) ) { + // IE doesn't fire change on a check/radio until blur; trigger it on click + // after a propertychange. Eat the blur-change in special.change.handle. + // This still fires onchange a second time for check/radio after blur. + if ( this.type === "checkbox" || this.type === "radio" ) { + jQuery.event.add( this, "propertychange._change", function( event ) { + if ( event.originalEvent.propertyName === "checked" ) { + this._just_changed = true; + } + }); + jQuery.event.add( this, "click._change", function( event ) { + if ( this._just_changed && !event.isTrigger ) { + this._just_changed = false; + jQuery.event.simulate( "change", this, event, true ); + } + }); + } + return false; + } + // Delegated event; lazy-add a change handler on descendant inputs + jQuery.event.add( this, "beforeactivate._change", function( e ) { + var elem = e.target; + + if ( rformElems.test( elem.nodeName ) && !elem._change_attached ) { + jQuery.event.add( elem, "change._change", function( event ) { + if ( this.parentNode && !event.isSimulated && !event.isTrigger ) { + jQuery.event.simulate( "change", this.parentNode, event, true ); + } + }); + elem._change_attached = true; + } + }); + }, + + handle: function( event ) { + var elem = event.target; + + // Swallow native change events from checkbox/radio, we already triggered them above + if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) { + return event.handleObj.handler.apply( this, arguments ); + } + }, + + teardown: function() { + jQuery.event.remove( this, "._change" ); + + return rformElems.test( this.nodeName ); + } + }; +} + +// Create "bubbling" focus and blur events +if ( !jQuery.support.focusinBubbles ) { + jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler while someone wants focusin/focusout + var attaches = 0, + handler = function( event ) { + jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); + }; + + jQuery.event.special[ fix ] = { + setup: function() { + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); + } + }, + teardown: function() { + if ( --attaches === 0 ) { + document.removeEventListener( orig, handler, true ); + } + } + }; + }); +} + +jQuery.fn.extend({ + + on: function( types, selector, data, fn, /*INTERNAL*/ one ) { + var origFn, type; + + // Types can be a map of types/handlers + if ( typeof types === "object" ) { + // ( types-Object, selector, data ) + if ( typeof selector !== "string" ) { // && selector != null + // ( types-Object, data ) + data = data || selector; + selector = undefined; + } + for ( type in types ) { + this.on( type, selector, data, types[ type ], one ); + } + return this; + } + + if ( data == null && fn == null ) { + // ( types, fn ) + fn = selector; + data = selector = undefined; + } else if ( fn == null ) { + if ( typeof selector === "string" ) { + // ( types, selector, fn ) + fn = data; + data = undefined; + } else { + // ( types, data, fn ) + fn = data; + data = selector; + selector = undefined; + } + } + if ( fn === false ) { + fn = returnFalse; + } else if ( !fn ) { + return this; + } + + if ( one === 1 ) { + origFn = fn; + fn = function( event ) { + // Can use an empty set, since event contains the info + jQuery().off( event ); + return origFn.apply( this, arguments ); + }; + // Use same guid so caller can remove using origFn + fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ ); + } + return this.each( function() { + jQuery.event.add( this, types, fn, data, selector ); + }); + }, + one: function( types, selector, data, fn ) { + return this.on( types, selector, data, fn, 1 ); + }, + off: function( types, selector, fn ) { + if ( types && types.preventDefault && types.handleObj ) { + // ( event ) dispatched jQuery.Event + var handleObj = types.handleObj; + jQuery( types.delegateTarget ).off( + handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType, + handleObj.selector, + handleObj.handler + ); + return this; + } + if ( typeof types === "object" ) { + // ( types-object [, selector] ) + for ( var type in types ) { + this.off( type, selector, types[ type ] ); + } + return this; + } + if ( selector === false || typeof selector === "function" ) { + // ( types [, fn] ) + fn = selector; + selector = undefined; + } + if ( fn === false ) { + fn = returnFalse; + } + return this.each(function() { + jQuery.event.remove( this, types, fn, selector ); + }); + }, + + bind: function( types, data, fn ) { + return this.on( types, null, data, fn ); + }, + unbind: function( types, fn ) { + return this.off( types, null, fn ); + }, + + live: function( types, data, fn ) { + jQuery( this.context ).on( types, this.selector, data, fn ); + return this; + }, + die: function( types, fn ) { + jQuery( this.context ).off( types, this.selector || "**", fn ); + return this; + }, + + delegate: function( selector, types, data, fn ) { + return this.on( types, selector, data, fn ); + }, + undelegate: function( selector, types, fn ) { + // ( namespace ) or ( selector, types [, fn] ) + return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn ); + }, + + trigger: function( type, data ) { + return this.each(function() { + jQuery.event.trigger( type, data, this ); + }); + }, + triggerHandler: function( type, data ) { + if ( this[0] ) { + return jQuery.event.trigger( type, data, this[0], true ); + } + }, + + toggle: function( fn ) { + // Save reference to arguments for access in closure + var args = arguments, + guid = fn.guid || jQuery.guid++, + i = 0, + toggler = function( event ) { + // Figure out which function to execute + var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i; + jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 ); + + // Make sure that clicks stop + event.preventDefault(); + + // and execute the function + return args[ lastToggle ].apply( this, arguments ) || false; + }; + + // link all the functions, so any of them can unbind this click handler + toggler.guid = guid; + while ( i < args.length ) { + args[ i++ ].guid = guid; + } + + return this.click( toggler ); + }, + + hover: function( fnOver, fnOut ) { + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); + } +}); + +jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + + "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) { + + // Handle event binding + jQuery.fn[ name ] = function( data, fn ) { + if ( fn == null ) { + fn = data; + data = null; + } + + return arguments.length > 0 ? + this.on( name, null, data, fn ) : + this.trigger( name ); + }; + + if ( jQuery.attrFn ) { + jQuery.attrFn[ name ] = true; + } + + if ( rkeyEvent.test( name ) ) { + jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks; + } + + if ( rmouseEvent.test( name ) ) { + jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks; + } +}); + + + +/*! + * Sizzle CSS Selector Engine + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){ + +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, + expando = "sizcache" + (Math.random() + '').replace('.', ''), + done = 0, + toString = Object.prototype.toString, + hasDuplicate = false, + baseHasDuplicate = true, + rBackslash = /\\/g, + rReturn = /\r\n/g, + rNonWord = /\W/; + +// Here we check if the JavaScript engine is using some sort of +// optimization where it does not always call our comparision +// function. If that is the case, discard the hasDuplicate value. +// Thus far that includes Google Chrome. +[0, 0].sort(function() { + baseHasDuplicate = false; + return 0; +}); + +var Sizzle = function( selector, context, results, seed ) { + results = results || []; + context = context || document; + + var origContext = context; + + if ( context.nodeType !== 1 && context.nodeType !== 9 ) { + return []; + } + + if ( !selector || typeof selector !== "string" ) { + return results; + } + + var m, set, checkSet, extra, ret, cur, pop, i, + prune = true, + contextXML = Sizzle.isXML( context ), + parts = [], + soFar = selector; + + // Reset the position of the chunker regexp (start from head) + do { + chunker.exec( "" ); + m = chunker.exec( soFar ); + + if ( m ) { + soFar = m[3]; + + parts.push( m[1] ); + + if ( m[2] ) { + extra = m[3]; + break; + } + } + } while ( m ); + + if ( parts.length > 1 && origPOS.exec( selector ) ) { + + if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { + set = posProcess( parts[0] + parts[1], context, seed ); + + } else { + set = Expr.relative[ parts[0] ] ? + [ context ] : + Sizzle( parts.shift(), context ); + + while ( parts.length ) { + selector = parts.shift(); + + if ( Expr.relative[ selector ] ) { + selector += parts.shift(); + } + + set = posProcess( selector, set, seed ); + } + } + + } else { + // Take a shortcut and set the context if the root selector is an ID + // (but not if it'll be faster if the inner selector is an ID) + if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && + Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { + + ret = Sizzle.find( parts.shift(), context, contextXML ); + context = ret.expr ? + Sizzle.filter( ret.expr, ret.set )[0] : + ret.set[0]; + } + + if ( context ) { + ret = seed ? + { expr: parts.pop(), set: makeArray(seed) } : + Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); + + set = ret.expr ? + Sizzle.filter( ret.expr, ret.set ) : + ret.set; + + if ( parts.length > 0 ) { + checkSet = makeArray( set ); + + } else { + prune = false; + } + + while ( parts.length ) { + cur = parts.pop(); + pop = cur; + + if ( !Expr.relative[ cur ] ) { + cur = ""; + } else { + pop = parts.pop(); + } + + if ( pop == null ) { + pop = context; + } + + Expr.relative[ cur ]( checkSet, pop, contextXML ); + } + + } else { + checkSet = parts = []; + } + } + + if ( !checkSet ) { + checkSet = set; + } + + if ( !checkSet ) { + Sizzle.error( cur || selector ); + } + + if ( toString.call(checkSet) === "[object Array]" ) { + if ( !prune ) { + results.push.apply( results, checkSet ); + + } else if ( context && context.nodeType === 1 ) { + for ( i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) { + results.push( set[i] ); + } + } + + } else { + for ( i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && checkSet[i].nodeType === 1 ) { + results.push( set[i] ); + } + } + } + + } else { + makeArray( checkSet, results ); + } + + if ( extra ) { + Sizzle( extra, origContext, results, seed ); + Sizzle.uniqueSort( results ); + } + + return results; +}; + +Sizzle.uniqueSort = function( results ) { + if ( sortOrder ) { + hasDuplicate = baseHasDuplicate; + results.sort( sortOrder ); + + if ( hasDuplicate ) { + for ( var i = 1; i < results.length; i++ ) { + if ( results[i] === results[ i - 1 ] ) { + results.splice( i--, 1 ); + } + } + } + } + + return results; +}; + +Sizzle.matches = function( expr, set ) { + return Sizzle( expr, null, null, set ); +}; + +Sizzle.matchesSelector = function( node, expr ) { + return Sizzle( expr, null, null, [node] ).length > 0; +}; + +Sizzle.find = function( expr, context, isXML ) { + var set, i, len, match, type, left; + + if ( !expr ) { + return []; + } + + for ( i = 0, len = Expr.order.length; i < len; i++ ) { + type = Expr.order[i]; + + if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { + left = match[1]; + match.splice( 1, 1 ); + + if ( left.substr( left.length - 1 ) !== "\\" ) { + match[1] = (match[1] || "").replace( rBackslash, "" ); + set = Expr.find[ type ]( match, context, isXML ); + + if ( set != null ) { + expr = expr.replace( Expr.match[ type ], "" ); + break; + } + } + } + } + + if ( !set ) { + set = typeof context.getElementsByTagName !== "undefined" ? + context.getElementsByTagName( "*" ) : + []; + } + + return { set: set, expr: expr }; +}; + +Sizzle.filter = function( expr, set, inplace, not ) { + var match, anyFound, + type, found, item, filter, left, + i, pass, + old = expr, + result = [], + curLoop = set, + isXMLFilter = set && set[0] && Sizzle.isXML( set[0] ); + + while ( expr && set.length ) { + for ( type in Expr.filter ) { + if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { + filter = Expr.filter[ type ]; + left = match[1]; + + anyFound = false; + + match.splice(1,1); + + if ( left.substr( left.length - 1 ) === "\\" ) { + continue; + } + + if ( curLoop === result ) { + result = []; + } + + if ( Expr.preFilter[ type ] ) { + match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); + + if ( !match ) { + anyFound = found = true; + + } else if ( match === true ) { + continue; + } + } + + if ( match ) { + for ( i = 0; (item = curLoop[i]) != null; i++ ) { + if ( item ) { + found = filter( item, match, i, curLoop ); + pass = not ^ found; + + if ( inplace && found != null ) { + if ( pass ) { + anyFound = true; + + } else { + curLoop[i] = false; + } + + } else if ( pass ) { + result.push( item ); + anyFound = true; + } + } + } + } + + if ( found !== undefined ) { + if ( !inplace ) { + curLoop = result; + } + + expr = expr.replace( Expr.match[ type ], "" ); + + if ( !anyFound ) { + return []; + } + + break; + } + } + } + + // Improper expression + if ( expr === old ) { + if ( anyFound == null ) { + Sizzle.error( expr ); + + } else { + break; + } + } + + old = expr; + } + + return curLoop; +}; + +Sizzle.error = function( msg ) { + throw new Error( "Syntax error, unrecognized expression: " + msg ); +}; + +/** + * Utility function for retreiving the text value of an array of DOM nodes + * @param {Array|Element} elem + */ +var getText = Sizzle.getText = function( elem ) { + var i, node, + nodeType = elem.nodeType, + ret = ""; + + if ( nodeType ) { + if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { + // Use textContent || innerText for elements + if ( typeof elem.textContent === 'string' ) { + return elem.textContent; + } else if ( typeof elem.innerText === 'string' ) { + // Replace IE's carriage returns + return elem.innerText.replace( rReturn, '' ); + } else { + // Traverse it's children + for ( elem = elem.firstChild; elem; elem = elem.nextSibling) { + ret += getText( elem ); + } + } + } else if ( nodeType === 3 || nodeType === 4 ) { + return elem.nodeValue; + } + } else { + + // If no nodeType, this is expected to be an array + for ( i = 0; (node = elem[i]); i++ ) { + // Do not traverse comment nodes + if ( node.nodeType !== 8 ) { + ret += getText( node ); + } + } + } + return ret; +}; + +var Expr = Sizzle.selectors = { + order: [ "ID", "NAME", "TAG" ], + + match: { + ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, + CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/, + TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, + CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/, + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, + PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ + }, + + leftMatch: {}, + + attrMap: { + "class": "className", + "for": "htmlFor" + }, + + attrHandle: { + href: function( elem ) { + return elem.getAttribute( "href" ); + }, + type: function( elem ) { + return elem.getAttribute( "type" ); + } + }, + + relative: { + "+": function(checkSet, part){ + var isPartStr = typeof part === "string", + isTag = isPartStr && !rNonWord.test( part ), + isPartStrNotTag = isPartStr && !isTag; + + if ( isTag ) { + part = part.toLowerCase(); + } + + for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { + if ( (elem = checkSet[i]) ) { + while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} + + checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? + elem || false : + elem === part; + } + } + + if ( isPartStrNotTag ) { + Sizzle.filter( part, checkSet, true ); + } + }, + + ">": function( checkSet, part ) { + var elem, + isPartStr = typeof part === "string", + i = 0, + l = checkSet.length; + + if ( isPartStr && !rNonWord.test( part ) ) { + part = part.toLowerCase(); + + for ( ; i < l; i++ ) { + elem = checkSet[i]; + + if ( elem ) { + var parent = elem.parentNode; + checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; + } + } + + } else { + for ( ; i < l; i++ ) { + elem = checkSet[i]; + + if ( elem ) { + checkSet[i] = isPartStr ? + elem.parentNode : + elem.parentNode === part; + } + } + + if ( isPartStr ) { + Sizzle.filter( part, checkSet, true ); + } + } + }, + + "": function(checkSet, part, isXML){ + var nodeCheck, + doneName = done++, + checkFn = dirCheck; + + if ( typeof part === "string" && !rNonWord.test( part ) ) { + part = part.toLowerCase(); + nodeCheck = part; + checkFn = dirNodeCheck; + } + + checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML ); + }, + + "~": function( checkSet, part, isXML ) { + var nodeCheck, + doneName = done++, + checkFn = dirCheck; + + if ( typeof part === "string" && !rNonWord.test( part ) ) { + part = part.toLowerCase(); + nodeCheck = part; + checkFn = dirNodeCheck; + } + + checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML ); + } + }, + + find: { + ID: function( match, context, isXML ) { + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + return m && m.parentNode ? [m] : []; + } + }, + + NAME: function( match, context ) { + if ( typeof context.getElementsByName !== "undefined" ) { + var ret = [], + results = context.getElementsByName( match[1] ); + + for ( var i = 0, l = results.length; i < l; i++ ) { + if ( results[i].getAttribute("name") === match[1] ) { + ret.push( results[i] ); + } + } + + return ret.length === 0 ? null : ret; + } + }, + + TAG: function( match, context ) { + if ( typeof context.getElementsByTagName !== "undefined" ) { + return context.getElementsByTagName( match[1] ); + } + } + }, + preFilter: { + CLASS: function( match, curLoop, inplace, result, not, isXML ) { + match = " " + match[1].replace( rBackslash, "" ) + " "; + + if ( isXML ) { + return match; + } + + for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { + if ( elem ) { + if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) { + if ( !inplace ) { + result.push( elem ); + } + + } else if ( inplace ) { + curLoop[i] = false; + } + } + } + + return false; + }, + + ID: function( match ) { + return match[1].replace( rBackslash, "" ); + }, + + TAG: function( match, curLoop ) { + return match[1].replace( rBackslash, "" ).toLowerCase(); + }, + + CHILD: function( match ) { + if ( match[1] === "nth" ) { + if ( !match[2] ) { + Sizzle.error( match[0] ); + } + + match[2] = match[2].replace(/^\+|\s*/g, ''); + + // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' + var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec( + match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || + !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); + + // calculate the numbers (first)n+(last) including if they are negative + match[2] = (test[1] + (test[2] || 1)) - 0; + match[3] = test[3] - 0; + } + else if ( match[2] ) { + Sizzle.error( match[0] ); + } + + // TODO: Move to normal caching system + match[0] = done++; + + return match; + }, + + ATTR: function( match, curLoop, inplace, result, not, isXML ) { + var name = match[1] = match[1].replace( rBackslash, "" ); + + if ( !isXML && Expr.attrMap[name] ) { + match[1] = Expr.attrMap[name]; + } + + // Handle if an un-quoted value was used + match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" ); + + if ( match[2] === "~=" ) { + match[4] = " " + match[4] + " "; + } + + return match; + }, + + PSEUDO: function( match, curLoop, inplace, result, not ) { + if ( match[1] === "not" ) { + // If we're dealing with a complex expression, or a simple one + if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { + match[3] = Sizzle(match[3], null, null, curLoop); + + } else { + var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); + + if ( !inplace ) { + result.push.apply( result, ret ); + } + + return false; + } + + } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { + return true; + } + + return match; + }, + + POS: function( match ) { + match.unshift( true ); + + return match; + } + }, + + filters: { + enabled: function( elem ) { + return elem.disabled === false && elem.type !== "hidden"; + }, + + disabled: function( elem ) { + return elem.disabled === true; + }, + + checked: function( elem ) { + return elem.checked === true; + }, + + selected: function( elem ) { + // Accessing this property makes selected-by-default + // options in Safari work properly + if ( elem.parentNode ) { + elem.parentNode.selectedIndex; + } + + return elem.selected === true; + }, + + parent: function( elem ) { + return !!elem.firstChild; + }, + + empty: function( elem ) { + return !elem.firstChild; + }, + + has: function( elem, i, match ) { + return !!Sizzle( match[3], elem ).length; + }, + + header: function( elem ) { + return (/h\d/i).test( elem.nodeName ); + }, + + text: function( elem ) { + var attr = elem.getAttribute( "type" ), type = elem.type; + // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) + // use getAttribute instead to test this case + return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null ); + }, + + radio: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type; + }, + + checkbox: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type; + }, + + file: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "file" === elem.type; + }, + + password: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "password" === elem.type; + }, + + submit: function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && "submit" === elem.type; + }, + + image: function( elem ) { + return elem.nodeName.toLowerCase() === "input" && "image" === elem.type; + }, + + reset: function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && "reset" === elem.type; + }, + + button: function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && "button" === elem.type || name === "button"; + }, + + input: function( elem ) { + return (/input|select|textarea|button/i).test( elem.nodeName ); + }, + + focus: function( elem ) { + return elem === elem.ownerDocument.activeElement; + } + }, + setFilters: { + first: function( elem, i ) { + return i === 0; + }, + + last: function( elem, i, match, array ) { + return i === array.length - 1; + }, + + even: function( elem, i ) { + return i % 2 === 0; + }, + + odd: function( elem, i ) { + return i % 2 === 1; + }, + + lt: function( elem, i, match ) { + return i < match[3] - 0; + }, + + gt: function( elem, i, match ) { + return i > match[3] - 0; + }, + + nth: function( elem, i, match ) { + return match[3] - 0 === i; + }, + + eq: function( elem, i, match ) { + return match[3] - 0 === i; + } + }, + filter: { + PSEUDO: function( elem, match, i, array ) { + var name = match[1], + filter = Expr.filters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + + } else if ( name === "contains" ) { + return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0; + + } else if ( name === "not" ) { + var not = match[3]; + + for ( var j = 0, l = not.length; j < l; j++ ) { + if ( not[j] === elem ) { + return false; + } + } + + return true; + + } else { + Sizzle.error( name ); + } + }, + + CHILD: function( elem, match ) { + var first, last, + doneName, parent, cache, + count, diff, + type = match[1], + node = elem; + + switch ( type ) { + case "only": + case "first": + while ( (node = node.previousSibling) ) { + if ( node.nodeType === 1 ) { + return false; + } + } + + if ( type === "first" ) { + return true; + } + + node = elem; + + /* falls through */ + case "last": + while ( (node = node.nextSibling) ) { + if ( node.nodeType === 1 ) { + return false; + } + } + + return true; + + case "nth": + first = match[2]; + last = match[3]; + + if ( first === 1 && last === 0 ) { + return true; + } + + doneName = match[0]; + parent = elem.parentNode; + + if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) { + count = 0; + + for ( node = parent.firstChild; node; node = node.nextSibling ) { + if ( node.nodeType === 1 ) { + node.nodeIndex = ++count; + } + } + + parent[ expando ] = doneName; + } + + diff = elem.nodeIndex - last; + + if ( first === 0 ) { + return diff === 0; + + } else { + return ( diff % first === 0 && diff / first >= 0 ); + } + } + }, + + ID: function( elem, match ) { + return elem.nodeType === 1 && elem.getAttribute("id") === match; + }, + + TAG: function( elem, match ) { + return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match; + }, + + CLASS: function( elem, match ) { + return (" " + (elem.className || elem.getAttribute("class")) + " ") + .indexOf( match ) > -1; + }, + + ATTR: function( elem, match ) { + var name = match[1], + result = Sizzle.attr ? + Sizzle.attr( elem, name ) : + Expr.attrHandle[ name ] ? + Expr.attrHandle[ name ]( elem ) : + elem[ name ] != null ? + elem[ name ] : + elem.getAttribute( name ), + value = result + "", + type = match[2], + check = match[4]; + + return result == null ? + type === "!=" : + !type && Sizzle.attr ? + result != null : + type === "=" ? + value === check : + type === "*=" ? + value.indexOf(check) >= 0 : + type === "~=" ? + (" " + value + " ").indexOf(check) >= 0 : + !check ? + value && result !== false : + type === "!=" ? + value !== check : + type === "^=" ? + value.indexOf(check) === 0 : + type === "$=" ? + value.substr(value.length - check.length) === check : + type === "|=" ? + value === check || value.substr(0, check.length + 1) === check + "-" : + false; + }, + + POS: function( elem, match, i, array ) { + var name = match[2], + filter = Expr.setFilters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } + } + } +}; + +var origPOS = Expr.match.POS, + fescape = function(all, num){ + return "\\" + (num - 0 + 1); + }; + +for ( var type in Expr.match ) { + Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); + Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); +} +// Expose origPOS +// "global" as in regardless of relation to brackets/parens +Expr.match.globalPOS = origPOS; + +var makeArray = function( array, results ) { + array = Array.prototype.slice.call( array, 0 ); + + if ( results ) { + results.push.apply( results, array ); + return results; + } + + return array; +}; + +// Perform a simple check to determine if the browser is capable of +// converting a NodeList to an array using builtin methods. +// Also verifies that the returned array holds DOM nodes +// (which is not the case in the Blackberry browser) +try { + Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; + +// Provide a fallback method if it does not work +} catch( e ) { + makeArray = function( array, results ) { + var i = 0, + ret = results || []; + + if ( toString.call(array) === "[object Array]" ) { + Array.prototype.push.apply( ret, array ); + + } else { + if ( typeof array.length === "number" ) { + for ( var l = array.length; i < l; i++ ) { + ret.push( array[i] ); + } + + } else { + for ( ; array[i]; i++ ) { + ret.push( array[i] ); + } + } + } + + return ret; + }; +} + +var sortOrder, siblingCheck; + +if ( document.documentElement.compareDocumentPosition ) { + sortOrder = function( a, b ) { + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { + return a.compareDocumentPosition ? -1 : 1; + } + + return a.compareDocumentPosition(b) & 4 ? -1 : 1; + }; + +} else { + sortOrder = function( a, b ) { + // The nodes are identical, we can exit early + if ( a === b ) { + hasDuplicate = true; + return 0; + + // Fallback to using sourceIndex (in IE) if it's available on both nodes + } else if ( a.sourceIndex && b.sourceIndex ) { + return a.sourceIndex - b.sourceIndex; + } + + var al, bl, + ap = [], + bp = [], + aup = a.parentNode, + bup = b.parentNode, + cur = aup; + + // If the nodes are siblings (or identical) we can do a quick check + if ( aup === bup ) { + return siblingCheck( a, b ); + + // If no parents were found then the nodes are disconnected + } else if ( !aup ) { + return -1; + + } else if ( !bup ) { + return 1; + } + + // Otherwise they're somewhere else in the tree so we need + // to build up a full list of the parentNodes for comparison + while ( cur ) { + ap.unshift( cur ); + cur = cur.parentNode; + } + + cur = bup; + + while ( cur ) { + bp.unshift( cur ); + cur = cur.parentNode; + } + + al = ap.length; + bl = bp.length; + + // Start walking down the tree looking for a discrepancy + for ( var i = 0; i < al && i < bl; i++ ) { + if ( ap[i] !== bp[i] ) { + return siblingCheck( ap[i], bp[i] ); + } + } + + // We ended someplace up the tree so do a sibling check + return i === al ? + siblingCheck( a, bp[i], -1 ) : + siblingCheck( ap[i], b, 1 ); + }; + + siblingCheck = function( a, b, ret ) { + if ( a === b ) { + return ret; + } + + var cur = a.nextSibling; + + while ( cur ) { + if ( cur === b ) { + return -1; + } + + cur = cur.nextSibling; + } + + return 1; + }; +} + +// Check to see if the browser returns elements by name when +// querying by getElementById (and provide a workaround) +(function(){ + // We're going to inject a fake input element with a specified name + var form = document.createElement("div"), + id = "script" + (new Date()).getTime(), + root = document.documentElement; + + form.innerHTML = ""; + + // Inject it into the root element, check its status, and remove it quickly + root.insertBefore( form, root.firstChild ); + + // The workaround has to do additional checks after a getElementById + // Which slows things down for other browsers (hence the branching) + if ( document.getElementById( id ) ) { + Expr.find.ID = function( match, context, isXML ) { + if ( typeof context.getElementById !== "undefined" && !isXML ) { + var m = context.getElementById(match[1]); + + return m ? + m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? + [m] : + undefined : + []; + } + }; + + Expr.filter.ID = function( elem, match ) { + var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); + + return elem.nodeType === 1 && node && node.nodeValue === match; + }; + } + + root.removeChild( form ); + + // release memory in IE + root = form = null; +})(); + +(function(){ + // Check to see if the browser returns only elements + // when doing getElementsByTagName("*") + + // Create a fake element + var div = document.createElement("div"); + div.appendChild( document.createComment("") ); + + // Make sure no comments are found + if ( div.getElementsByTagName("*").length > 0 ) { + Expr.find.TAG = function( match, context ) { + var results = context.getElementsByTagName( match[1] ); + + // Filter out possible comments + if ( match[1] === "*" ) { + var tmp = []; + + for ( var i = 0; results[i]; i++ ) { + if ( results[i].nodeType === 1 ) { + tmp.push( results[i] ); + } + } + + results = tmp; + } + + return results; + }; + } + + // Check to see if an attribute returns normalized href attributes + div.innerHTML = ""; + + if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && + div.firstChild.getAttribute("href") !== "#" ) { + + Expr.attrHandle.href = function( elem ) { + return elem.getAttribute( "href", 2 ); + }; + } + + // release memory in IE + div = null; +})(); + +if ( document.querySelectorAll ) { + (function(){ + var oldSizzle = Sizzle, + div = document.createElement("div"), + id = "__sizzle__"; + + div.innerHTML = "

"; + + // Safari can't handle uppercase or unicode characters when + // in quirks mode. + if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { + return; + } + + Sizzle = function( query, context, extra, seed ) { + context = context || document; + + // Only use querySelectorAll on non-XML documents + // (ID selectors don't work in non-HTML documents) + if ( !seed && !Sizzle.isXML(context) ) { + // See if we find a selector to speed up + var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query ); + + if ( match && (context.nodeType === 1 || context.nodeType === 9) ) { + // Speed-up: Sizzle("TAG") + if ( match[1] ) { + return makeArray( context.getElementsByTagName( query ), extra ); + + // Speed-up: Sizzle(".CLASS") + } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) { + return makeArray( context.getElementsByClassName( match[2] ), extra ); + } + } + + if ( context.nodeType === 9 ) { + // Speed-up: Sizzle("body") + // The body element only exists once, optimize finding it + if ( query === "body" && context.body ) { + return makeArray( [ context.body ], extra ); + + // Speed-up: Sizzle("#ID") + } else if ( match && match[3] ) { + var elem = context.getElementById( match[3] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id === match[3] ) { + return makeArray( [ elem ], extra ); + } + + } else { + return makeArray( [], extra ); + } + } + + try { + return makeArray( context.querySelectorAll(query), extra ); + } catch(qsaError) {} + + // qSA works strangely on Element-rooted queries + // We can work around this by specifying an extra ID on the root + // and working up from there (Thanks to Andrew Dupont for the technique) + // IE 8 doesn't work on object elements + } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { + var oldContext = context, + old = context.getAttribute( "id" ), + nid = old || id, + hasParent = context.parentNode, + relativeHierarchySelector = /^\s*[+~]/.test( query ); + + if ( !old ) { + context.setAttribute( "id", nid ); + } else { + nid = nid.replace( /'/g, "\\$&" ); + } + if ( relativeHierarchySelector && hasParent ) { + context = context.parentNode; + } + + try { + if ( !relativeHierarchySelector || hasParent ) { + return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra ); + } + + } catch(pseudoError) { + } finally { + if ( !old ) { + oldContext.removeAttribute( "id" ); + } + } + } + } + + return oldSizzle(query, context, extra, seed); + }; + + for ( var prop in oldSizzle ) { + Sizzle[ prop ] = oldSizzle[ prop ]; + } + + // release memory in IE + div = null; + })(); +} + +(function(){ + var html = document.documentElement, + matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector; + + if ( matches ) { + // Check to see if it's possible to do matchesSelector + // on a disconnected node (IE 9 fails this) + var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ), + pseudoWorks = false; + + try { + // This should fail with an exception + // Gecko does not error, returns false instead + matches.call( document.documentElement, "[test!='']:sizzle" ); + + } catch( pseudoError ) { + pseudoWorks = true; + } + + Sizzle.matchesSelector = function( node, expr ) { + // Make sure that attribute selectors are quoted + expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']"); + + if ( !Sizzle.isXML( node ) ) { + try { + if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) { + var ret = matches.call( node, expr ); + + // IE 9's matchesSelector returns false on disconnected nodes + if ( ret || !disconnectedMatch || + // As well, disconnected nodes are said to be in a document + // fragment in IE 9, so check for that + node.document && node.document.nodeType !== 11 ) { + return ret; + } + } + } catch(e) {} + } + + return Sizzle(expr, null, null, [node]).length > 0; + }; + } +})(); + +(function(){ + var div = document.createElement("div"); + + div.innerHTML = "
"; + + // Opera can't find a second classname (in 9.6) + // Also, make sure that getElementsByClassName actually exists + if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { + return; + } + + // Safari caches class attributes, doesn't catch changes (in 3.2) + div.lastChild.className = "e"; + + if ( div.getElementsByClassName("e").length === 1 ) { + return; + } + + Expr.order.splice(1, 0, "CLASS"); + Expr.find.CLASS = function( match, context, isXML ) { + if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { + return context.getElementsByClassName(match[1]); + } + }; + + // release memory in IE + div = null; +})(); + +function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + + if ( elem ) { + var match = false; + + elem = elem[dir]; + + while ( elem ) { + if ( elem[ expando ] === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 && !isXML ){ + elem[ expando ] = doneName; + elem.sizset = i; + } + + if ( elem.nodeName.toLowerCase() === cur ) { + match = elem; + break; + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + + if ( elem ) { + var match = false; + + elem = elem[dir]; + + while ( elem ) { + if ( elem[ expando ] === doneName ) { + match = checkSet[elem.sizset]; + break; + } + + if ( elem.nodeType === 1 ) { + if ( !isXML ) { + elem[ expando ] = doneName; + elem.sizset = i; + } + + if ( typeof cur !== "string" ) { + if ( elem === cur ) { + match = true; + break; + } + + } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { + match = elem; + break; + } + } + + elem = elem[dir]; + } + + checkSet[i] = match; + } + } +} + +if ( document.documentElement.contains ) { + Sizzle.contains = function( a, b ) { + return a !== b && (a.contains ? a.contains(b) : true); + }; + +} else if ( document.documentElement.compareDocumentPosition ) { + Sizzle.contains = function( a, b ) { + return !!(a.compareDocumentPosition(b) & 16); + }; + +} else { + Sizzle.contains = function() { + return false; + }; +} + +Sizzle.isXML = function( elem ) { + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; + + return documentElement ? documentElement.nodeName !== "HTML" : false; +}; + +var posProcess = function( selector, context, seed ) { + var match, + tmpSet = [], + later = "", + root = context.nodeType ? [context] : context; + + // Position selectors must be done after the filter + // And so must :not(positional) so we move all PSEUDOs to the end + while ( (match = Expr.match.PSEUDO.exec( selector )) ) { + later += match[0]; + selector = selector.replace( Expr.match.PSEUDO, "" ); + } + + selector = Expr.relative[selector] ? selector + "*" : selector; + + for ( var i = 0, l = root.length; i < l; i++ ) { + Sizzle( selector, root[i], tmpSet, seed ); + } + + return Sizzle.filter( later, tmpSet ); +}; + +// EXPOSE +// Override sizzle attribute retrieval +Sizzle.attr = jQuery.attr; +Sizzle.selectors.attrMap = {}; +jQuery.find = Sizzle; +jQuery.expr = Sizzle.selectors; +jQuery.expr[":"] = jQuery.expr.filters; +jQuery.unique = Sizzle.uniqueSort; +jQuery.text = Sizzle.getText; +jQuery.isXMLDoc = Sizzle.isXML; +jQuery.contains = Sizzle.contains; + + +})(); + + +var runtil = /Until$/, + rparentsprev = /^(?:parents|prevUntil|prevAll)/, + // Note: This RegExp should be improved, or likely pulled from Sizzle + rmultiselector = /,/, + isSimple = /^.[^:#\[\.,]*$/, + slice = Array.prototype.slice, + POS = jQuery.expr.match.globalPOS, + // methods guaranteed to produce a unique set when starting from a unique set + guaranteedUnique = { + children: true, + contents: true, + next: true, + prev: true + }; + +jQuery.fn.extend({ + find: function( selector ) { + var self = this, + i, l; + + if ( typeof selector !== "string" ) { + return jQuery( selector ).filter(function() { + for ( i = 0, l = self.length; i < l; i++ ) { + if ( jQuery.contains( self[ i ], this ) ) { + return true; + } + } + }); + } + + var ret = this.pushStack( "", "find", selector ), + length, n, r; + + for ( i = 0, l = this.length; i < l; i++ ) { + length = ret.length; + jQuery.find( selector, this[i], ret ); + + if ( i > 0 ) { + // Make sure that the results are unique + for ( n = length; n < ret.length; n++ ) { + for ( r = 0; r < length; r++ ) { + if ( ret[r] === ret[n] ) { + ret.splice(n--, 1); + break; + } + } + } + } + } + + return ret; + }, + + has: function( target ) { + var targets = jQuery( target ); + return this.filter(function() { + for ( var i = 0, l = targets.length; i < l; i++ ) { + if ( jQuery.contains( this, targets[i] ) ) { + return true; + } + } + }); + }, + + not: function( selector ) { + return this.pushStack( winnow(this, selector, false), "not", selector); + }, + + filter: function( selector ) { + return this.pushStack( winnow(this, selector, true), "filter", selector ); + }, + + is: function( selector ) { + return !!selector && ( + typeof selector === "string" ? + // If this is a positional selector, check membership in the returned set + // so $("p:first").is("p:last") won't return true for a doc with two "p". + POS.test( selector ) ? + jQuery( selector, this.context ).index( this[0] ) >= 0 : + jQuery.filter( selector, this ).length > 0 : + this.filter( selector ).length > 0 ); + }, + + closest: function( selectors, context ) { + var ret = [], i, l, cur = this[0]; + + // Array (deprecated as of jQuery 1.7) + if ( jQuery.isArray( selectors ) ) { + var level = 1; + + while ( cur && cur.ownerDocument && cur !== context ) { + for ( i = 0; i < selectors.length; i++ ) { + + if ( jQuery( cur ).is( selectors[ i ] ) ) { + ret.push({ selector: selectors[ i ], elem: cur, level: level }); + } + } + + cur = cur.parentNode; + level++; + } + + return ret; + } + + // String + var pos = POS.test( selectors ) || typeof selectors !== "string" ? + jQuery( selectors, context || this.context ) : + 0; + + for ( i = 0, l = this.length; i < l; i++ ) { + cur = this[i]; + + while ( cur ) { + if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) { + ret.push( cur ); + break; + + } else { + cur = cur.parentNode; + if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) { + break; + } + } + } + } + + ret = ret.length > 1 ? jQuery.unique( ret ) : ret; + + return this.pushStack( ret, "closest", selectors ); + }, + + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + + // No argument, return index in parent + if ( !elem ) { + return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1; + } + + // index in selector + if ( typeof elem === "string" ) { + return jQuery.inArray( this[0], jQuery( elem ) ); + } + + // Locate the position of the desired element + return jQuery.inArray( + // If it receives a jQuery object, the first element is used + elem.jquery ? elem[0] : elem, this ); + }, + + add: function( selector, context ) { + var set = typeof selector === "string" ? + jQuery( selector, context ) : + jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ), + all = jQuery.merge( this.get(), set ); + + return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ? + all : + jQuery.unique( all ) ); + }, + + andSelf: function() { + return this.add( this.prevObject ); + } +}); + +// A painfully simple check to see if an element is disconnected +// from a document (should be improved, where feasible). +function isDisconnected( node ) { + return !node || !node.parentNode || node.parentNode.nodeType === 11; +} + +jQuery.each({ + parent: function( elem ) { + var parent = elem.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; + }, + parents: function( elem ) { + return jQuery.dir( elem, "parentNode" ); + }, + parentsUntil: function( elem, i, until ) { + return jQuery.dir( elem, "parentNode", until ); + }, + next: function( elem ) { + return jQuery.nth( elem, 2, "nextSibling" ); + }, + prev: function( elem ) { + return jQuery.nth( elem, 2, "previousSibling" ); + }, + nextAll: function( elem ) { + return jQuery.dir( elem, "nextSibling" ); + }, + prevAll: function( elem ) { + return jQuery.dir( elem, "previousSibling" ); + }, + nextUntil: function( elem, i, until ) { + return jQuery.dir( elem, "nextSibling", until ); + }, + prevUntil: function( elem, i, until ) { + return jQuery.dir( elem, "previousSibling", until ); + }, + siblings: function( elem ) { + return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); + }, + children: function( elem ) { + return jQuery.sibling( elem.firstChild ); + }, + contents: function( elem ) { + return jQuery.nodeName( elem, "iframe" ) ? + elem.contentDocument || elem.contentWindow.document : + jQuery.makeArray( elem.childNodes ); + } +}, function( name, fn ) { + jQuery.fn[ name ] = function( until, selector ) { + var ret = jQuery.map( this, fn, until ); + + if ( !runtil.test( name ) ) { + selector = until; + } + + if ( selector && typeof selector === "string" ) { + ret = jQuery.filter( selector, ret ); + } + + ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret; + + if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) { + ret = ret.reverse(); + } + + return this.pushStack( ret, name, slice.call( arguments ).join(",") ); + }; +}); + +jQuery.extend({ + filter: function( expr, elems, not ) { + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return elems.length === 1 ? + jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] : + jQuery.find.matches(expr, elems); + }, + + dir: function( elem, dir, until ) { + var matched = [], + cur = elem[ dir ]; + + while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { + if ( cur.nodeType === 1 ) { + matched.push( cur ); + } + cur = cur[dir]; + } + return matched; + }, + + nth: function( cur, result, dir, elem ) { + result = result || 1; + var num = 0; + + for ( ; cur; cur = cur[dir] ) { + if ( cur.nodeType === 1 && ++num === result ) { + break; + } + } + + return cur; + }, + + sibling: function( n, elem ) { + var r = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType === 1 && n !== elem ) { + r.push( n ); + } + } + + return r; + } +}); + +// Implement the identical functionality for filter and not +function winnow( elements, qualifier, keep ) { + + // Can't pass null or undefined to indexOf in Firefox 4 + // Set to 0 to skip string check + qualifier = qualifier || 0; + + if ( jQuery.isFunction( qualifier ) ) { + return jQuery.grep(elements, function( elem, i ) { + var retVal = !!qualifier.call( elem, i, elem ); + return retVal === keep; + }); + + } else if ( qualifier.nodeType ) { + return jQuery.grep(elements, function( elem, i ) { + return ( elem === qualifier ) === keep; + }); + + } else if ( typeof qualifier === "string" ) { + var filtered = jQuery.grep(elements, function( elem ) { + return elem.nodeType === 1; + }); + + if ( isSimple.test( qualifier ) ) { + return jQuery.filter(qualifier, filtered, !keep); + } else { + qualifier = jQuery.filter( qualifier, filtered ); + } + } + + return jQuery.grep(elements, function( elem, i ) { + return ( jQuery.inArray( elem, qualifier ) >= 0 ) === keep; + }); +} + + + + +function createSafeFragment( document ) { + var list = nodeNames.split( "|" ), + safeFrag = document.createDocumentFragment(); + + if ( safeFrag.createElement ) { + while ( list.length ) { + safeFrag.createElement( + list.pop() + ); + } + } + return safeFrag; +} + +var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + + "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", + rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, + rleadingWhitespace = /^\s+/, + rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, + rtagName = /<([\w:]+)/, + rtbody = /]", "i"), + // checked="checked" or checked + rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, + rscriptType = /\/(java|ecma)script/i, + rcleanScript = /^\s*", "" ], + legend: [ 1, "
", "
" ], + thead: [ 1, "", "
" ], + tr: [ 2, "", "
" ], + td: [ 3, "", "
" ], + col: [ 2, "", "
" ], + area: [ 1, "", "" ], + _default: [ 0, "", "" ] + }, + safeFragment = createSafeFragment( document ); + +wrapMap.optgroup = wrapMap.option; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.th = wrapMap.td; + +// IE can't serialize and