Merge branch 'bb-10.0-serg' into 10.0

This commit is contained in:
Sergei Golubchik 2016-08-14 09:16:07 +02:00
commit 47a1087ff6
291 changed files with 4160 additions and 3645 deletions

View File

@ -240,7 +240,7 @@ static int process_selected_tables(char *db, char **table_names, int tables);
static int process_all_tables_in_db(char *database);
static int process_one_db(char *database);
static int use_db(char *database);
static int handle_request_for_tables(char *tables, size_t length, my_bool view);
static int handle_request_for_tables(char *, size_t, my_bool, my_bool);
static int dbConnect(char *host, char *user,char *passwd);
static void dbDisconnect(char *host);
static void DBerror(MYSQL *mysql, const char *when);
@ -577,7 +577,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
}
*--end = 0;
handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1,
opt_do_views != 0);
opt_do_views != 0, opt_all_in_1);
my_free(table_names_comma_sep);
}
else
@ -588,7 +588,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
view= is_view(table);
if (view < 0)
continue;
handle_request_for_tables(table, table_len, (view == 1));
handle_request_for_tables(table, table_len, view == 1, opt_all_in_1);
}
DBUG_RETURN(0);
} /* process_selected_tables */
@ -616,13 +616,9 @@ static char *fix_table_name(char *dest, char *src)
*dest++= '`';
for (; *src; src++)
{
switch (*src) {
case '`': /* escape backtick character */
if (*src == '`')
*dest++= '`';
/* fall through */
default:
*dest++= *src;
}
*dest++= *src;
}
*dest++= '`';
@ -711,9 +707,9 @@ static int process_all_tables_in_db(char *database)
*--end = 0;
*--views_end = 0;
if (tot_length)
handle_request_for_tables(tables + 1, tot_length - 1, FALSE);
handle_request_for_tables(tables + 1, tot_length - 1, FALSE, opt_all_in_1);
if (tot_views_length)
handle_request_for_tables(views + 1, tot_views_length - 1, TRUE);
handle_request_for_tables(views + 1, tot_views_length - 1, TRUE, opt_all_in_1);
my_free(tables);
my_free(views);
}
@ -739,7 +735,7 @@ static int process_all_tables_in_db(char *database)
!strcmp(row[0], "slow_log")))
continue; /* Skip logging tables */
handle_request_for_tables(row[0], fixed_name_length(row[0]), view);
handle_request_for_tables(row[0], fixed_name_length(row[0]), view, opt_all_in_1);
}
}
mysql_free_result(res);
@ -800,13 +796,11 @@ static int rebuild_table(char *name)
int rc= 0;
DBUG_ENTER("rebuild_table");
query= (char*)my_malloc(sizeof(char) * (12 + fixed_name_length(name) + 6 + 1),
query= (char*)my_malloc(sizeof(char) * (12 + strlen(name) + 6 + 1),
MYF(MY_WME));
if (!query)
DBUG_RETURN(1);
ptr= strmov(query, "ALTER TABLE ");
ptr= fix_table_name(ptr, name);
ptr= strxmov(ptr, " FORCE", NullS);
ptr= strxmov(query, "ALTER TABLE ", name, " FORCE", NullS);
if (verbose >= 3)
puts(query);
if (mysql_real_query(sock, query, (ulong)(ptr - query)))
@ -869,7 +863,8 @@ static int disable_binlog()
return run_query(stmt, 0);
}
static int handle_request_for_tables(char *tables, size_t length, my_bool view)
static int handle_request_for_tables(char *tables, size_t length,
my_bool view, my_bool dont_quote)
{
char *query, *end, options[100], message[100];
char table_name_buff[NAME_CHAR_LEN*2*2+1], *table_name;
@ -928,7 +923,7 @@ static int handle_request_for_tables(char *tables, size_t length, my_bool view)
if (!(query =(char *) my_malloc(query_size, MYF(MY_WME))))
DBUG_RETURN(1);
if (opt_all_in_1)
if (dont_quote)
{
DBUG_ASSERT(strlen(op)+strlen(tables)+strlen(options)+8+1 <= query_size);
@ -973,6 +968,13 @@ static int handle_request_for_tables(char *tables, size_t length, my_bool view)
DBUG_RETURN(0);
}
static void insert_table_name(DYNAMIC_ARRAY *arr, char *in, size_t dblen)
{
char buf[NAME_LEN*2+2];
in[dblen]= 0;
my_snprintf(buf, sizeof(buf), "%`s.%`s", in, in + dblen + 1);
insert_dynamic(arr, (uchar*) buf);
}
static void print_result()
{
@ -980,16 +982,13 @@ static void print_result()
MYSQL_ROW row;
char prev[(NAME_LEN+9)*3+2];
char prev_alter[MAX_ALTER_STR_SIZE];
char *db_name;
uint length_of_db;
size_t length_of_db= strlen(sock->db);
uint i;
my_bool found_error=0, table_rebuild=0;
DYNAMIC_ARRAY *array4repair= &tables4repair;
DBUG_ENTER("print_result");
res = mysql_use_result(sock);
db_name= sock->db;
length_of_db= strlen(db_name);
prev[0] = '\0';
prev_alter[0]= 0;
@ -1013,16 +1012,10 @@ static void print_result()
if (prev_alter[0])
insert_dynamic(&alter_table_cmds, (uchar*) prev_alter);
else
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4rebuild, (uchar*) table_name);
}
insert_table_name(&tables4rebuild, prev, length_of_db);
}
else
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(array4repair, table_name);
}
insert_table_name(array4repair, prev, length_of_db);
}
array4repair= &tables4repair;
found_error=0;
@ -1067,16 +1060,10 @@ static void print_result()
if (prev_alter[0])
insert_dynamic(&alter_table_cmds, prev_alter);
else
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4rebuild, table_name);
}
insert_table_name(&tables4rebuild, prev, length_of_db);
}
else
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(array4repair, table_name);
}
insert_table_name(array4repair, prev, length_of_db);
}
mysql_free_result(res);
DBUG_VOID_RETURN;
@ -1221,7 +1208,7 @@ int main(int argc, char **argv)
for (i = 0; i < tables4repair.elements ; i++)
{
char *name= (char*) dynamic_array_ptr(&tables4repair, i);
handle_request_for_tables(name, fixed_name_length(name), FALSE);
handle_request_for_tables(name, fixed_name_length(name), FALSE, TRUE);
}
for (i = 0; i < tables4rebuild.elements ; i++)
rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i));
@ -1232,7 +1219,7 @@ int main(int argc, char **argv)
for (i = 0; i < views4repair.elements ; i++)
{
char *name= (char*) dynamic_array_ptr(&views4repair, i);
handle_request_for_tables(name, fixed_name_length(name), TRUE);
handle_request_for_tables(name, fixed_name_length(name), TRUE, TRUE);
}
}
ret= MY_TEST(first_error);

View File

@ -37,6 +37,7 @@
/* Global Thread counter */
uint counter= 0;
pthread_mutex_t init_mutex;
pthread_mutex_t counter_mutex;
pthread_cond_t count_threshhold;
@ -421,8 +422,19 @@ static MYSQL *db_connect(char *host, char *database,
MYSQL *mysql;
if (verbose)
fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
if (!(mysql= mysql_init(NULL)))
return 0;
if (opt_use_threads && !lock_tables)
{
pthread_mutex_lock(&init_mutex);
if (!(mysql= mysql_init(NULL)))
{
pthread_mutex_unlock(&init_mutex);
return 0;
}
pthread_mutex_unlock(&init_mutex);
}
else
if (!(mysql= mysql_init(NULL)))
return 0;
if (opt_compress)
mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
if (opt_local_file)
@ -614,7 +626,7 @@ error:
pthread_cond_signal(&count_threshhold);
pthread_mutex_unlock(&counter_mutex);
mysql_thread_end();
pthread_exit(0);
return 0;
}
@ -638,15 +650,31 @@ int main(int argc, char **argv)
if (opt_use_threads && !lock_tables)
{
pthread_t mainthread; /* Thread descriptor */
pthread_attr_t attr; /* Thread attributes */
char **save_argv;
uint worker_thread_count= 0, table_count= 0, i= 0;
pthread_t *worker_threads; /* Thread descriptor */
pthread_attr_t attr; /* Thread attributes */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,
PTHREAD_CREATE_DETACHED);
PTHREAD_CREATE_JOINABLE);
pthread_mutex_init(&init_mutex, NULL);
pthread_mutex_init(&counter_mutex, NULL);
pthread_cond_init(&count_threshhold, NULL);
/* Count the number of tables. This number denotes the total number
of threads spawn.
*/
save_argv= argv;
for (table_count= 0; *argv != NULL; argv++)
table_count++;
argv= save_argv;
if (!(worker_threads= (pthread_t*) my_malloc(table_count *
sizeof(*worker_threads),
MYF(0))))
return -2;
for (counter= 0; *argv != NULL; argv++) /* Loop through tables */
{
pthread_mutex_lock(&counter_mutex);
@ -661,15 +689,16 @@ int main(int argc, char **argv)
counter++;
pthread_mutex_unlock(&counter_mutex);
/* now create the thread */
if (pthread_create(&mainthread, &attr, worker_thread,
(void *)*argv) != 0)
if (pthread_create(&worker_threads[worker_thread_count], &attr,
worker_thread, (void *)*argv) != 0)
{
pthread_mutex_lock(&counter_mutex);
counter--;
pthread_mutex_unlock(&counter_mutex);
fprintf(stderr,"%s: Could not create thread\n",
my_progname);
fprintf(stderr,"%s: Could not create thread\n", my_progname);
continue;
}
worker_thread_count++;
}
/*
@ -684,9 +713,18 @@ int main(int argc, char **argv)
pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
}
pthread_mutex_unlock(&counter_mutex);
pthread_mutex_destroy(&init_mutex);
pthread_mutex_destroy(&counter_mutex);
pthread_cond_destroy(&count_threshhold);
pthread_attr_destroy(&attr);
for(i= 0; i < worker_thread_count; i++)
{
if (pthread_join(worker_threads[i], NULL))
fprintf(stderr,"%s: Could not join worker thread.\n", my_progname);
}
my_free(worker_threads);
}
else
{

View File

@ -1,12 +0,0 @@
#
# show server variables
#
--disable_query_log
--echo ===== ENGINES =====
show engines;
--echo ===== VARIABLES =====
show variables;
--echo ===== STOP =====
--enable_query_log
exit;

View File

@ -279,7 +279,6 @@ my $opt_port_base= $ENV{'MTR_PORT_BASE'} || "auto";
my $build_thread= 0;
my $opt_record;
my $opt_report_features;
our $opt_resfile= $ENV{'MTR_RESULT_FILE'} || 0;
@ -434,21 +433,6 @@ sub main {
exit 0;
}
if ( $opt_report_features ) {
# Put "report features" as the first test to run
my $tinfo = My::Test->new
(
name => 'report_features',
# No result_file => Prints result
path => 'include/report-features.test',
template_path => "include/default_my.cnf",
master_opt => [],
slave_opt => [],
suite => 'main',
);
unshift(@$tests, $tinfo);
}
#######################################################################
my $num_tests= @$tests;
if ( $opt_parallel eq "auto" ) {
@ -1214,7 +1198,6 @@ sub command_line_setup {
'client-libdir=s' => \$path_client_libdir,
# Misc
'report-features' => \$opt_report_features,
'comment=s' => \$opt_comment,
'fast' => \$opt_fast,
'force-restart' => \$opt_force_restart,
@ -6634,7 +6617,6 @@ Misc options
gprof Collect profiling information using gprof.
experimental=<file> Refer to list of tests considered experimental;
failures will be marked exp-fail instead of fail.
report-features First run a "test" that reports mysql features
timestamp Print timestamp before each test report line
timediff With --timestamp, also print time passed since
*previous* test started

View File

@ -2270,3 +2270,42 @@ t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
EXECUTE stmt;
t2_id GROUP_CONCAT(IF (t6.b, t6.f, t5.f) ORDER BY 1)
DROP TABLE t1,t2,t3,t4,t5,t6;
#
# MDEV-10500 CASE/IF Statement returns multiple values and shifts further result values to the next column
#
CREATE TABLE t1 (
id int not null AUTO_INCREMENT,
active bool not null,
data1 bigint,
data2 bigint,
data3 bigint,
primary key (id)
);
INSERT INTO t1 (active,data1,data2,data3) VALUES (1,null,100,200);
SELECT
CASE WHEN active THEN SUM(data1) END AS C_1,
SUM(data2) AS C_2,
SUM(data3) AS C_3
FROM t1;
C_1 C_2 C_3
NULL 100 200
SELECT
IF(active, SUM(data1), 5) AS C_1,
SUM(data2) AS C_2,
SUM(data3) AS C_3
FROM t1;
C_1 C_2 C_3
NULL 100 200
DROP TABLE t1;
#
# MDEV-10468 Assertion `nr >= 0.0' failed in Item_sum_std::val_real()
#
SELECT STDDEV_POP(f) FROM (SELECT "1e+309" AS f UNION SELECT "-1e+309" AS f) tbl;
STDDEV_POP(f)
1.7976931348623157e308
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: '1e+309'
Warning 1292 Truncated incorrect DOUBLE value: '-1e+309'
SELECT STDDEV(f) FROM (SELECT 1.7976931348623157e+308 AS f UNION SELECT -1.7976931348623157e+308 AS f) tbl;
STDDEV(f)
1.7976931348623157e308

View File

@ -777,12 +777,18 @@ select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
5.9 div 2 1.23456789e3 DIV 2 1.23456789e9 DIV 2 1.23456789e19 DIV 2
2 617 617283945 6172839450000000000
#
# MDEV-10467 Assertion `nr >= 0.0' failed in Item_sum_std::val_real()
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT STDDEV_SAMP(ROUND('0', 309)) FROM t1;
STDDEV_SAMP(ROUND('0', 309))
0
DROP TABLE t1;
#
# End of 5.5 tests
#
#
# Start of 10.0 tests
#
#
# MDEV-5781 Item_sum_std::val_real(): Assertion `nr >= 0.0' fails on query with STDDEV_POP, ROUND and variable
#
SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table;

View File

@ -571,6 +571,13 @@ AND 57813X540X1723 = 'Test';
N AVG
0 NULL
drop table t1;
SELECT NAME_CONST('a', -(1 OR 2)) OR 1;
ERROR HY000: Incorrect arguments to NAME_CONST
SELECT NAME_CONST('a', -(1 AND 2)) OR 1;
ERROR HY000: Incorrect arguments to NAME_CONST
SELECT NAME_CONST('a', -(1)) OR 1;
NAME_CONST('a', -(1)) OR 1
1
#
# End of 5.5 tests
#

View File

@ -507,7 +507,7 @@ DROP TABLE t1;
# Bug#11765139 58069: LOAD DATA INFILE: VALGRIND REPORTS INVALID MEMORY READS AND WRITES WITH U
#
CREATE TABLE t1(f1 INT);
SELECT 0xE1BB30 INTO OUTFILE 't1.dat';
SELECT 0xE1C330 INTO OUTFILE 't1.dat';
LOAD DATA INFILE 't1.dat' IGNORE INTO TABLE t1 CHARACTER SET utf8;
DROP TABLE t1;
#
@ -532,3 +532,27 @@ FIELDS TERMINATED BY 't' LINES TERMINATED BY '';
Got one of the listed errors
SET @@sql_mode= @old_mode;
DROP TABLE t1;
#
# Bug#23080148 - Backport of Bug#20683959.
# Bug#20683959 LOAD DATA INFILE IGNORES A SPECIFIC ROW SILENTLY
# UNDER DB CHARSET IS UTF8.
#
CREATE DATABASE d1 CHARSET latin1;
USE d1;
CREATE TABLE t1 (val TEXT);
LOAD DATA INFILE '../../std_data/bug20683959loaddata.txt' INTO TABLE t1;
SELECT COUNT(*) FROM t1;
COUNT(*)
1
SELECT HEX(val) FROM t1;
HEX(val)
C38322525420406E696F757A656368756E3A20E98198E2889AF58081AEE7B99DE4B88AE383A3E7B99DE69690F58087B3E7B9A7EFBDA8E7B99DEFBDB3E7B99DE78999E880B3E7B8BAEFBDAAE7B9A7E89699E296A1E7B8BAE4BBA3EFBD8CE7B8BAEFBDA9E7B8B2E2889AE38184E7B99DEFBDB3E7B99DE4B88AE383A3E7B99DE69690F58087B3E7B9A7EFBDA8E7B99DEFBDB3E7B99DE5B3A8EFBD84E8ABA0EFBDA8E89C89F580948EE599AAE7B8BAEFBDAAE7B8BAE9A198EFBDA9EFBDB1E7B9A7E581B5E289A0E7B8BAEFBDBEE7B9A7E9A194EFBDA9E882B4EFBDA5EFBDB5E980A7F5808B96E28693E99EABE38287E58F99E7B8BAE58AB1E28691E7B8BAF5808B9AE7828AE98095EFBDB1E7B8BAEFBDAFE7B8B2E288ABE6A89FE89EB3E6BA98F58081ADE88EA0EFBDBAE98095E6BA98F58081AEE89D93EFBDBAE8AD9BEFBDACE980A7F5808B96E28693E7B8BAF580918EE288AAE7B8BAE4B88AEFBC9EE7B8BAE4B99DE28691E7B8BAF5808B96EFBCA0E88DB3E6A68AEFBDB9EFBDB3E981B2E5B3A8E296A1E7B8BAE7A4BCE7828AE88DB3E6A68AEFBDB0EFBDBDE7B8BAA0E7B8BAE88B93EFBDBEE5B899EFBC9E
CREATE DATABASE d2 CHARSET utf8;
USE d2;
CREATE TABLE t1 (val TEXT);
LOAD DATA INFILE '../../std_data/bug20683959loaddata.txt' INTO TABLE t1;
ERROR HY000: Invalid utf8 character string: 'Ã"RT @niouzechun: \9058\221A'
DROP TABLE d1.t1, d2.t1;
DROP DATABASE d1;
DROP DATABASE d2;

View File

@ -0,0 +1,114 @@
CREATE TABLE t1 (
pk INT AUTO_INCREMENT,
i INT,
d DATE,
dt DATETIME,
v VARCHAR(1),
PRIMARY KEY (pk),
KEY (dt)
) ENGINE=MyISAM;
INSERT INTO t1 (i, d, dt, v) VALUES
(9, '2005-07-23', '2004-05-13 01:01:39', 't'),
(2, '2009-11-01', '2003-12-24 07:39:29', 'h'),
(6, NULL, '2008-07-03 05:32:22', 'l'),
(6, '2007-07-16', '2008-08-28 18:46:11', 'j'),
(5, NULL, '2001-07-12 21:27:00', 'h'),
(3, '2007-07-22', '1900-01-01 00:00:00', 'p'),
(2, '2000-11-21', '2007-05-25 11:58:54', 'g'),
(6, '1900-01-01', '2009-06-03 17:11:10', 'i'),
(2, '2008-02-10', '2001-06-15 16:20:07', 'p'),
(3, '2009-06-04', '1900-01-01 00:00:00', 'h'),
(9, '2007-04-25', '1900-01-01 00:00:00', 'e'),
(9, '2006-03-02', '1900-01-01 00:00:00', 'e'),
(1, '1900-01-01', '2002-11-08 09:33:27', 'u'),
(7, '2008-07-13', '2007-08-07 17:35:52', 'j'),
(0, '2004-11-12', '2006-05-01 00:00:00', 'e'),
(0, '1900-01-01', '2003-05-01 00:00:00', 'z'),
(1, '2009-09-02', '2007-02-12 09:30:49', 'w'),
(0, '2004-11-06', '1900-01-01 00:00:00', 't'),
(4, '2003-01-06', '2002-07-03 02:51:11', 'i'),
(6, '2006-01-14', '2008-02-26 04:57:32', 'i'),
(0, '2002-01-19', '2009-02-12 00:00:00', 'i'),
(8, '2007-02-12', '1900-01-01 00:00:00', 'b'),
(4, '1900-01-01', '2001-05-16 05:28:40', 'm'),
(2, '2005-07-16', NULL, 'j'),
(1, '2004-09-04', '2001-01-24 21:45:18', 'v'),
(3, '2009-07-01', NULL, NULL),
(2, '2009-07-21', '2002-07-24 00:00:00', 'h'),
(4, NULL, '2001-11-03 12:22:30', 'q'),
(1, '2002-06-22', '2008-06-17 03:17:59', 'f'),
(7, '2005-06-23', '2005-12-24 00:00:00', 'p'),
(6, '2001-05-20', '2008-10-23 00:00:00', NULL),
(3, '2001-10-01', '2000-10-12 16:32:35', 'o'),
(3, '2001-01-07', '2005-09-11 10:09:54', 'w'),
(6, '2007-11-02', '2009-09-10 01:44:18', 'l'),
(6, NULL, NULL, 'i'),
(9, NULL, '2002-05-18 15:21:55', 'd'),
(4, '2008-12-21', '2004-10-15 10:09:54', 'j'),
(6, '2003-10-05', '2009-07-13 03:51:02', 'e'),
(2, '2001-03-03', '1900-01-01 00:00:00', 'e'),
(2, '2007-04-04', '2001-11-08 21:14:52', 'q'),
(5, NULL, '2006-12-02 00:00:00', 'm'),
(0, '2009-01-04', '1900-01-01 00:00:00', NULL),
(8, '2008-04-03', '2005-01-01 11:55:18', 'q'),
(8, NULL, '2005-02-28 03:44:02', 'w'),
(0, '2003-08-22', NULL, 'c'),
(9, '1900-01-01', NULL, 'y'),
(NULL, NULL, '2006-08-25 16:28:09', 'g'),
(5, '2004-07-04', '2002-08-11 00:00:00', 'z'),
(1, '1900-01-01', '2007-07-22 21:19:18', 'm'),
(2, '2007-02-04', '2006-02-10 18:41:38', 't'),
(2, '1900-01-01', '2009-02-16 14:58:58', 'd'),
(7, '2001-03-14', '2007-08-14 00:00:00', 'h'),
(0, NULL, '1900-01-01 00:00:00', NULL),
(1, '2008-10-05', NULL, 'f'),
(6, '2001-11-25', '2008-12-03 06:59:23', 'l'),
(NULL, '2003-01-27', '2008-10-04 00:00:00', 'g'),
(8, '2008-08-08', '2009-07-07 07:00:21', 'v'),
(8, '2006-07-03', '2001-04-15 00:00:00', NULL),
(5, '2002-11-21', '2007-07-08 04:01:58', 'm'),
(5, '2006-04-08', '2007-09-23 00:01:35', 'i'),
(5, '2001-05-06', '2008-05-15 00:00:00', 'h'),
(7, '1900-01-01', '1900-01-01 00:00:00', 'u'),
(30, '2007-04-16', '2004-03-05 23:35:38', 'o'),
(NULL, '1900-01-01', '2007-08-25 01:32:47', 'z'),
(6, '2004-12-03', '1900-01-01 00:00:00', 'o'),
(8, '2001-06-23', '1900-01-01 00:00:00', 'f'),
(NULL, '2008-12-15', '2001-05-19 08:28:28', 'a'),
(9, '2000-02-15', '2009-09-03 06:07:22', 'd'),
(2, '2001-08-05', '2006-10-08 07:17:27', 'k'),
(5, '2004-01-17', '2003-09-06 20:36:01', 'd'),
(4, '2003-10-01', '2001-02-05 18:10:49', 'u'),
(4, '2003-07-28', '2001-01-07 16:11:37', 'h'),
(0, '1900-01-01', '2008-08-01 05:26:38', 'w'),
(9, '1900-01-01', '2001-05-08 00:00:00', 't'),
(1, '2000-04-17', '2008-07-10 21:26:28', 'i'),
(8, '2002-01-05', '2006-08-06 20:56:35', 'k'),
(9, '2001-04-10', '2003-02-17 00:00:00', 'z'),
(0, '2009-12-04', NULL, 'h'),
(7, NULL, '2004-10-27 00:29:57', 'h'),
(2, '2006-03-07', '2008-03-04 06:14:13', 'b'),
(0, '2001-10-15', '2001-03-17 00:00:00', 'm'),
(5, '1900-01-01', '2009-02-21 11:35:50', 'i'),
(4, NULL, '1900-01-01 00:00:00', 'w'),
(5, '2009-04-05', '1900-01-01 00:00:00', 'm'),
(6, '2001-03-19', '2001-04-12 00:00:00', 'q'),
(NULL, '2009-12-08', '2001-12-04 20:21:01', 'k'),
(2, '2005-02-09', '2001-05-27 08:41:01', 'l'),
(9, '2004-05-25', '2004-09-18 00:00:00', 'c'),
(3, '2005-01-17', '2002-09-12 11:18:48', 'd'),
(0, '2003-08-28', '1900-01-01 00:00:00', 'k'),
(6, '2006-10-11', '2003-10-28 03:31:02', 'a'),
(5, '1900-01-01', '2001-08-22 10:20:09', 'p'),
(8, '1900-01-01', '2008-04-24 00:00:00', 'o'),
(4, '2005-08-18', '2006-11-10 10:08:49', 'e'),
(NULL, '2007-03-12', '2007-10-16 00:00:00', 'n'),
(1, '2000-11-18', '2009-05-27 12:25:07', 't'),
(4, '2001-03-03', NULL, 'u'),
(3, '2003-09-11', '2001-09-10 18:10:10', 'f'),
(4, '2007-06-17', '1900-01-01 00:00:00', 't'),
(NULL, '2008-09-11', '2004-06-07 23:17:09', 'k');
ALTER TABLE t1 ADD UNIQUE KEY ind1 (pk, d, i, v);
ALTER TABLE t1 ADD UNIQUE KEY ind2 (d, v);
ERROR 23000: Duplicate entry '2008-09-11-k' for key 'ind2'
DROP TABLE t1;

View File

@ -343,10 +343,37 @@ DROP TABLE bug47205;
#
#MDEV-6128:[PATCH] mysqlcheck wrongly escapes '.' in table names
#
CREATE TABLE test.`t.1` (id int);
create table `t.1` (id int);
create view `v.1` as select 1;
mysqlcheck test t.1
test.t.1 OK
drop table test.`t.1`;
mysqlcheck --all-in-1 test t.1
test.t.1 OK
mysqlcheck --all-in-1 --databases --process-views test
test.t.1 OK
test.v.1 OK
create table `t.2`(a varchar(20) primary key) default character set utf8 collate utf8_general_ci engine=innodb;
flush table `t.2`;
mysqlcheck --check-upgrade --auto-repair test
test.t.1 OK
test.t.2
error : Table rebuild required. Please do "ALTER TABLE `t.2` FORCE" or dump/reload to fix it!
test.t.3 Needs upgrade
Repairing tables
test.t.3 OK
check table `t.1`, `t.2`, `t.3`;
Table Op Msg_type Msg_text
test.t.1 check status OK
test.t.2 check status OK
test.t.3 check status OK
check table `t.1`, `t.2`, `t.3` for upgrade;
Table Op Msg_type Msg_text
test.t.1 check status OK
test.t.2 check status OK
test.t.3 check status OK
drop view `v.1`;
drop table test.`t.1`, `t.2`, `t.3`;
#
# MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
#
@ -381,6 +408,57 @@ show tables;
Tables_in_test
t1`1
drop table `t1``1`;
call mtr.add_suppression("ha_myisam");
call mtr.add_suppression("Checking table");
create database mysqltest1;
create table mysqltest1.t1 (a int) engine=myisam;
create table t2 (a int);
check table mysqltest1.t1;
Table Op Msg_type Msg_text
mysqltest1.t1 check warning Size of datafile is: 4 Should be: 0
mysqltest1.t1 check error got error: 0 when reading datafile at record: 0
mysqltest1.t1 check error Corrupt
mtr.global_suppressions Table is already up to date
mtr.test_suppressions Table is already up to date
mysql.column_stats Table is already up to date
mysql.columns_priv Table is already up to date
mysql.db Table is already up to date
mysql.event Table is already up to date
mysql.func Table is already up to date
mysql.gtid_slave_pos Table is already up to date
mysql.help_category Table is already up to date
mysql.help_keyword Table is already up to date
mysql.help_relation Table is already up to date
mysql.help_topic Table is already up to date
mysql.host Table is already up to date
mysql.index_stats Table is already up to date
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.plugin Table is already up to date
mysql.proc Table is already up to date
mysql.procs_priv Table is already up to date
mysql.proxies_priv Table is already up to date
mysql.roles_mapping Table is already up to date
mysql.servers Table is already up to date
mysql.table_stats Table is already up to date
mysql.tables_priv Table is already up to date
mysql.time_zone Table is already up to date
mysql.time_zone_leap_second Table is already up to date
mysql.time_zone_name Table is already up to date
mysql.time_zone_transition Table is already up to date
mysql.time_zone_transition_type Table is already up to date
mysql.user Table is already up to date
mysqltest1.t1
warning : Table is marked as crashed
warning : Size of datafile is: 4 Should be: 0
error : got error: 0 when reading datafile at record: 0
error : Corrupt
test.t2 Table is already up to date
Repairing tables
mysqltest1.t1 OK
drop table t2;
drop database mysqltest1;
#
#MDEV-7384 [PATCH] add PERSISENT FOR ALL option to mysqlanalyze/mysqlcheck
#

View File

@ -2114,6 +2114,37 @@ a b
1 1
drop table t2;
#
# MDEV-10228: Delete missing rows with OR conditions
# (The example uses UPDATE, because UPDATE allows to use index hints
# and so it's possible to make an example that works with any storage
# engine)
#
CREATE TABLE t1 (
key1varchar varchar(14) NOT NULL,
key2int int(11) NOT NULL DEFAULT '0',
col1 int,
PRIMARY KEY (key1varchar,key2int),
KEY key1varchar (key1varchar),
KEY key2int (key2int)
) DEFAULT CHARSET=utf8;
insert into t1 values
('value1',0, 0),
('value1',1, 0),
('value1',1000685, 0),
('value1',1003560, 0),
('value1',1004807, 0);
update t1 force index (PRIMARY) set col1=12345
where (key1varchar='value1' AND (key2int <=1 OR key2int > 1));
# The following must show col1=12345 for all rows:
select * from t1;
key1varchar key2int col1
value1 0 12345
value1 1 12345
value1 1000685 12345
value1 1003560 12345
value1 1004807 12345
drop table t1;
#
# BUG#13731380: RANGE OPTIMIZER CALLS RECORDS_IN_RANGE() FOR OPEN RANGE
#
CREATE TABLE t1 (pk INT PRIMARY KEY);

View File

@ -2116,6 +2116,37 @@ a b
1 1
drop table t2;
#
# MDEV-10228: Delete missing rows with OR conditions
# (The example uses UPDATE, because UPDATE allows to use index hints
# and so it's possible to make an example that works with any storage
# engine)
#
CREATE TABLE t1 (
key1varchar varchar(14) NOT NULL,
key2int int(11) NOT NULL DEFAULT '0',
col1 int,
PRIMARY KEY (key1varchar,key2int),
KEY key1varchar (key1varchar),
KEY key2int (key2int)
) DEFAULT CHARSET=utf8;
insert into t1 values
('value1',0, 0),
('value1',1, 0),
('value1',1000685, 0),
('value1',1003560, 0),
('value1',1004807, 0);
update t1 force index (PRIMARY) set col1=12345
where (key1varchar='value1' AND (key2int <=1 OR key2int > 1));
# The following must show col1=12345 for all rows:
select * from t1;
key1varchar key2int col1
value1 0 12345
value1 1 12345
value1 1000685 12345
value1 1003560 12345
value1 1004807 12345
drop table t1;
#
# BUG#13731380: RANGE OPTIMIZER CALLS RECORDS_IN_RANGE() FOR OPEN RANGE
#
CREATE TABLE t1 (pk INT PRIMARY KEY);

View File

@ -320,3 +320,23 @@ c2
DROP TRIGGER t1_ai;
DROP TABLE t1, t2;
End of 5.0 tests
#
# Bug#21142859: FUNCTION UPDATING A VIEW FAILS TO FIND TABLE THAT ACTUALLY EXISTS
#
CREATE TABLE t1 SELECT 1 AS fld1, 'A' AS fld2;
CREATE TABLE t2 (fld3 INT, fld4 CHAR(1));
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE TRIGGER t1_au AFTER UPDATE ON t1
FOR EACH ROW INSERT INTO t2 VALUES (new.fld1, new.fld2);
CREATE FUNCTION f1() RETURNS INT
BEGIN
UPDATE v1 SET fld2='B' WHERE fld1=1;
RETURN row_count();
END !
# Without the patch, an error was getting reported.
SELECT f1();
f1()
1
DROP FUNCTION f1;
DROP VIEW v1;
DROP TABLE t1,t2;

View File

@ -165,6 +165,7 @@ str_to_date( '', a )
NULL
DROP TABLE t1;
CREATE TABLE t1 (a DATE, b INT, PRIMARY KEY (a,b));
SET timestamp=UNIX_TIMESTAMP('2016-07-21 14:48:18');
INSERT INTO t1 VALUES (DATE(NOW()), 1);
SELECT COUNT(*) FROM t1 WHERE a = NOW();
COUNT(*)
@ -192,6 +193,7 @@ COUNT(*)
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
SET timestamp=DEFAULT;
DROP TABLE t1;
CREATE TABLE t1 (a DATE);
CREATE TABLE t2 (a DATE);

View File

@ -5518,6 +5518,21 @@ test.v1 check Error 'test.v1' is not BASE TABLE
test.v1 check status Operation failed
drop view v1;
drop table t1;
#
# MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty
#
CREATE TABLE t1 (c1 CHAR(13));
CREATE TABLE t2 (c2 CHAR(13));
CREATE FUNCTION f() RETURNS INT RETURN 0;
CREATE OR REPLACE VIEW v1 AS select f() from t1 where c1 in (select c2 from t2);
DROP FUNCTION f;
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 `f`() AS `f()` from `t1` where `test`.`t1`.`c1` in (select `test`.`t2`.`c2` from `t2`) latin1 latin1_swedish_ci
Warnings:
Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop view v1;
drop table t1,t2;
# -----------------------------------------------------------------
# -- End of 5.5 tests.
# -----------------------------------------------------------------

View File

@ -311,10 +311,10 @@ concat('c-', 1000 + C.a, '-c'),
'filler'
from t1 A, t1 B, t1 C;
explain
select count(length(a) + length(filler)) from t2 where a>='a-1000-a' and a <'a-1001-a';
select count(length(a) + length(filler)) from t2 force index (a) where a>='a-1000-a' and a <'a-1001-a';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range a a 9 NULL 99 Using index condition; Rowid-ordered scan
select count(length(a) + length(filler)) from t2 where a>='a-1000-a' and a <'a-1001-a';
select count(length(a) + length(filler)) from t2 force index (a) where a>='a-1000-a' and a <'a-1001-a';
count(length(a) + length(filler))
100
drop table t2;

View File

@ -0,0 +1 @@
Ã"RT @niouzechun: 遘√<E98198><E2889A><EFBFBD><EFBFBD>繝上ャ繝斐<E7B99D><E69690><EFBFBD><EFBFBD>繧ィ繝ウ繝牙耳縺ェ繧薙□縺代縺ゥ縲√い繝ウ繝上ャ繝斐<E7B99D><E69690><EFBFBD><EFBFBD>繧ィ繝ウ繝峨諠ィ蜉<EFBDA8><E89C89><EFBFBD><EFBFBD>噪縺ェ縺願ゥア繧偵≠縺セ繧顔ゥ肴・オ逧<EFBDB5><E980A7><EFBFBD><EFBFBD>↓鞫ょ叙縺励↑縺<E28691><E7B8BA><EFBFBD><EFBFBD>炊逕ア縺ッ縲∫樟螳溘<E89EB3><E6BA98><EFBFBD><EFBFBD>莠コ逕溘<E98095><E6BA98><EFBFBD><EFBFBD>蝓コ譛ャ逧<EFBDAC><E980A7><EFBFBD><EFBFBD>↓縺<E28693><E7B8BA><EFBFBD><EFBFBD>縺上縺九↑縺<E28691><E7B8BA><EFBFBD><EFBFBD>荳榊ケウ遲峨□縺礼炊荳榊ース縺<EFBDBD>縺苓セ帙

View File

@ -0,0 +1,58 @@
DROP TABLE IF EXISTS t1 ;
# READ_ONLY does nothing to SUPER users
# so we use a non-SUPER one:
GRANT CREATE, SELECT, DROP ON *.* TO test@localhost;
connect con1,localhost,test,,test;
connection default;
SET GLOBAL READ_ONLY=1;
connection con1;
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=INNODB;
# Test INSERTS with autocommit being off and on.
BEGIN;
INSERT INTO t1 VALUES (10);
COMMIT;
INSERT INTO t1 VALUES (20);
# Test UPDATES with autocommit being off and on.
BEGIN;
UPDATE t1 SET a=30 WHERE a=10;
COMMIT;
UPDATE t1 SET a=40 WHERE a=20;
connection default;
SET GLOBAL READ_ONLY=0;
# Test scenario where global read_only is enabled in the middle of transaction.
# Test INSERT operations on temporary tables, INSERTs should be successful even
# when global read_only is enabled.
connection con1;
BEGIN;
INSERT INTO t1 VALUES(50);
connection default;
SET GLOBAL READ_ONLY=1;
connection con1;
SELECT @@GLOBAL.READ_ONLY;
@@GLOBAL.READ_ONLY
1
COMMIT;
connection default;
SET GLOBAL READ_ONLY=0;
# Test UPDATE operations on temporary tables, UPDATEs should be successful even
# when global read_only is enabled.
connection con1;
BEGIN;
UPDATE t1 SET a=60 WHERE a=50;
connection default;
SET GLOBAL READ_ONLY=1;
connection con1;
SELECT @@GLOBAL.READ_ONLY;
@@GLOBAL.READ_ONLY
1
COMMIT;
SELECT * FROM t1;
a
30
40
60
# Clean up
connection default;
SET GLOBAL READ_ONLY=0;
disconnect con1;
DROP USER test@localhost;

View File

@ -0,0 +1,91 @@
# ==== Purpose ====
#
# Check that DMLs are allowed on temporary tables, when server is in read only
# mode and binary log is enabled with binlog-format being stmt/mixed mode.
#
# ==== Implementation ====
#
# Start the server with binary log being enabled. Mark the server as read only.
# Create a non-SUPER user and let the user to create a temporary table and
# perform DML operations on that temporary table. DMLs should not be blocked
# with a 'server read-only mode' error.
#
# ==== References ====
#
# Bug#12818255: READ-ONLY OPTION DOES NOT ALLOW INSERTS/UPDATES ON TEMPORARY
# TABLES
# Bug#14294223: CHANGES NOT ALLOWED TO TEMPORARY TABLES ON READ-ONLY SERVERS
###############################################################################
--source include/have_log_bin.inc
--source include/have_innodb.inc
--disable_warnings
DROP TABLE IF EXISTS t1 ;
--enable_warnings
--enable_connect_log
--echo # READ_ONLY does nothing to SUPER users
--echo # so we use a non-SUPER one:
GRANT CREATE, SELECT, DROP ON *.* TO test@localhost;
connect (con1,localhost,test,,test);
connection default;
SET GLOBAL READ_ONLY=1;
connection con1;
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=INNODB;
--echo # Test INSERTS with autocommit being off and on.
BEGIN;
INSERT INTO t1 VALUES (10);
COMMIT;
INSERT INTO t1 VALUES (20);
--echo # Test UPDATES with autocommit being off and on.
BEGIN;
UPDATE t1 SET a=30 WHERE a=10;
COMMIT;
UPDATE t1 SET a=40 WHERE a=20;
connection default;
SET GLOBAL READ_ONLY=0;
--echo # Test scenario where global read_only is enabled in the middle of transaction.
--echo # Test INSERT operations on temporary tables, INSERTs should be successful even
--echo # when global read_only is enabled.
connection con1;
BEGIN;
INSERT INTO t1 VALUES(50);
connection default;
SET GLOBAL READ_ONLY=1;
connection con1;
SELECT @@GLOBAL.READ_ONLY;
COMMIT;
connection default;
SET GLOBAL READ_ONLY=0;
--echo # Test UPDATE operations on temporary tables, UPDATEs should be successful even
--echo # when global read_only is enabled.
connection con1;
BEGIN;
UPDATE t1 SET a=60 WHERE a=50;
connection default;
SET GLOBAL READ_ONLY=1;
connection con1;
SELECT @@GLOBAL.READ_ONLY;
COMMIT;
SELECT * FROM t1;
--echo # Clean up
connection default;
SET GLOBAL READ_ONLY=0;
disconnect con1;
DROP USER test@localhost;
--disable_connect_log

View File

@ -0,0 +1,56 @@
--- suite/innodb/r/innodb-wl5522.result
+++ suite/innodb/r/innodb-wl5522.reject
@@ -580,7 +580,7 @@
ERROR HY000: Tablespace has been discarded for table 't1'
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x5 and the meta-data file has 0x0)
+ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x1 and the meta-data file has 0x0)
unlink: t1.ibd
unlink: t1.cfg
DROP TABLE t1;
@@ -592,7 +592,7 @@
ERROR HY000: Tablespace has been discarded for table 't1'
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x5 and the meta-data file has 0x0)
+ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x21 and the meta-data file has 0x0)
unlink: t1.ibd
unlink: t1.cfg
DROP TABLE t1;
@@ -766,7 +766,7 @@
ERROR HY000: Tablespace has been discarded for table 't1'
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x5 and the meta-data file has 0x1)
+ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x0 and the meta-data file has 0x1)
unlink: t1.ibd
unlink: t1.cfg
DROP TABLE t1;
@@ -778,7 +778,7 @@
ERROR HY000: Tablespace has been discarded for table 't1'
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x5 and the meta-data file has 0x1)
+ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x21 and the meta-data file has 0x1)
unlink: t1.ibd
unlink: t1.cfg
DROP TABLE t1;
@@ -955,7 +955,7 @@
ERROR HY000: Tablespace has been discarded for table 't1'
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x5 and the meta-data file has 0x21)
+ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x1 and the meta-data file has 0x21)
unlink: t1.ibd
unlink: t1.cfg
DROP TABLE t1;
@@ -967,7 +967,7 @@
ERROR HY000: Tablespace has been discarded for table 't1'
restore: t1 .ibd and .cfg files
ALTER TABLE t1 IMPORT TABLESPACE;
-ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x5 and the meta-data file has 0x21)
+ERROR HY000: Schema mismatch (Table flags don't match, server table has 0x0 and the meta-data file has 0x21)
unlink: t1.ibd
unlink: t1.cfg
DROP TABLE t1;

View File

@ -5,6 +5,9 @@ grant proxy on pam_test to test_pam;
show variables like 'pam%';
Variable_name Value
pam_use_cleartext_plugin ON
#
# same test as in pam.test now fails
#
drop user test_pam;
drop user pam_test;
uninstall plugin pam;

View File

@ -29,5 +29,6 @@ EOF
--remove_file $MYSQLTEST_VARDIR/tmp/pam_bad.txt
drop user test_pam;
drop user pam_test;
let $count_sessions= 1;
--source include/wait_until_count_sessions.inc
uninstall plugin pam;

View File

@ -3,11 +3,22 @@
show variables like 'pam%';
--write_file $MYSQLTEST_VARDIR/tmp/pam_good.txt
not very secret challenge
9225
select user(), current_user(), database();
EOF
--echo #
--echo # same test as in pam.test now fails
--echo #
--error 1
--exec echo FAIL | $MYSQL_TEST -u test_pam --plugin-dir=$plugindir
--exec $MYSQL_TEST -u test_pam --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/pam_good.txt
--remove_file $MYSQLTEST_VARDIR/tmp/pam_good.txt
drop user test_pam;
drop user pam_test;
--disable_warnings
let $count_sessions= 1;
--source include/wait_until_count_sessions.inc
uninstall plugin pam;

View File

@ -12,6 +12,16 @@ SET @@global.general_log_file = mytest.log;
ERROR 42000: Incorrect argument type to variable 'general_log_file'
SET @@global.general_log_file = 12;
ERROR 42000: Incorrect argument type to variable 'general_log_file'
SET @@global.general_log_file = 'my.cnf';
ERROR 42000: Variable 'general_log_file' can't be set to the value of 'my.cnf'
SET @@global.general_log_file = '/tmp/my.cnf';
ERROR 42000: Variable 'general_log_file' can't be set to the value of '/tmp/my.cnf'
SET @@global.general_log_file = '.my.cnf';
ERROR 42000: Variable 'general_log_file' can't be set to the value of '.my.cnf'
SET @@global.general_log_file = 'my.cnf\0foo';
ERROR 42000: Variable 'general_log_file' can't be set to the value of 'my.cnf'
SET @@global.general_log_file = 'my.ini';
ERROR 42000: Variable 'general_log_file' can't be set to the value of 'my.ini'
'#----------------------FN_DYNVARS_004_03------------------------#'
SELECT @@global.general_log_file = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES

View File

@ -9,6 +9,16 @@ SET @@global.slow_query_log_file = mytest.log;
ERROR 42000: Incorrect argument type to variable 'slow_query_log_file'
SET @@global.slow_query_log_file = 12;
ERROR 42000: Incorrect argument type to variable 'slow_query_log_file'
SET @@global.slow_query_log_file = 'my.cnf';
ERROR 42000: Variable 'slow_query_log_file' can't be set to the value of 'my.cnf'
SET @@global.slow_query_log_file = '/tmp/my.cnf';
ERROR 42000: Variable 'slow_query_log_file' can't be set to the value of '/tmp/my.cnf'
SET @@global.general_log_file = '.my.cnf';
ERROR 42000: Variable 'general_log_file' can't be set to the value of '.my.cnf'
SET @@global.general_log_file = 'my.cnf\0foo';
ERROR 42000: Variable 'general_log_file' can't be set to the value of 'my.cnf'
SET @@global.general_log_file = 'my.ini';
ERROR 42000: Variable 'general_log_file' can't be set to the value of 'my.ini'
'#----------------------FN_DYNVARS_004_03------------------------#'
SELECT @@global.slow_query_log_file = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES

View File

@ -58,6 +58,20 @@ SET @@global.general_log_file = mytest.log;
--error ER_WRONG_TYPE_FOR_VAR
SET @@global.general_log_file = 12;
#
# MDEV-10465
#
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = 'my.cnf';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = '/tmp/my.cnf';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = '.my.cnf';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = 'my.cnf\0foo';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = 'my.ini';
--echo '#----------------------FN_DYNVARS_004_03------------------------#'
##############################################################################

View File

@ -56,6 +56,20 @@ SET @@global.slow_query_log_file = mytest.log;
--error ER_WRONG_TYPE_FOR_VAR
SET @@global.slow_query_log_file = 12;
#
# MDEV-10465
#
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.slow_query_log_file = 'my.cnf';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.slow_query_log_file = '/tmp/my.cnf';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = '.my.cnf';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = 'my.cnf\0foo';
--error ER_WRONG_VALUE_FOR_VAR
SET @@global.general_log_file = 'my.ini';
--echo '#----------------------FN_DYNVARS_004_03------------------------#'
##############################################################################
# Check if the value in GLOBAL Tables matches values in variable #

View File

@ -1565,3 +1565,34 @@ EXECUTE stmt;
EXECUTE stmt;
DROP TABLE t1,t2,t3,t4,t5,t6;
--echo #
--echo # MDEV-10500 CASE/IF Statement returns multiple values and shifts further result values to the next column
--echo #
CREATE TABLE t1 (
id int not null AUTO_INCREMENT,
active bool not null,
data1 bigint,
data2 bigint,
data3 bigint,
primary key (id)
);
INSERT INTO t1 (active,data1,data2,data3) VALUES (1,null,100,200);
SELECT
CASE WHEN active THEN SUM(data1) END AS C_1,
SUM(data2) AS C_2,
SUM(data3) AS C_3
FROM t1;
SELECT
IF(active, SUM(data1), 5) AS C_1,
SUM(data2) AS C_2,
SUM(data3) AS C_3
FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-10468 Assertion `nr >= 0.0' failed in Item_sum_std::val_real()
--echo #
SELECT STDDEV_POP(f) FROM (SELECT "1e+309" AS f UNION SELECT "-1e+309" AS f) tbl;
SELECT STDDEV(f) FROM (SELECT 1.7976931348623157e+308 AS f UNION SELECT -1.7976931348623157e+308 AS f) tbl;

View File

@ -578,11 +578,15 @@ select 5 div 2.0;
select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
--echo #
--echo # End of 5.5 tests
--echo # MDEV-10467 Assertion `nr >= 0.0' failed in Item_sum_std::val_real()
--echo #
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT STDDEV_SAMP(ROUND('0', 309)) FROM t1;
DROP TABLE t1;
--echo #
--echo # Start of 10.0 tests
--echo # End of 5.5 tests
--echo #
--echo #
@ -590,7 +594,6 @@ select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2;
--echo #
SELECT STDDEV_POP(ROUND(0,@A:=2009)) FROM (SELECT 1 UNION SELECT 2) fake_table;
--echo #
--echo # End of 10.0 tests
--echo #

View File

@ -596,6 +596,16 @@ AND 57813X540X1723 = 'Test';
drop table t1;
#
# Bug#12735545 - PARSER STACK OVERFLOW WITH NAME_CONST
# CONTAINING OR EXPRESSION
#
--error ER_WRONG_ARGUMENTS
SELECT NAME_CONST('a', -(1 OR 2)) OR 1;
--error ER_WRONG_ARGUMENTS
SELECT NAME_CONST('a', -(1 AND 2)) OR 1;
SELECT NAME_CONST('a', -(1)) OR 1;
--echo #
--echo # End of 5.5 tests
--echo #

View File

@ -612,7 +612,7 @@ disconnect con1;
--echo #
CREATE TABLE t1(f1 INT);
EVAL SELECT 0xE1BB30 INTO OUTFILE 't1.dat';
EVAL SELECT 0xE1C330 INTO OUTFILE 't1.dat';
--disable_warnings
LOAD DATA INFILE 't1.dat' IGNORE INTO TABLE t1 CHARACTER SET utf8;
--enable_warnings
@ -658,3 +658,26 @@ SET @@sql_mode= @old_mode;
--remove_file $MYSQLTEST_VARDIR/mysql
DROP TABLE t1;
--echo
--echo #
--echo # Bug#23080148 - Backport of Bug#20683959.
--echo # Bug#20683959 LOAD DATA INFILE IGNORES A SPECIFIC ROW SILENTLY
--echo # UNDER DB CHARSET IS UTF8.
--echo #
CREATE DATABASE d1 CHARSET latin1;
USE d1;
CREATE TABLE t1 (val TEXT);
LOAD DATA INFILE '../../std_data/bug20683959loaddata.txt' INTO TABLE t1;
SELECT COUNT(*) FROM t1;
SELECT HEX(val) FROM t1;
CREATE DATABASE d2 CHARSET utf8;
USE d2;
CREATE TABLE t1 (val TEXT);
--error ER_INVALID_CHARACTER_STRING
LOAD DATA INFILE '../../std_data/bug20683959loaddata.txt' INTO TABLE t1;
DROP TABLE d1.t1, d2.t1;
DROP DATABASE d1;
DROP DATABASE d2;

View File

@ -0,0 +1,117 @@
#
# MDEV-10506 Protocol::end_statement(): Assertion `0' failed upon ALTER TABLE
#
CREATE TABLE t1 (
pk INT AUTO_INCREMENT,
i INT,
d DATE,
dt DATETIME,
v VARCHAR(1),
PRIMARY KEY (pk),
KEY (dt)
) ENGINE=MyISAM;
INSERT INTO t1 (i, d, dt, v) VALUES
(9, '2005-07-23', '2004-05-13 01:01:39', 't'),
(2, '2009-11-01', '2003-12-24 07:39:29', 'h'),
(6, NULL, '2008-07-03 05:32:22', 'l'),
(6, '2007-07-16', '2008-08-28 18:46:11', 'j'),
(5, NULL, '2001-07-12 21:27:00', 'h'),
(3, '2007-07-22', '1900-01-01 00:00:00', 'p'),
(2, '2000-11-21', '2007-05-25 11:58:54', 'g'),
(6, '1900-01-01', '2009-06-03 17:11:10', 'i'),
(2, '2008-02-10', '2001-06-15 16:20:07', 'p'),
(3, '2009-06-04', '1900-01-01 00:00:00', 'h'),
(9, '2007-04-25', '1900-01-01 00:00:00', 'e'),
(9, '2006-03-02', '1900-01-01 00:00:00', 'e'),
(1, '1900-01-01', '2002-11-08 09:33:27', 'u'),
(7, '2008-07-13', '2007-08-07 17:35:52', 'j'),
(0, '2004-11-12', '2006-05-01 00:00:00', 'e'),
(0, '1900-01-01', '2003-05-01 00:00:00', 'z'),
(1, '2009-09-02', '2007-02-12 09:30:49', 'w'),
(0, '2004-11-06', '1900-01-01 00:00:00', 't'),
(4, '2003-01-06', '2002-07-03 02:51:11', 'i'),
(6, '2006-01-14', '2008-02-26 04:57:32', 'i'),
(0, '2002-01-19', '2009-02-12 00:00:00', 'i'),
(8, '2007-02-12', '1900-01-01 00:00:00', 'b'),
(4, '1900-01-01', '2001-05-16 05:28:40', 'm'),
(2, '2005-07-16', NULL, 'j'),
(1, '2004-09-04', '2001-01-24 21:45:18', 'v'),
(3, '2009-07-01', NULL, NULL),
(2, '2009-07-21', '2002-07-24 00:00:00', 'h'),
(4, NULL, '2001-11-03 12:22:30', 'q'),
(1, '2002-06-22', '2008-06-17 03:17:59', 'f'),
(7, '2005-06-23', '2005-12-24 00:00:00', 'p'),
(6, '2001-05-20', '2008-10-23 00:00:00', NULL),
(3, '2001-10-01', '2000-10-12 16:32:35', 'o'),
(3, '2001-01-07', '2005-09-11 10:09:54', 'w'),
(6, '2007-11-02', '2009-09-10 01:44:18', 'l'),
(6, NULL, NULL, 'i'),
(9, NULL, '2002-05-18 15:21:55', 'd'),
(4, '2008-12-21', '2004-10-15 10:09:54', 'j'),
(6, '2003-10-05', '2009-07-13 03:51:02', 'e'),
(2, '2001-03-03', '1900-01-01 00:00:00', 'e'),
(2, '2007-04-04', '2001-11-08 21:14:52', 'q'),
(5, NULL, '2006-12-02 00:00:00', 'm'),
(0, '2009-01-04', '1900-01-01 00:00:00', NULL),
(8, '2008-04-03', '2005-01-01 11:55:18', 'q'),
(8, NULL, '2005-02-28 03:44:02', 'w'),
(0, '2003-08-22', NULL, 'c'),
(9, '1900-01-01', NULL, 'y'),
(NULL, NULL, '2006-08-25 16:28:09', 'g'),
(5, '2004-07-04', '2002-08-11 00:00:00', 'z'),
(1, '1900-01-01', '2007-07-22 21:19:18', 'm'),
(2, '2007-02-04', '2006-02-10 18:41:38', 't'),
(2, '1900-01-01', '2009-02-16 14:58:58', 'd'),
(7, '2001-03-14', '2007-08-14 00:00:00', 'h'),
(0, NULL, '1900-01-01 00:00:00', NULL),
(1, '2008-10-05', NULL, 'f'),
(6, '2001-11-25', '2008-12-03 06:59:23', 'l'),
(NULL, '2003-01-27', '2008-10-04 00:00:00', 'g'),
(8, '2008-08-08', '2009-07-07 07:00:21', 'v'),
(8, '2006-07-03', '2001-04-15 00:00:00', NULL),
(5, '2002-11-21', '2007-07-08 04:01:58', 'm'),
(5, '2006-04-08', '2007-09-23 00:01:35', 'i'),
(5, '2001-05-06', '2008-05-15 00:00:00', 'h'),
(7, '1900-01-01', '1900-01-01 00:00:00', 'u'),
(30, '2007-04-16', '2004-03-05 23:35:38', 'o'),
(NULL, '1900-01-01', '2007-08-25 01:32:47', 'z'),
(6, '2004-12-03', '1900-01-01 00:00:00', 'o'),
(8, '2001-06-23', '1900-01-01 00:00:00', 'f'),
(NULL, '2008-12-15', '2001-05-19 08:28:28', 'a'),
(9, '2000-02-15', '2009-09-03 06:07:22', 'd'),
(2, '2001-08-05', '2006-10-08 07:17:27', 'k'),
(5, '2004-01-17', '2003-09-06 20:36:01', 'd'),
(4, '2003-10-01', '2001-02-05 18:10:49', 'u'),
(4, '2003-07-28', '2001-01-07 16:11:37', 'h'),
(0, '1900-01-01', '2008-08-01 05:26:38', 'w'),
(9, '1900-01-01', '2001-05-08 00:00:00', 't'),
(1, '2000-04-17', '2008-07-10 21:26:28', 'i'),
(8, '2002-01-05', '2006-08-06 20:56:35', 'k'),
(9, '2001-04-10', '2003-02-17 00:00:00', 'z'),
(0, '2009-12-04', NULL, 'h'),
(7, NULL, '2004-10-27 00:29:57', 'h'),
(2, '2006-03-07', '2008-03-04 06:14:13', 'b'),
(0, '2001-10-15', '2001-03-17 00:00:00', 'm'),
(5, '1900-01-01', '2009-02-21 11:35:50', 'i'),
(4, NULL, '1900-01-01 00:00:00', 'w'),
(5, '2009-04-05', '1900-01-01 00:00:00', 'm'),
(6, '2001-03-19', '2001-04-12 00:00:00', 'q'),
(NULL, '2009-12-08', '2001-12-04 20:21:01', 'k'),
(2, '2005-02-09', '2001-05-27 08:41:01', 'l'),
(9, '2004-05-25', '2004-09-18 00:00:00', 'c'),
(3, '2005-01-17', '2002-09-12 11:18:48', 'd'),
(0, '2003-08-28', '1900-01-01 00:00:00', 'k'),
(6, '2006-10-11', '2003-10-28 03:31:02', 'a'),
(5, '1900-01-01', '2001-08-22 10:20:09', 'p'),
(8, '1900-01-01', '2008-04-24 00:00:00', 'o'),
(4, '2005-08-18', '2006-11-10 10:08:49', 'e'),
(NULL, '2007-03-12', '2007-10-16 00:00:00', 'n'),
(1, '2000-11-18', '2009-05-27 12:25:07', 't'),
(4, '2001-03-03', NULL, 'u'),
(3, '2003-09-11', '2001-09-10 18:10:10', 'f'),
(4, '2007-06-17', '1900-01-01 00:00:00', 't'),
(NULL, '2008-09-11', '2004-06-07 23:17:09', 'k');
ALTER TABLE t1 ADD UNIQUE KEY ind1 (pk, d, i, v);
--error ER_DUP_ENTRY
ALTER TABLE t1 ADD UNIQUE KEY ind2 (d, v);
DROP TABLE t1;

View File

@ -309,15 +309,36 @@ CHECK TABLE bug47205 FOR UPGRADE;
DROP TABLE bug47205;
--echo #
--echo #MDEV-6128:[PATCH] mysqlcheck wrongly escapes '.' in table names
--echo #
CREATE TABLE test.`t.1` (id int);
create table `t.1` (id int);
create view `v.1` as select 1;
--echo mysqlcheck test t.1
--exec $MYSQL_CHECK test t.1
--echo mysqlcheck --all-in-1 test t.1
--exec $MYSQL_CHECK --all-in-1 test t.1
--echo mysqlcheck --all-in-1 --databases --process-views test
--exec $MYSQL_CHECK --all-in-1 --databases --process-views test
drop table test.`t.1`;
create table `t.2`(a varchar(20) primary key) default character set utf8 collate utf8_general_ci engine=innodb;
flush table `t.2`;
--remove_file $MYSQLD_DATADIR/test/t@002e2.frm
--copy_file std_data/bug47205.frm $MYSQLD_DATADIR/test/t@002e2.frm
--copy_file std_data/bug36055.frm $MYSQLD_DATADIR/test/t@002e3.frm
--copy_file std_data/bug36055.MYD $MYSQLD_DATADIR/test/t@002e3.MYD
--copy_file std_data/bug36055.MYI $MYSQLD_DATADIR/test/t@002e3.MYI
--echo mysqlcheck --check-upgrade --auto-repair test
--exec $MYSQL_CHECK --check-upgrade --auto-repair test
check table `t.1`, `t.2`, `t.3`;
check table `t.1`, `t.2`, `t.3` for upgrade;
drop view `v.1`;
drop table test.`t.1`, `t.2`, `t.3`;
--echo #
--echo # MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
@ -355,6 +376,28 @@ create table `#mysql50#t1``1` (a int) engine=myisam;
show tables;
drop table `t1``1`;
#
# MDEV-9440 mysqlcheck -A --auto-repair selects wrong database when trying to repair broken table
#
call mtr.add_suppression("ha_myisam");
call mtr.add_suppression("Checking table");
create database mysqltest1;
create table mysqltest1.t1 (a int) engine=myisam;
create table t2 (a int);
let $datadir= `select @@datadir`;
remove_file $datadir/mysqltest1/t1.MYD;
write_file $datadir/mysqltest1/t1.MYD;
foo
EOF
check table mysqltest1.t1;
--exec $MYSQL_CHECK -A --auto-repair --fast
drop table t2;
drop database mysqltest1;
--echo #
--echo #MDEV-7384 [PATCH] add PERSISENT FOR ALL option to mysqlanalyze/mysqlcheck
--echo #

View File

@ -22,3 +22,12 @@ connect(pipe_con,localhost,root,,,,,PIPE);
connection default;
disconnect pipe_con;
# MDEV-10383 : check that other server cannot 'bind' on the same pipe
let $MYSQLD_DATADIR= `select @@datadir`;
--error 1
--exec $MYSQLD_CMD --enable-named-pipe --skip-networking --log-error=second-mysqld.err
let SEARCH_FILE=$MYSQLD_DATADIR/second-mysqld.err;
let SEARCH_RANGE= -50;
let SEARCH_PATTERN=\[ERROR\] Create named pipe failed;
source include/search_pattern_in_file.inc;

View File

@ -1690,6 +1690,35 @@ analyze table t2;
select a, b from t2 where (a, b) in ((0, 0), (1, 1));
drop table t2;
--echo #
--echo # MDEV-10228: Delete missing rows with OR conditions
--echo # (The example uses UPDATE, because UPDATE allows to use index hints
--echo # and so it's possible to make an example that works with any storage
--echo # engine)
--echo #
CREATE TABLE t1 (
key1varchar varchar(14) NOT NULL,
key2int int(11) NOT NULL DEFAULT '0',
col1 int,
PRIMARY KEY (key1varchar,key2int),
KEY key1varchar (key1varchar),
KEY key2int (key2int)
) DEFAULT CHARSET=utf8;
insert into t1 values
('value1',0, 0),
('value1',1, 0),
('value1',1000685, 0),
('value1',1003560, 0),
('value1',1004807, 0);
update t1 force index (PRIMARY) set col1=12345
where (key1varchar='value1' AND (key2int <=1 OR key2int > 1));
--echo # The following must show col1=12345 for all rows:
select * from t1;
drop table t1;
--echo #
--echo # BUG#13731380: RANGE OPTIMIZER CALLS RECORDS_IN_RANGE() FOR OPEN RANGE
--echo #

View File

@ -388,3 +388,29 @@ DROP TABLE t1, t2;
--echo End of 5.0 tests
--echo #
--echo # Bug#21142859: FUNCTION UPDATING A VIEW FAILS TO FIND TABLE THAT ACTUALLY EXISTS
--echo #
CREATE TABLE t1 SELECT 1 AS fld1, 'A' AS fld2;
CREATE TABLE t2 (fld3 INT, fld4 CHAR(1));
CREATE VIEW v1 AS SELECT * FROM t1;
CREATE TRIGGER t1_au AFTER UPDATE ON t1
FOR EACH ROW INSERT INTO t2 VALUES (new.fld1, new.fld2);
DELIMITER !;
CREATE FUNCTION f1() RETURNS INT
BEGIN
UPDATE v1 SET fld2='B' WHERE fld1=1;
RETURN row_count();
END !
DELIMITER ;!
--echo # Without the patch, an error was getting reported.
SELECT f1();
DROP FUNCTION f1;
DROP VIEW v1;
DROP TABLE t1,t2;

View File

@ -169,18 +169,8 @@ DROP TABLE t1;
#
CREATE TABLE t1 (a DATE, b INT, PRIMARY KEY (a,b));
## The current sub test could fail (difference to expected result) if we
## have just reached midnight.
## (Bug#41776 type_date.test may fail if run around midnight)
## Therefore we sleep a bit if we are too close to midnight.
## The complete test itself needs in average less than 1 second.
## Therefore a time_distance to midnight of 5 seconds should be sufficient.
if (`SELECT CURTIME() > SEC_TO_TIME(24 * 3600 - 5)`)
{
# We are here when CURTIME() is between '23:59:56' and '23:59:59'.
# So a sleep time of 5 seconds brings us between '00:00:01' and '00:00:04'.
--real_sleep 5
}
SET timestamp=UNIX_TIMESTAMP('2016-07-21 14:48:18');
INSERT INTO t1 VALUES (DATE(NOW()), 1);
SELECT COUNT(*) FROM t1 WHERE a = NOW();
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
@ -192,6 +182,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW() AND b = 1;
ALTER TABLE t1 DROP PRIMARY KEY;
SELECT COUNT(*) FROM t1 WHERE a = NOW();
EXPLAIN SELECT COUNT(*) FROM t1 WHERE a = NOW();
SET timestamp=DEFAULT;
DROP TABLE t1;

View File

@ -5490,6 +5490,21 @@ alter table v1 check partition p1;
drop view v1;
drop table t1;
--echo #
--echo # MDEV-10419: crash in mariadb 10.1.16-MariaDB-1~trusty
--echo #
CREATE TABLE t1 (c1 CHAR(13));
CREATE TABLE t2 (c2 CHAR(13));
CREATE FUNCTION f() RETURNS INT RETURN 0;
CREATE OR REPLACE VIEW v1 AS select f() from t1 where c1 in (select c2 from t2);
DROP FUNCTION f;
SHOW CREATE VIEW v1;
drop view v1;
drop table t1,t2;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.5 tests.
--echo # -----------------------------------------------------------------

View File

@ -33,8 +33,8 @@ insert into t2 select
from t1 A, t1 B, t1 C;
explain
select count(length(a) + length(filler)) from t2 where a>='a-1000-a' and a <'a-1001-a';
select count(length(a) + length(filler)) from t2 where a>='a-1000-a' and a <'a-1001-a';
select count(length(a) + length(filler)) from t2 force index (a) where a>='a-1000-a' and a <'a-1001-a';
select count(length(a) + length(filler)) from t2 force index (a) where a>='a-1000-a' and a <'a-1001-a';
drop table t2;
# Try a very big rowid

View File

@ -696,30 +696,27 @@ my_context_destroy(struct my_context *c)
int
my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
void *current_fiber;
c->user_func= f;
c->user_arg= d;
return my_context_continue(c);
}
int
my_context_continue(struct my_context *c)
{
/*
This seems to be a common trick to run ConvertThreadToFiber() only on the
first occurence in a thread, in a way that works on multiple Windows
versions.
*/
current_fiber= GetCurrentFiber();
void *current_fiber= GetCurrentFiber();
if (current_fiber == NULL || current_fiber == (void *)0x1e00)
current_fiber= ConvertThreadToFiber(c);
c->app_fiber= current_fiber;
DBUG_SWAP_CODE_STATE(&c->dbug_state);
SwitchToFiber(c->lib_fiber);
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return c->return_value;
}
int
my_context_continue(struct my_context *c)
{
DBUG_SWAP_CODE_STATE(&c->dbug_state);
SwitchToFiber(c->lib_fiber);
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return c->return_value;
}

View File

@ -217,7 +217,7 @@ sub remove_remote_root {
sub remove_test_database {
print " - Dropping test database...\n";
if (do_query("DROP DATABASE test;")) {
if (do_query("DROP DATABASE IF EXISTS test;")) {
print " ... Success!\n";
} else {
print " ... Failed! Not critical, keep moving...\n";

View File

@ -332,7 +332,7 @@ remove_remote_root() {
remove_test_database() {
echo " - Dropping test database..."
do_query "DROP DATABASE test;"
do_query "DROP DATABASE IF EXISTS test;"
if [ $? -eq 0 ]; then
echo " ... Success!"
else

View File

@ -1337,7 +1337,8 @@ int ha_commit_trans(THD *thd, bool all)
uint rw_ha_count= ha_check_and_coalesce_trx_read_only(thd, ha_info, all);
/* rw_trans is TRUE when we in a transaction changing data */
bool rw_trans= is_real_trans && (rw_ha_count > 0);
bool rw_trans= is_real_trans &&
(rw_ha_count > !thd->is_current_stmt_binlog_disabled());
MDL_request mdl_request;
DBUG_PRINT("info", ("is_real_trans: %d rw_trans: %d rw_ha_count: %d",
is_real_trans, rw_trans, rw_ha_count));

View File

@ -3763,7 +3763,7 @@ int subselect_uniquesubquery_engine::scan_table()
}
table->file->extra_opt(HA_EXTRA_CACHE,
current_thd->variables.read_buff_size);
get_thd()->variables.read_buff_size);
table->null_row= 0;
for (;;)
{
@ -4201,7 +4201,7 @@ table_map subselect_union_engine::upper_select_const_tables()
void subselect_single_select_engine::print(String *str,
enum_query_type query_type)
{
select_lex->print(thd, str, query_type);
select_lex->print(get_thd(), str, query_type);
}
@ -4732,6 +4732,7 @@ my_bitmap_init_memroot(MY_BITMAP *map, uint n_bits, MEM_ROOT *mem_root)
bool subselect_hash_sj_engine::init(List<Item> *tmp_columns, uint subquery_id)
{
THD *thd= get_thd();
select_union *result_sink;
/* Options to create_tmp_table. */
ulonglong tmp_create_options= thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS;
@ -5959,6 +5960,7 @@ bool
subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts,
MY_BITMAP *partial_match_key_parts)
{
THD *thd= get_thd();
/* The length in bytes of the rowids (positions) of tmp_table. */
uint rowid_length= tmp_table->file->ref_length;
ha_rows row_count= tmp_table->file->stats.records;
@ -6497,7 +6499,7 @@ bool subselect_table_scan_engine::partial_match()
}
tmp_table->file->extra_opt(HA_EXTRA_CACHE,
current_thd->variables.read_buff_size);
get_thd()->variables.read_buff_size);
for (;;)
{
error= tmp_table->file->ha_rnd_next(tmp_table->record[0]);

View File

@ -751,7 +751,8 @@ public:
ROWID_MERGE_ENGINE, TABLE_SCAN_ENGINE};
subselect_engine(Item_subselect *si,
select_result_interceptor *res)
select_result_interceptor *res):
thd(NULL)
{
result= res;
item= si;
@ -767,7 +768,7 @@ public:
Should be called before prepare().
*/
void set_thd(THD *thd_arg);
THD * get_thd() { return thd; }
THD * get_thd() { return thd ? thd : current_thd; }
virtual int prepare(THD *)= 0;
virtual void fix_length_and_dec(Item_cache** row)= 0;
/*

View File

@ -1479,7 +1479,7 @@ my_decimal *Item_sum_sum::val_decimal(my_decimal *val)
if (aggr)
aggr->endup();
if (hybrid_type == DECIMAL_RESULT)
return (dec_buffs + curr_dec_buff);
return null_value ? NULL : (dec_buffs + curr_dec_buff);
return val_decimal_from_real(val);
}
@ -1779,6 +1779,8 @@ double Item_sum_std::val_real()
{
DBUG_ASSERT(fixed == 1);
double nr= Item_sum_variance::val_real();
if (my_isinf(nr))
return DBL_MAX;
DBUG_ASSERT(nr >= 0.0);
return sqrt(nr);
}

View File

@ -2563,26 +2563,17 @@ static void network_init(void)
saPipeSecurity.lpSecurityDescriptor = &sdPipeDescriptor;
saPipeSecurity.bInheritHandle = FALSE;
if ((hPipe= CreateNamedPipe(pipe_name,
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE |
PIPE_READMODE_BYTE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
(int) global_system_variables.net_buffer_length,
(int) global_system_variables.net_buffer_length,
NMPWAIT_USE_DEFAULT_WAIT,
&saPipeSecurity)) == INVALID_HANDLE_VALUE)
{
LPVOID lpMsgBuf;
int error=GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
sql_perror((char *)lpMsgBuf);
LocalFree(lpMsgBuf);
unireg_abort(1);
}
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
(int) global_system_variables.net_buffer_length,
(int) global_system_variables.net_buffer_length,
NMPWAIT_USE_DEFAULT_WAIT,
&saPipeSecurity)) == INVALID_HANDLE_VALUE)
{
sql_perror("Create named pipe failed");
unireg_abort(1);
}
}
#endif

View File

@ -10999,8 +10999,10 @@ get_quick_keys(PARAM *param,QUICK_RANGE_SELECT *quick,KEY_PART *key,
KEY *table_key=quick->head->key_info+quick->index;
flag=EQ_RANGE;
if ((table_key->flags & HA_NOSAME) &&
min_part == key_tree->part &&
key_tree->part == table_key->user_defined_key_parts-1)
{
DBUG_ASSERT(min_part == max_part);
if ((table_key->flags & HA_NULL_PART_KEY) &&
null_part_in_key(key,
param->min_key,

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
Copyright (c) 2010, 2016, MariaDB
This program is free software; you can redistribute it and/or modify
@ -4851,6 +4851,15 @@ handle_view(THD *thd, Query_tables_list *prelocking_ctx,
&table_list->view->sroutines_list,
table_list->top_table());
}
/*
If a trigger was defined on one of the associated tables then assign the
'trg_event_map' value of the view to the next table in table_list. When a
Stored function is invoked, all the associated tables including the tables
associated with the trigger are prelocked.
*/
if (table_list->trg_event_map && table_list->next_global)
table_list->next_global->trg_event_map= table_list->trg_event_map;
return FALSE;
}

View File

@ -3281,6 +3281,7 @@ bool Delayed_insert::handle_inserts(void)
max_rows= 0; // For DBUG output
#endif
/* Remove all not used rows */
mysql_mutex_lock(&mutex);
while ((row=rows.get()))
{
if (table->s->blob_fields)
@ -3297,7 +3298,6 @@ bool Delayed_insert::handle_inserts(void)
}
DBUG_PRINT("error", ("dropped %lu rows after an error", max_rows));
thread_safe_increment(delayed_insert_errors, &LOCK_delayed_status);
mysql_mutex_lock(&mutex);
DBUG_RETURN(1);
}
#endif /* EMBEDDED_LIBRARY */

View File

@ -1405,7 +1405,7 @@ READ_INFO::READ_INFO(File file_par, uint tot_length, CHARSET_INFO *cs,
set_if_bigger(length,line_start.length());
stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
if (!(buffer=(uchar*) my_malloc(buff_length+1,MYF(MY_THREAD_SPECIFIC))))
if (!(buffer=(uchar*) my_malloc(buff_length+1,MYF(MY_WME | MY_THREAD_SPECIFIC))))
error=1; /* purecov: inspected */
else
{
@ -1597,37 +1597,50 @@ int READ_INFO::read_field()
}
}
#ifdef USE_MB
if (my_mbcharlen(read_charset, chr) > 1 &&
to + my_mbcharlen(read_charset, chr) <= end_of_buff)
{
uchar* p= to;
int ml, i;
*to++ = chr;
ml= my_mbcharlen(read_charset, chr);
for (i= 1; i < ml; i++)
uint ml= my_mbcharlen(read_charset, chr);
if (ml == 0)
{
chr= GET;
if (chr == my_b_EOF)
{
/*
Need to back up the bytes already ready from illformed
multi-byte char
*/
to-= i;
goto found_eof;
}
*to++ = chr;
*to= '\0';
my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
read_charset->csname, buffer);
error= true;
return 1;
}
if (my_ismbchar(read_charset,
if (ml > 1 &&
to + ml <= end_of_buff)
{
uchar* p= to;
*to++ = chr;
for (uint i= 1; i < ml; i++)
{
chr= GET;
if (chr == my_b_EOF)
{
/*
Need to back up the bytes already ready from illformed
multi-byte char
*/
to-= i;
goto found_eof;
}
*to++ = chr;
}
if (my_ismbchar(read_charset,
(const char *)p,
(const char *)to))
continue;
for (i= 0; i < ml; i++)
PUSH(*--to);
chr= GET;
}
continue;
for (uint i= 0; i < ml; i++)
PUSH(*--to);
chr= GET;
}
else if (ml > 1)
{
// Buffer is too small, exit while loop, and reallocate.
PUSH(chr);
break;
}
#endif
*to++ = (uchar) chr;
}
@ -1871,7 +1884,15 @@ int READ_INFO::read_value(int delim, String *val)
for (chr= GET; my_tospace(chr) != delim && chr != my_b_EOF;)
{
#ifdef USE_MB
if (my_mbcharlen(read_charset, chr) > 1)
uint ml= my_mbcharlen(read_charset, chr);
if (ml == 0)
{
chr= my_b_EOF;
val->length(0);
return chr;
}
if (ml > 1)
{
DBUG_PRINT("read_xml",("multi byte"));
int i, ml= my_mbcharlen(read_charset, chr);

View File

@ -2937,68 +2937,8 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
if (!thd->variables.dynamic_variables_ptr ||
(uint)offset > thd->variables.dynamic_variables_head)
{
uint idx;
mysql_rwlock_rdlock(&LOCK_system_variables_hash);
thd->variables.dynamic_variables_ptr= (char*)
my_realloc(thd->variables.dynamic_variables_ptr,
global_variables_dynamic_size,
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
if (global_lock)
mysql_mutex_lock(&LOCK_global_system_variables);
mysql_mutex_assert_owner(&LOCK_global_system_variables);
memcpy(thd->variables.dynamic_variables_ptr +
thd->variables.dynamic_variables_size,
global_system_variables.dynamic_variables_ptr +
thd->variables.dynamic_variables_size,
global_system_variables.dynamic_variables_size -
thd->variables.dynamic_variables_size);
/*
now we need to iterate through any newly copied 'defaults'
and if it is a string type with MEMALLOC flag, we need to strdup
*/
for (idx= 0; idx < bookmark_hash.records; idx++)
{
sys_var_pluginvar *pi;
sys_var *var;
st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx);
if (v->version <= thd->variables.dynamic_variables_version)
continue; /* already in thd->variables */
if (!(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
!(pi= var->cast_pluginvar()) ||
v->key[0] != plugin_var_bookmark_key(pi->plugin_var->flags))
continue;
/* Here we do anything special that may be required of the data types */
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
{
char **pp= (char**) (thd->variables.dynamic_variables_ptr +
*(int*)(pi->plugin_var + 1));
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
*(int*)(pi->plugin_var + 1))))
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
}
}
if (global_lock)
mysql_mutex_unlock(&LOCK_global_system_variables);
thd->variables.dynamic_variables_version=
global_system_variables.dynamic_variables_version;
thd->variables.dynamic_variables_head=
global_system_variables.dynamic_variables_head;
thd->variables.dynamic_variables_size=
global_system_variables.dynamic_variables_size;
sync_dynamic_session_variables(thd, global_lock);
mysql_rwlock_unlock(&LOCK_system_variables_hash);
}
DBUG_RETURN((uchar*)thd->variables.dynamic_variables_ptr + offset);
@ -3078,6 +3018,70 @@ void plugin_thdvar_init(THD *thd)
}
void sync_dynamic_session_variables(THD* thd, bool global_lock)
{
uint idx;
thd->variables.dynamic_variables_ptr= (char*)
my_realloc(thd->variables.dynamic_variables_ptr,
global_variables_dynamic_size,
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
if (global_lock)
mysql_mutex_lock(&LOCK_global_system_variables);
mysql_mutex_assert_owner(&LOCK_global_system_variables);
memcpy(thd->variables.dynamic_variables_ptr +
thd->variables.dynamic_variables_size,
global_system_variables.dynamic_variables_ptr +
thd->variables.dynamic_variables_size,
global_system_variables.dynamic_variables_size -
thd->variables.dynamic_variables_size);
/*
now we need to iterate through any newly copied 'defaults'
and if it is a string type with MEMALLOC flag, we need to strdup
*/
for (idx= 0; idx < bookmark_hash.records; idx++)
{
sys_var_pluginvar *pi;
sys_var *var;
st_bookmark *v= (st_bookmark*) my_hash_element(&bookmark_hash,idx);
if (v->version <= thd->variables.dynamic_variables_version)
continue; /* already in thd->variables */
if (!(var= intern_find_sys_var(v->key + 1, v->name_len)) ||
!(pi= var->cast_pluginvar()) ||
v->key[0] != plugin_var_bookmark_key(pi->plugin_var->flags))
continue;
/* Here we do anything special that may be required of the data types */
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
{
int offset= ((thdvar_str_t *)(pi->plugin_var))->offset;
char **pp= (char**) (thd->variables.dynamic_variables_ptr + offset);
if (*pp)
*pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
}
}
if (global_lock)
mysql_mutex_unlock(&LOCK_global_system_variables);
thd->variables.dynamic_variables_version=
global_system_variables.dynamic_variables_version;
thd->variables.dynamic_variables_head=
global_system_variables.dynamic_variables_head;
thd->variables.dynamic_variables_size=
global_system_variables.dynamic_variables_size;
}
/*
Unlocks all system variables which hold a reference
*/

View File

@ -188,6 +188,8 @@ typedef my_bool (plugin_foreach_func)(THD *thd,
#define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
int type, uint state_mask, void *arg);
extern void sync_dynamic_session_variables(THD* thd, bool global_lock);
extern bool plugin_dl_foreach(THD *thd, const LEX_STRING *dl,
plugin_foreach_func *func, void *arg);
#endif

View File

@ -7409,19 +7409,30 @@ int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond)
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
enum enum_schema_tables schema_table_idx=
get_schema_table_idx(tables->schema_table);
enum enum_var_type option_type= OPT_SESSION;
enum enum_var_type scope= OPT_SESSION;
bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
if ((sorted_vars && lex->option_type == OPT_GLOBAL) ||
schema_table_idx == SCH_GLOBAL_VARIABLES)
option_type= OPT_GLOBAL;
scope= OPT_GLOBAL;
COND *partial_cond= make_cond_for_info_schema(cond, tables);
mysql_rwlock_rdlock(&LOCK_system_variables_hash);
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars, option_type),
option_type, NULL, "", tables->table,
/*
Avoid recursive LOCK_system_variables_hash acquisition in
intern_sys_var_ptr() by pre-syncing dynamic session variables.
*/
if (scope == OPT_SESSION &&
(!thd->variables.dynamic_variables_ptr ||
global_system_variables.dynamic_variables_head >
thd->variables.dynamic_variables_head))
sync_dynamic_session_variables(thd, true);
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars, scope),
scope, NULL, "", tables->table,
upper_case_names, partial_cond);
mysql_rwlock_unlock(&LOCK_system_variables_hash);
DBUG_RETURN(res);

View File

@ -893,6 +893,12 @@ bool st_select_lex_unit::cleanup()
join->tables_list= 0;
join->table_count= 0;
join->top_join_tab_count= 0;
if (join->tmp_join && join->tmp_join != join)
{
join->tmp_join->tables_list= 0;
join->tmp_join->table_count= 0;
join->tmp_join->top_join_tab_count= 0;
}
}
error|= fake_select_lex->cleanup();
/*

View File

@ -3832,14 +3832,16 @@ static bool check_log_path(sys_var *self, THD *thd, set_var *var)
if (!var->save_result.string_value.str)
return true;
if (var->save_result.string_value.length > FN_REFLEN)
LEX_STRING *val= &var->save_result.string_value;
if (val->length > FN_REFLEN)
{ // path is too long
my_error(ER_PATH_LENGTH, MYF(0), self->name.str);
return true;
}
char path[FN_REFLEN];
size_t path_length= unpack_filename(path, var->save_result.string_value.str);
size_t path_length= unpack_filename(path, val->str);
if (!path_length)
return true;
@ -3852,6 +3854,17 @@ static bool check_log_path(sys_var *self, THD *thd, set_var *var)
return true;
}
static const LEX_CSTRING my_cnf= { STRING_WITH_LEN("my.cnf") };
static const LEX_CSTRING my_ini= { STRING_WITH_LEN("my.ini") };
if (path_length >= my_cnf.length)
{
if (strcasecmp(path + path_length - my_cnf.length, my_cnf.str) == 0)
return true; // log file name ends with "my.cnf"
DBUG_ASSERT(my_cnf.length == my_ini.length);
if (strcasecmp(path + path_length - my_ini.length, my_ini.str) == 0)
return true; // log file name ends with "my.ini"
}
MY_STAT f_stat;
if (my_stat(path, &f_stat, MYF(0)))
@ -3861,9 +3874,9 @@ static bool check_log_path(sys_var *self, THD *thd, set_var *var)
return false;
}
(void) dirname_part(path, var->save_result.string_value.str, &path_length);
(void) dirname_part(path, val->str, &path_length);
if (var->save_result.string_value.length - path_length >= FN_LEN)
if (val->length - path_length >= FN_LEN)
{ // filename is too long
my_error(ER_PATH_LENGTH, MYF(0), self->name.str);
return true;

View File

@ -0,0 +1,58 @@
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import org.apache.commons.dbcp2.BasicDataSource;
public class ApacheInterface extends JdbcInterface {
static Hashtable<String,BasicDataSource> pool = new Hashtable<String, BasicDataSource>();
public ApacheInterface() {
this(true);
} // end of default constructor
public ApacheInterface(boolean b) {
super(b);
} // end of constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
BasicDataSource ds = null;
if (DEBUG)
System.out.println("Connecting to Apache data source");
try {
CheckURL(url, null);
if ((ds = pool.get(url)) == null) {
ds = new BasicDataSource();
ds.setDriverClassName(parms[0]);
ds.setUrl(url);
ds.setUsername(parms[2]);
ds.setPassword(parms[3]);
pool.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch (Exception e) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class ApacheInterface

View File

@ -235,25 +235,29 @@ ENDIF(CONNECT_WITH_ODBC)
#
# JDBC
#
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
IF(APPLE)
OPTION(CONNECT_WITH_JDBC "some comment" OFF)
ELSE()
OPTION(CONNECT_WITH_JDBC "some comment" ON)
ENDIF()
IF(CONNECT_WITH_JDBC)
# TODO: detect Java SDK and the presence of JDBC connectors
# TODO: Find how to compile and install the java wrapper class
# Find required libraries and include directories
FIND_PACKAGE(Java 1.6)
FIND_PACKAGE(JNI)
IF (JAVA_FOUND AND JNI_FOUND)
INCLUDE(UseJava)
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH2})
# SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY})
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
JdbcInterface.java JdbcInterface.class
JdbcDSInterface.java JdbcDSInterface.class
JdbcApacheInterface.java JdbcApacheInterface.class
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h)
# SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY}) will be dynamically linked
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
jdbconn.cpp tabjdbc.cpp jdbconn.h tabjdbc.h jdbccat.h
JdbcInterface.java ApacheInterface.java MariadbInterface.java
MysqlInterface.java OracleInterface.java PostgresqlInterface.java)
# TODO: Find how to compile and install the java wrapper classes
# Find required libraries and include directories
SET (JAVA_SOURCES JdbcInterface.java)
add_jar(JdbcInterface ${JAVA_SOURCES})
install_jar(JdbcInterface DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
add_definitions(-DJDBC_SUPPORT)
ELSE()
SET(JDBC_LIBRARY "")

183
storage/connect/Client.java Normal file
View File

@ -0,0 +1,183 @@
package wrappers;
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
public class Client {
static boolean DEBUG = true;
static final Console c = System.console();
static JdbcInterface jdi = null;
public static void main(String[] args) {
int rc, n, ncol, i = 0, fsize = 0;
boolean scrollable = false;
String s;
String[] parms = new String[4];
if (args.length > 0)
try {
i = Integer.parseInt(args[i]);
} catch (NumberFormatException e) {
i = 0;
} // end try/catch
switch (i) {
case 1:
jdi = new ApacheInterface(DEBUG);
break;
case 2:
jdi = new MysqlInterface(DEBUG);
break;
case 3:
jdi = new MariadbInterface(DEBUG);
break;
case 4:
jdi = new OracleInterface(DEBUG);
break;
case 5:
jdi = new PostgresqlInterface(DEBUG);
break;
default:
jdi = new JdbcInterface(DEBUG);
} // endswitch i
parms[0] = getLine("Driver: ", false);
parms[1] = getLine("URL: ", false);
parms[2] = getLine("User: ", false);
parms[3] = getLine("Password: ", true);
s = getLine("Fsize: ", false);
fsize = (s != null) ? Integer.parseInt(s) : 0;
s = getLine("Scrollable: ", false);
scrollable = (s != null) ? s.toLowerCase().charAt(0) != 'n' : false;
rc = jdi.JdbcConnect(parms, fsize, scrollable);
if (rc == 0) {
String query;
System.out.println("Successfully connected to " + parms[1]);
while ((query = getLine("Query: ", false)) != null) {
n = jdi.Execute(query);
System.out.println("Returned n = " + n);
if ((ncol = jdi.GetResult()) > 0)
PrintResult(ncol);
else
System.out.println("Affected rows = " + n);
} // endwhile
rc = jdi.JdbcDisconnect();
System.out.println("Disconnect returned " + rc);
} else
System.out.println(jdi.GetErrmsg() + " rc=" + rc);
} // end of main
private static void PrintResult(int ncol) {
// Get result set meta data
int i;
String columnName;
// Get the column names; column indices start from 1
for (i = 1; i <= ncol; i++) {
columnName = jdi.ColumnName(i);
if (columnName == null)
return;
// Get the name of the column's table name
//String tableName = rsmd.getTableName(i);
if (i > 1)
System.out.print("\t");
System.out.print(columnName);
} // endfor i
System.out.println();
// Loop through the result set
while (jdi.ReadNext() > 0) {
for (i = 1; i <= ncol; i++) {
if (i > 1)
System.out.print("\t");
if (DEBUG)
System.out.print("(" + jdi.ColumnType(i, null) + ")");
switch (jdi.ColumnType(i, null)) {
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
case java.sql.Types.CHAR:
System.out.print(jdi.StringField(i, null));
break;
case java.sql.Types.INTEGER:
System.out.print(jdi.IntField(i, null));
break;
case java.sql.Types.BIGINT:
System.out.print(jdi.BigintField(i, null));
break;
case java.sql.Types.TIMESTAMP:
System.out.print(jdi.TimestampField(i, null));
break;
case java.sql.Types.TIME:
System.out.print(jdi.TimeField(i, null));
break;
case java.sql.Types.DATE:
System.out.print(jdi.DateField(i, null));
break;
case java.sql.Types.SMALLINT:
System.out.print(jdi.IntField(i, null));
break;
case java.sql.Types.DOUBLE:
case java.sql.Types.REAL:
case java.sql.Types.FLOAT:
case java.sql.Types.DECIMAL:
System.out.print(jdi.DoubleField(i, null));
break;
case java.sql.Types.BOOLEAN:
System.out.print(jdi.BooleanField(i, null));
default:
break;
} // endswitch Type
} // endfor i
System.out.println();
} // end while rs
} // end of PrintResult
// ==================================================================
private static String getLine(String p, boolean b) {
String response;
if (c != null) {
// Standard console mode
if (b) {
response = new String(c.readPassword(p));
} else
response = c.readLine(p);
} else {
// For instance when testing from Eclipse
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print(p);
try {
// Cannot suppress echo for password entry
response = in.readLine();
} catch (IOException e) {
response = "";
} // end of try/catch
} // endif c
return (response.isEmpty()) ? null : response;
} // end of getLine
} // end of class Client

View File

@ -1,709 +0,0 @@
import java.math.*;
import java.sql.*;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import org.apache.commons.dbcp2.BasicDataSource;
public class JdbcApacheInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
DatabaseMetaData dbmd = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
static Hashtable<String,BasicDataSource> pool = new Hashtable<String, BasicDataSource>();
// === Constructors/finalize =========================================
public JdbcApacheInterface() {
this(true);
} // end of default constructor
public JdbcApacheInterface(boolean b) {
DEBUG = b;
} // end of constructor
private void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
Errmsg = e.toString();
} // end of SetErrmsg
private void SetErrmsg(String s) {
if (DEBUG)
System.out.println(s);
Errmsg = s;
} // end of SetErrmsg
public String GetErrmsg() {
String err = Errmsg;
Errmsg = "No error";
return err;
} // end of GetErrmsg
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
BasicDataSource ds = null;
if (url == null) {
SetErrmsg("URL cannot be null");
return -1;
} // endif url
try {
if ((ds = pool.get(url)) == null) {
ds = new BasicDataSource();
ds.setDriverClassName(parms[0]);
ds.setUrl(url);
ds.setUsername(parms[2]);
ds.setPassword(parms[3]);
pool.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
public int CreatePrepStmt(String sql) {
int rc = 0;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException se) {
SetErrmsg(se);
rc = -1;
} catch (Exception e) {
SetErrmsg(e);
rc = -2;
} // end try/catch
return rc;
} // end of CreatePrepStmt
public void SetStringParm(int i, String s) {
try {
pstmt.setString(i, s);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetStringParm
public void SetIntParm(int i, int n) {
try {
pstmt.setInt(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetIntParm
public void SetShortParm(int i, short n) {
try {
pstmt.setShort(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetShortParm
public void SetBigintParm(int i, long n) {
try {
pstmt.setLong(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetBigintParm
public void SetFloatParm(int i, float f) {
try {
pstmt.setFloat(i, f);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetFloatParm
public void SetDoubleParm(int i, double d) {
try {
pstmt.setDouble(i, d);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetDoubleParm
public void SetTimestampParm(int i, Timestamp t) {
try {
pstmt.setTimestamp(i, t);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetTimestampParm
public int ExecutePrep() {
int n = -3;
if (pstmt != null) try {
n = pstmt.executeUpdate();
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecutePrep
public boolean ClosePrepStmt() {
boolean b = false;
if (pstmt != null) try {
pstmt.close();
pstmt = null;
} catch (SQLException se) {
SetErrmsg(se);
b = true;
} catch (Exception e) {
SetErrmsg(e);
b = true;
} // end try/catch
return b;
} // end of ClosePrepStmt
public int JdbcDisconnect() {
int rc = 0;
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
rc += 1;
} // nothing more we can do
// Close the statement and the connection
if (rs != null)
try {
if (DEBUG)
System.out.println("Closing result set");
rs.close();
} catch(SQLException se) {
SetErrmsg(se);
rc = 2;
} // nothing more we can do
if (stmt != null)
try {
if (DEBUG)
System.out.println("Closing statement");
stmt.close();
} catch(SQLException se) {
SetErrmsg(se);
rc += 4;
} // nothing more we can do
ClosePrepStmt();
if (conn != null)
try {
if (DEBUG)
System.out.println("Closing connection");
conn.close();
} catch (SQLException se) {
SetErrmsg(se);
rc += 8;
} //end try/catch
if (DEBUG)
System.out.println("All closed");
return rc;
} // end of JdbcDisconnect
public int GetMaxValue(int n) {
int m = 0;
try {
switch (n) {
case 1: // Max columns in table
m = dbmd.getMaxColumnsInTable();
break;
case 2: // Max catalog name length
m = dbmd.getMaxCatalogNameLength();
break;
case 3: // Max schema name length
m = dbmd.getMaxSchemaNameLength();
break;
case 4: // Max table name length
m = dbmd.getMaxTableNameLength();
break;
case 5: // Max column name length
m = dbmd.getMaxColumnNameLength();
break;
} // endswitch n
} catch(Exception e) {
SetErrmsg(e);
m = -1;
} // end try/catch
return m;
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
try {
if (rs != null) rs.close();
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int GetTables(String[] parms) {
int ncol = 0;
String[] typ = null;
if (parms[3] != null) {
typ = new String[1];
typ[0] = parms[3];
} // endif parms
try {
if (rs != null) rs.close();
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int Execute(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing '" + query + "'");
try {
boolean b = stmt.execute(query);
if (b == false) {
n = stmt.getUpdateCount();
if (rs != null) rs.close();
} // endif b
if (DEBUG)
System.out.println("Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of Execute
public int GetResult() {
int ncol = 0;
try {
rs = stmt.getResultSet();
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG)
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif rs
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of GetResult
public int ExecuteQuery(String query) {
int ncol = 0;
if (DEBUG)
System.out.println("Executing query '" + query + "'");
try {
rs = stmt.executeQuery(query);
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG) {
System.out.println("Query '" + query + "' executed successfully");
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif DEBUG
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of ExecuteQuery
public int ExecuteUpdate(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing update query '" + query + "'");
try {
n = stmt.executeUpdate(query);
if (DEBUG)
System.out.println("Update Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecuteUpdate
public int ReadNext() {
if (rs != null) {
try {
return rs.next() ? 1 : 0;
} catch (SQLException se) {
SetErrmsg(se);
return -1;
} //end try/catch
} else
return 0;
} // end of ReadNext
public boolean Fetch(int row) {
if (rs != null) {
try {
return rs.absolute(row);
} catch (SQLException se) {
SetErrmsg(se);
return false;
} //end try/catch
} else
return false;
} // end of Fetch
public String ColumnName(int n) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnName
public int ColumnType(int n, String name) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
if (n == 0)
n = rs.findColumn(name);
return rsmd.getColumnType(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 666; // Not a type
} // end of ColumnType
public String ColumnDesc(int n, int[] val) {
if (rsmd == null) {
System.out.println("No result metadata");
return null;
} else try {
val[0] = rsmd.getColumnType(n);
val[1] = rsmd.getPrecision(n);
val[2] = rsmd.getScale(n);
val[3] = rsmd.isNullable(n);
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnDesc
public String StringField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getString(n) : rs.getString(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of StringField
public int IntField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getInt(n) : rs.getInt(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of IntField
public long BigintField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
BigDecimal bigDecimal = (n > 0) ? rs.getBigDecimal(n) : rs.getBigDecimal(name);
return bigDecimal != null ? bigDecimal.longValue() : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of BiginttField
public double DoubleField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDouble(n) : rs.getDouble(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0.;
} // end of DoubleField
public float FloatField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getFloat(n) : rs.getFloat(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of FloatField
public boolean BooleanField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getBoolean(n) : rs.getBoolean(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return false;
} // end of BooleanField
public Date DateField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDate(n) : rs.getDate(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of DateField
public Time TimeField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTime(n) : rs.getTime(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimeField
public Timestamp TimestampField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimestampField
public String ObjectField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getObject(n).toString() : rs.getObject(name).toString();
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ObjectField
public int GetDrivers(String[] s, int mxs) {
int n = 0;
List<Driver> drivers = Collections.list(DriverManager.getDrivers());
int size = Math.min(mxs, drivers.size());
for (int i = 0; i < size; i++) {
Driver driver = (Driver)drivers.get(i);
// Get name of driver
s[n++] = driver.getClass().getName();
// Get version info
s[n++] = driver.getMajorVersion() + "." + driver.getMinorVersion();
s[n++] = driver.jdbcCompliant() ? "Yes" : "No";
s[n++] = driver.toString();
} // endfor i
return size;
} // end of GetDrivers
/**
* Adds the specified path to the java library path
* from Fahd Shariff blog
*
* @param pathToAdd the path to add
static public int addLibraryPath(String pathToAdd) {
System.out.println("jpath = " + pathToAdd);
try {
Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
//get array of paths
String[] paths = (String[])usrPathsField.get(null);
//check if the path to add is already present
for (String path : paths) {
System.out.println("path = " + path);
if (path.equals(pathToAdd))
return -5;
} // endfor path
//add the new path
String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[paths.length] = pathToAdd;
usrPathsField.set(null, newPaths);
System.setProperty("java.library.path",
System.getProperty("java.library.path") + File.pathSeparator + pathToAdd);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
SetErrmsg(e);
return -1;
} // end try/catch
return 0;
} // end of addLibraryPath
*/
} // end of class JdbcApacheInterface

View File

@ -1,743 +0,0 @@
import java.math.*;
import java.sql.*;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import javax.sql.DataSource;
import org.mariadb.jdbc.MariaDbDataSource;
import org.postgresql.jdbc2.optional.PoolingDataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
import oracle.jdbc.pool.OracleDataSource;
public class JdbcDSInterface {
boolean DEBUG = false;
String Errmsg = "No error";
Connection conn = null;
DatabaseMetaData dbmd = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
Hashtable<String,DataSource> dst = null;
// === Constructors/finalize =========================================
public JdbcDSInterface() {
this(true);
} // end of default constructor
public JdbcDSInterface(boolean b) {
DEBUG = b;
dst = new Hashtable<String, DataSource>();
} // end of constructor
private void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
Errmsg = e.toString();
} // end of SetErrmsg
private void SetErrmsg(String s) {
if (DEBUG)
System.out.println(s);
Errmsg = s;
} // end of SetErrmsg
public String GetErrmsg() {
String err = Errmsg;
Errmsg = "No error";
return err;
} // end of GetErrmsg
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
MysqlDataSource mds = null;
MariaDbDataSource ads = null;
OracleDataSource ods = null;
PoolingDataSource pds = null;
if (url == null) {
SetErrmsg("URL cannot be null");
return -1;
} // endif driver
try {
if ((ds = dst.get(url)) == null) {
if (url.toLowerCase().contains("mysql")) {
mds = new MysqlDataSource();
mds.setURL(url);
mds.setUser(parms[2]);
mds.setPassword(parms[3]);
ds = mds;
} else if (url.toLowerCase().contains("mariadb")) {
ads = new MariaDbDataSource();
ads.setUrl(url);
ads.setUser(parms[2]);
ads.setPassword(parms[3]);
ds = ads;
} else if (url.toLowerCase().contains("oracle")) {
ods = new OracleDataSource();
ods.setURL(url);
ods.setUser(parms[2]);
ods.setPassword(parms[3]);
ds = ods;
} else if (url.toLowerCase().contains("postgresql")) {
pds = new PoolingDataSource();
pds.setUrl(url);
pds.setUser(parms[2]);
pds.setPassword(parms[3]);
ds = pds;
} else {
SetErrmsg("Unsupported driver");
return -4;
} // endif driver
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
public int CreatePrepStmt(String sql) {
int rc = 0;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException se) {
SetErrmsg(se);
rc = -1;
} catch (Exception e) {
SetErrmsg(e);
rc = -2;
} // end try/catch
return rc;
} // end of CreatePrepStmt
public void SetStringParm(int i, String s) {
try {
pstmt.setString(i, s);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetStringParm
public void SetIntParm(int i, int n) {
try {
pstmt.setInt(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetIntParm
public void SetShortParm(int i, short n) {
try {
pstmt.setShort(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetShortParm
public void SetBigintParm(int i, long n) {
try {
pstmt.setLong(i, n);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetBigintParm
public void SetFloatParm(int i, float f) {
try {
pstmt.setFloat(i, f);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetFloatParm
public void SetDoubleParm(int i, double d) {
try {
pstmt.setDouble(i, d);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetDoubleParm
public void SetTimestampParm(int i, Timestamp t) {
try {
pstmt.setTimestamp(i, t);
} catch (Exception e) {
SetErrmsg(e);
} // end try/catch
} // end of SetTimestampParm
public int ExecutePrep() {
int n = -3;
if (pstmt != null) try {
n = pstmt.executeUpdate();
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecutePrep
public boolean ClosePrepStmt() {
boolean b = false;
if (pstmt != null) try {
pstmt.close();
pstmt = null;
} catch (SQLException se) {
SetErrmsg(se);
b = true;
} catch (Exception e) {
SetErrmsg(e);
b = true;
} // end try/catch
return b;
} // end of ClosePrepStmt
public int JdbcDisconnect() {
int rc = 0;
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
rc += 1;
} // nothing more we can do
// Close the statement and the connection
if (rs != null)
try {
if (DEBUG)
System.out.println("Closing result set");
rs.close();
} catch(SQLException se) {
SetErrmsg(se);
rc = 2;
} // nothing more we can do
if (stmt != null)
try {
if (DEBUG)
System.out.println("Closing statement");
stmt.close();
} catch(SQLException se) {
SetErrmsg(se);
rc += 4;
} // nothing more we can do
ClosePrepStmt();
if (conn != null)
try {
if (DEBUG)
System.out.println("Closing connection");
conn.close();
} catch (SQLException se) {
SetErrmsg(se);
rc += 8;
} //end try/catch
if (DEBUG)
System.out.println("All closed");
return rc;
} // end of JdbcDisconnect
public int GetMaxValue(int n) {
int m = 0;
try {
switch (n) {
case 1: // Max columns in table
m = dbmd.getMaxColumnsInTable();
break;
case 2: // Max catalog name length
m = dbmd.getMaxCatalogNameLength();
break;
case 3: // Max schema name length
m = dbmd.getMaxSchemaNameLength();
break;
case 4: // Max table name length
m = dbmd.getMaxTableNameLength();
break;
case 5: // Max column name length
m = dbmd.getMaxColumnNameLength();
break;
} // endswitch n
} catch(Exception e) {
SetErrmsg(e);
m = -1;
} // end try/catch
return m;
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
try {
if (rs != null) rs.close();
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int GetTables(String[] parms) {
int ncol = 0;
String[] typ = null;
if (parms[3] != null) {
typ = new String[1];
typ[0] = parms[3];
} // endif parms
try {
if (rs != null) rs.close();
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
} // endif rs
} catch(SQLException se) {
SetErrmsg(se);
} // end try/catch
return ncol;
} // end of GetColumns
public int Execute(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing '" + query + "'");
try {
boolean b = stmt.execute(query);
if (b == false) {
n = stmt.getUpdateCount();
if (rs != null) rs.close();
} // endif b
if (DEBUG)
System.out.println("Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of Execute
public int GetResult() {
int ncol = 0;
try {
rs = stmt.getResultSet();
if (rs != null) {
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG)
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif rs
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of GetResult
public int ExecuteQuery(String query) {
int ncol = 0;
if (DEBUG)
System.out.println("Executing query '" + query + "'");
try {
rs = stmt.executeQuery(query);
rsmd = rs.getMetaData();
ncol = rsmd.getColumnCount();
if (DEBUG) {
System.out.println("Query '" + query + "' executed successfully");
System.out.println("Result set has " + rsmd.getColumnCount() + " column(s)");
} // endif DEBUG
} catch (SQLException se) {
SetErrmsg(se);
ncol = -1;
} catch (Exception e) {
SetErrmsg(e);
ncol = -2;
} //end try/catch
return ncol;
} // end of ExecuteQuery
public int ExecuteUpdate(String query) {
int n = 0;
if (DEBUG)
System.out.println("Executing update query '" + query + "'");
try {
n = stmt.executeUpdate(query);
if (DEBUG)
System.out.println("Update Query '" + query + "' executed: n = " + n);
} catch (SQLException se) {
SetErrmsg(se);
n = -1;
} catch (Exception e) {
SetErrmsg(e);
n = -2;
} //end try/catch
return n;
} // end of ExecuteUpdate
public int ReadNext() {
if (rs != null) {
try {
return rs.next() ? 1 : 0;
} catch (SQLException se) {
SetErrmsg(se);
return -1;
} //end try/catch
} else
return 0;
} // end of ReadNext
public boolean Fetch(int row) {
if (rs != null) {
try {
return rs.absolute(row);
} catch (SQLException se) {
SetErrmsg(se);
return false;
} //end try/catch
} else
return false;
} // end of Fetch
public String ColumnName(int n) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnName
public int ColumnType(int n, String name) {
if (rsmd == null) {
System.out.println("No result metadata");
} else try {
if (n == 0)
n = rs.findColumn(name);
return rsmd.getColumnType(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 666; // Not a type
} // end of ColumnType
public String ColumnDesc(int n, int[] val) {
if (rsmd == null) {
System.out.println("No result metadata");
return null;
} else try {
val[0] = rsmd.getColumnType(n);
val[1] = rsmd.getPrecision(n);
val[2] = rsmd.getScale(n);
val[3] = rsmd.isNullable(n);
return rsmd.getColumnLabel(n);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ColumnDesc
public String StringField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getString(n) : rs.getString(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of StringField
public int IntField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getInt(n) : rs.getInt(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of IntField
public long BigintField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
BigDecimal bigDecimal = (n > 0) ? rs.getBigDecimal(n) : rs.getBigDecimal(name);
return bigDecimal != null ? bigDecimal.longValue() : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of BiginttField
public double DoubleField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDouble(n) : rs.getDouble(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0.;
} // end of DoubleField
public float FloatField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getFloat(n) : rs.getFloat(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return 0;
} // end of FloatField
public boolean BooleanField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getBoolean(n) : rs.getBoolean(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return false;
} // end of BooleanField
public Date DateField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDate(n) : rs.getDate(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of DateField
public Time TimeField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTime(n) : rs.getTime(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimeField
public Timestamp TimestampField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of TimestampField
public String ObjectField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getObject(n).toString() : rs.getObject(name).toString();
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
} // end of ObjectField
public int GetDrivers(String[] s, int mxs) {
int n = 0;
List<Driver> drivers = Collections.list(DriverManager.getDrivers());
int size = Math.min(mxs, drivers.size());
for (int i = 0; i < size; i++) {
Driver driver = (Driver)drivers.get(i);
// Get name of driver
s[n++] = driver.getClass().getName();
// Get version info
s[n++] = driver.getMajorVersion() + "." + driver.getMinorVersion();
s[n++] = driver.jdbcCompliant() ? "Yes" : "No";
s[n++] = driver.toString();
} // endfor i
return size;
} // end of GetDrivers
/**
* Adds the specified path to the java library path
* from Fahd Shariff blog
*
* @param pathToAdd the path to add
static public int addLibraryPath(String pathToAdd) {
System.out.println("jpath = " + pathToAdd);
try {
Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
//get array of paths
String[] paths = (String[])usrPathsField.get(null);
//check if the path to add is already present
for (String path : paths) {
System.out.println("path = " + path);
if (path.equals(pathToAdd))
return -5;
} // endfor path
//add the new path
String[] newPaths = Arrays.copyOf(paths, paths.length + 1);
newPaths[paths.length] = pathToAdd;
usrPathsField.set(null, newPaths);
System.setProperty("java.library.path",
System.getProperty("java.library.path") + File.pathSeparator + pathToAdd);
Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
SetErrmsg(e);
return -1;
} // end try/catch
return 0;
} // end of addLibraryPath
*/
} // end of class JdbcDSInterface

Binary file not shown.

View File

@ -1,13 +1,19 @@
package wrappers;
import java.math.*;
import java.sql.*;
//import java.util.Arrays;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
//import java.io.File;
//import java.lang.reflect.Field;
import javax.sql.DataSource;
public class JdbcInterface {
// This is used by DS classes
static Hashtable<String,DataSource> dst = null;
boolean DEBUG = false;
boolean CatisSchema = false;
String Errmsg = "No error";
Connection conn = null;
DatabaseMetaData dbmd = null;
@ -18,14 +24,14 @@ public class JdbcInterface {
// === Constructors/finalize =========================================
public JdbcInterface() {
this(true);
this(false);
} // end of default constructor
public JdbcInterface(boolean b) {
DEBUG = b;
} // end of constructor
private void SetErrmsg(Exception e) {
protected void SetErrmsg(Exception e) {
if (DEBUG)
System.out.println(e.getMessage());
@ -38,6 +44,22 @@ public class JdbcInterface {
Errmsg = "No error";
return err;
} // end of GetErrmsg
protected void CheckURL(String url, String vendor) throws Exception {
if (url == null)
throw new Exception("URL cannot be null");
String[] tk = url.split(":", 3);
if (!tk[0].equals("jdbc") || tk[1] == null)
throw new Exception("Invalid URL");
if (vendor != null && !tk[1].equals(vendor))
throw new Exception("Wrong URL for this wrapper");
// Some drivers use Catalog as Schema
CatisSchema = tk[1].equals("mysql") || tk[1].equals("mariadb");
} // end of CatalogIsSchema
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
@ -58,6 +80,8 @@ public class JdbcInterface {
if (DEBUG)
System.out.println("URL=" + parms[1]);
CheckURL(parms[1], null);
if (parms[2] != null && !parms[2].isEmpty()) {
if (DEBUG)
@ -74,27 +98,7 @@ public class JdbcInterface {
dbmd = conn.getMetaData();
// Get a statement from the connection
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
stmt = GetStmt(fsize, scrollable);
} catch(ClassNotFoundException e) {
SetErrmsg(e);
rc = -1;
@ -109,6 +113,34 @@ public class JdbcInterface {
return rc;
} // end of JdbcConnect
protected Statement GetStmt(int fsize, boolean scrollable) throws SQLException, Exception {
Statement stmt = null;
if (scrollable)
stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
else
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
if (DEBUG)
System.out.println("Statement type = " + stmt.getResultSetType()
+ " concurrency = " + stmt.getResultSetConcurrency());
if (DEBUG) // Get the fetch size of a statement
System.out.println("Default fetch size = " + stmt.getFetchSize());
if (fsize != 0) {
// Set the fetch size
stmt.setFetchSize(fsize);
if (DEBUG)
System.out.println("New fetch size = " + stmt.getFetchSize());
} // endif fsize
return stmt;
} // end of GetStmt
public int CreatePrepStmt(String sql) {
int rc = 0;
@ -227,7 +259,9 @@ public class JdbcInterface {
// Cancel pending statement
if (stmt != null)
try {
System.out.println("Cancelling statement");
if (DEBUG)
System.out.println("Cancelling statement");
stmt.cancel();
} catch(SQLException se) {
SetErrmsg(se);
@ -307,11 +341,15 @@ public class JdbcInterface {
} // end of GetMaxValue
public int GetColumns(String[] parms) {
int ncol = 0;
int ncol = -1;
try {
if (rs != null) rs.close();
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (CatisSchema)
rs = dbmd.getColumns(parms[1], null, parms[2], parms[3]);
else
rs = dbmd.getColumns(parms[0], parms[1], parms[2], parms[3]);
if (rs != null) {
rsmd = rs.getMetaData();
@ -326,7 +364,7 @@ public class JdbcInterface {
} // end of GetColumns
public int GetTables(String[] parms) {
int ncol = 0;
int ncol = -1;
String[] typ = null;
if (parms[3] != null) {
@ -336,7 +374,11 @@ public class JdbcInterface {
try {
if (rs != null) rs.close();
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (CatisSchema)
rs = dbmd.getTables(parms[1], null, parms[2], typ);
else
rs = dbmd.getTables(parms[0], parms[1], parms[2], typ);
if (rs != null) {
rsmd = rs.getMetaData();
@ -599,40 +641,43 @@ public class JdbcInterface {
return false;
} // end of BooleanField
public Date DateField(int n, String name) {
public int DateField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getDate(n) : rs.getDate(name);
Date d = (n > 0) ? rs.getDate(n) : rs.getDate(name);
return (d != null) ? (int)(d.getTime() / 1000) : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
return 0;
} // end of DateField
public Time TimeField(int n, String name) {
public int TimeField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTime(n) : rs.getTime(name);
Time t = (n > 0) ? rs.getTime(n) : rs.getTime(name);
return (t != null) ? (int)(t.getTime() / 1000) : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
return 0;
} // end of TimeField
public Timestamp TimestampField(int n, String name) {
public int TimestampField(int n, String name) {
if (rs == null) {
System.out.println("No result set");
} else try {
return (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
Timestamp ts = (n > 0) ? rs.getTimestamp(n) : rs.getTimestamp(name);
return (ts != null) ? (int)(ts.getTime() / 1000) : 0;
} catch (SQLException se) {
SetErrmsg(se);
} //end try/catch
return null;
return 0;
} // end of TimestampField
public String ObjectField(int n, String name) {
@ -710,3 +755,4 @@ public class JdbcInterface {
*/
} // end of class JdbcInterface

View File

@ -0,0 +1,69 @@
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import org.mariadb.jdbc.MariaDbDataSource;
public class MariadbInterface extends JdbcInterface {
public MariadbInterface() {
this(true);
} // end of default constructor
public MariadbInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of default constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
MariaDbDataSource ads = null;
if (DEBUG)
System.out.println("Connecting to MariaDB data source");
try {
CheckURL(url, "mariadb");
if ((ds = dst.get(url)) == null) {
ads = new MariaDbDataSource();
ads.setUrl(url);
if (parms[2] != null)
ads.setUser(parms[2]);
if (parms[3] != null)
ads.setPassword(parms[3]);
ds = ads;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
}

View File

@ -0,0 +1,69 @@
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
public class MysqlInterface extends JdbcInterface {
public MysqlInterface() {
this(true);
} // end of default constructor
public MysqlInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of default constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
MysqlDataSource mds = null;
if (DEBUG)
System.out.println("Connecting to MySQL data source");
try {
CheckURL(url, "mysql");
if ((ds = dst.get(url)) == null) {
mds = new MysqlDataSource();
mds.setUrl(url);
if (parms[2] != null)
mds.setUser(parms[2]);
if (parms[3] != null)
mds.setPassword(parms[3]);
ds = mds;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class MysqlInterface

View File

@ -0,0 +1,69 @@
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import oracle.jdbc.pool.OracleDataSource;
public class OracleInterface extends JdbcInterface {
public OracleInterface() {
this(true);
} // end of OracleInterface constructor
public OracleInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of OracleInterface constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
OracleDataSource ods = null;
if (DEBUG)
System.out.println("Connecting to Oracle data source");
try {
CheckURL(url, "oracle");
if ((ds = dst.get(url)) == null) {
ods = new OracleDataSource();
ods.setURL(url);
if (parms[2] != null)
ods.setUser(parms[2]);
if (parms[3] != null)
ods.setPassword(parms[3]);
ds = ods;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class OracleInterface

View File

@ -0,0 +1,69 @@
package wrappers;
import java.sql.*;
import java.util.Hashtable;
import javax.sql.DataSource;
import org.postgresql.jdbc2.optional.PoolingDataSource;
public class PostgresqlInterface extends JdbcInterface {
public PostgresqlInterface() {
this(true);
} // end of constructor
public PostgresqlInterface(boolean b) {
super(b);
if (dst == null)
dst = new Hashtable<String, DataSource>();
} // end of constructor
@Override
public int JdbcConnect(String[] parms, int fsize, boolean scrollable) {
int rc = 0;
String url = parms[1];
DataSource ds = null;
PoolingDataSource pds = null;
if (DEBUG)
System.out.println("Connecting to Postgresql data source");
try {
CheckURL(url, "postgresql");
if ((ds = dst.get(url)) == null) {
pds = new PoolingDataSource();
pds.setUrl(url);
if (parms[2] != null)
pds.setUser(parms[2]);
if (parms[3] != null)
pds.setPassword(parms[3]);
ds = pds;
dst.put(url, ds);
} // endif ds
// Get a connection from the data source
conn = ds.getConnection();
// Get the data base meta data object
dbmd = conn.getMetaData();
// Get a statement from the connection
stmt = GetStmt(fsize, scrollable);
} catch (SQLException se) {
SetErrmsg(se);
rc = -2;
} catch( Exception e ) {
SetErrmsg(e);
rc = -3;
} // end try/catch
return rc;
} // end of JdbcConnect
} // end of class PostgresqlInterface

View File

@ -65,7 +65,8 @@ class TDBDOX: public TDBDOS {
friend int CntIndexRange(PGLOBAL, PTDB, const uchar**, uint*,
bool*, key_part_map*);
friend class ha_connect;
}; // end of class TDBDOX
TDBDOX() : TDBDOS((PGLOBAL)0, (PTDBDOS)0) {} /* Never called */
}; // end of class TDBDOX
class XKPDEF: public KPARTDEF {
friend class TDBDOX;

View File

@ -5,7 +5,7 @@
/* */
/* COPYRIGHT: */
/* ---------- */
/* (C) Copyright to the author Olivier Bertrand 1995-2012 */
/* (C) Copyright to the author Olivier Bertrand 1995-2016 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
@ -721,8 +721,8 @@ int CSORT::Qsortc(void)
void CSORT::Qstc(int *base, int *max)
{
register int *i, *j, *jj, *lt, *eq, *gt, *mid;
int c, lo, hi, rc;
size_t zlo, zhi, cnm;
int c = 0, lo, hi, rc;
size_t zlo, zhi, cnm;
zlo = zhi = cnm = 0; // Avoid warning message
@ -774,8 +774,11 @@ void CSORT::Qstc(int *base, int *max)
/*****************************************************************/
/* Small group. Do special quicker processing. */
/*****************************************************************/
if ((rc = Qcompare(base, (i = base + 1))) > 0)
c = *base, *base = *i, *i = c;
if ((rc = Qcompare(base, (i = base + 1))) > 0) {
c = *base;
*base = *i;
*i = c;
} // endif rc
if (Pof)
Pof[base - Pex] = Pof[i - Pex] = (rc) ? 1 : 2;

View File

@ -171,9 +171,9 @@
#define JSONMAX 10 // JSON Default max grp size
extern "C" {
char version[]= "Version 1.04.0006 May 08, 2016";
char version[]= "Version 1.04.0008 August 10, 2016";
#if defined(__WIN__)
char compver[]= "Version 1.04.0006 " __DATE__ " " __TIME__;
char compver[]= "Version 1.04.0008 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
@ -195,7 +195,6 @@ extern "C" {
#if defined(JDBC_SUPPORT)
char *JvmPath;
char *ClassPath;
char *Wrapper;
#endif // JDBC_SUPPORT
#if defined(__WIN__)
@ -211,7 +210,7 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, bool info);
PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info);
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
int TranslateJDBCType(int stp, int prec, int& len, char& v);
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
void PushWarning(PGLOBAL g, THD *thd, int level);
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, const char *host,
const char *db, char *tab, const char *src, int port);
@ -220,6 +219,7 @@ USETEMP UseTemp(void);
int GetConvSize(void);
TYPCONV GetTypeConv(void);
uint GetJsonGrpSize(void);
char *GetJavaWrapper(void);
uint GetWorkSize(void);
void SetWorkSize(uint);
extern "C" const char *msglang(void);
@ -332,6 +332,15 @@ static MYSQL_THDVAR_UINT(json_grp_size,
"max number of rows for JSON aggregate functions.",
NULL, NULL, JSONMAX, 1, INT_MAX, 1);
#if defined(JDBC_SUPPORT)
// Default java wrapper to use with JDBC tables
static MYSQL_THDVAR_STR(java_wrapper,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Java wrapper class name",
// check_class_path, update_class_path,
NULL, NULL, "wrappers/JdbcInterface");
#endif // JDBC_SUPPORT
#if defined(XMSG) || defined(NEWMSG)
const char *language_names[]=
{
@ -384,6 +393,12 @@ extern "C" const char *msglang(void)
return language_names[THDVAR(current_thd, msg_lang)];
} // end of msglang
#else // !XMSG && !NEWMSG
#if defined(JDBC_SUPPORT)
char *GetJavaWrapper(void)
{return connect_hton ? THDVAR(current_thd, java_wrapper) : (char*)"wrappers/JdbcInterface";}
#endif // JDBC_SUPPORT
extern "C" const char *msglang(void)
{
#if defined(FRENCH)
@ -1123,7 +1138,7 @@ bool GetBooleanTableOption(PGLOBAL g, PTOS options, char *opname, bool bdef)
/****************************************************************************/
int GetIntegerTableOption(PGLOBAL g, PTOS options, char *opname, int idef)
{
ulonglong opval= NO_IVAL;
ulonglong opval= (ulonglong) NO_IVAL;
if (!options)
return idef;
@ -5508,7 +5523,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
break;
case FNC_TABLE:
qrp= ODBCTables(g, dsn, shm, tab, mxr, true, sop);
qrp= ODBCTables(g, dsn, shm, tab, NULL, mxr, true, sop);
break;
case FNC_DSN:
qrp= ODBCDataSources(g, mxr, true);
@ -5633,6 +5648,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
} else {
char *schem= NULL;
char *tn= NULL;
// Not a catalog table
if (!qrp->Nblin) {
@ -5649,7 +5665,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
typ= len= prec= dec= 0;
tm= NOT_NULL_FLAG;
cnm= (char*)"noname";
dft= xtra= key= fmt= NULL;
dft= xtra= key= fmt= tn= NULL;
v= ' ';
rem= NULL;
@ -5669,7 +5685,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
typ= crp->Kdata->GetIntValue(i);
v = (crp->Nulls) ? crp->Nulls[i] : 0;
break;
case FLD_PREC:
case FLD_TYPENAME:
tn= crp->Kdata->GetCharValue(i);
break;
case FLD_PREC:
// PREC must be always before LENGTH
len= prec= crp->Kdata->GetIntValue(i);
break;
@ -5713,8 +5732,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
break;
case FLD_SCHEM:
#if defined(ODBC_SUPPORT)
if (ttp == TAB_ODBC && crp->Kdata) {
#if defined(ODBC_SUPPORT) || defined(JDBC_SUPPORT)
if ((ttp == TAB_ODBC || ttp == TAB_JDBC) && crp->Kdata) {
if (schem && stricmp(schem, crp->Kdata->GetCharValue(i))) {
sprintf(g->Message,
"Several %s tables found, specify DBNAME", tab);
@ -5724,7 +5743,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
schem= crp->Kdata->GetCharValue(i);
} // endif ttp
#endif // ODBC_SUPPORT
#endif // ODBC_SUPPORT || JDBC_SUPPORT
default:
break; // Ignore
} // endswitch Fld
@ -5777,7 +5796,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
int plgtyp;
// typ must be PLG type, not SQL type
if (!(plgtyp= TranslateJDBCType(typ, dec, prec, v))) {
if (!(plgtyp= TranslateJDBCType(typ, tn, dec, prec, v))) {
if (GetTypeConv() == TPC_SKIP) {
// Skip this column
sprintf(g->Message, "Column %s skipped (unsupported type %d)",
@ -6875,12 +6894,6 @@ static MYSQL_SYSVAR_STR(class_path, ClassPath,
"Java class path",
// check_class_path, update_class_path,
NULL, NULL, NULL);
static MYSQL_SYSVAR_STR(java_wrapper, Wrapper,
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC,
"Java wrapper class",
// check_class_path, update_class_path,
NULL, NULL, "JdbcInterface");
#endif // JDBC_SUPPORT
@ -6922,7 +6935,7 @@ maria_declare_plugin(connect)
0x0104, /* version number (1.04) */
NULL, /* status variables */
connect_system_variables, /* system variables */
"1.04.0006", /* string version */
"1.04.0008", /* string version */
MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */
}
maria_declare_plugin_end;

View File

@ -6,6 +6,13 @@
/* This file contains the JDBC connection classes functions. */
/***********************************************************************/
#if defined(__WIN__)
// This is needed for RegGetValue
#define _WINVER 0x0601
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0601
#endif // __WIN__
/***********************************************************************/
/* Include relevant MariaDB header file. */
/***********************************************************************/
@ -52,10 +59,12 @@ extern "C" HINSTANCE s_hModule; // Saved module handle
#define nullptr 0
#endif // !__WIN__
TYPCONV GetTypeConv();
int GetConvSize();
extern char *JvmPath; // The connect_jvm_path global variable value
extern char *ClassPath; // The connect_class_path global variable value
extern char *Wrapper; // The connect_java_wrapper global variable value
char *GetJavaWrapper(void); // The connect_java_wrapper variable value
/***********************************************************************/
/* Static JDBConn objects. */
@ -79,7 +88,7 @@ GETDEF JDBConn::GetDefaultJavaVMInitArgs = NULL;
#endif // !_DEBUG
// To avoid gcc warning
int TranslateJDBCType(int stp, int prec, int& len, char& v);
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
/***********************************************************************/
/* GetJDBCType: returns the SQL_TYPE corresponding to a PLG type. */
@ -107,13 +116,16 @@ static short GetJDBCType(int type)
/***********************************************************************/
/* TranslateJDBCType: translate a JDBC Type to a PLG type. */
/***********************************************************************/
int TranslateJDBCType(int stp, int prec, int& len, char& v)
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v)
{
int type;
switch (stp) {
case -1: // LONGVARCHAR
len = MY_MIN(abs(len), GetConvSize());
if (GetTypeConv() != TPC_YES)
return TYPE_ERROR;
else
len = MY_MIN(abs(len), GetConvSize());
case 12: // VARCHAR
v = 'V';
case 1: // CHAR
@ -139,17 +151,24 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v)
case 8: // DOUBLE
type = TYPE_DOUBLE;
break;
case 93: // TIMESTAMP
case 93: // TIMESTAMP, DATETIME
type = TYPE_DATE;
len = 19 + ((prec) ? (prec+1) : 0);
v = 'S';
v = (tn && toupper(tn[0]) == 'T') ? 'S' : 'E';
break;
case 91: // TYPE_DATE
case 91: // DATE, YEAR
type = TYPE_DATE;
len = 10;
v = 'D';
if (!tn || toupper(tn[0]) != 'Y') {
len = 10;
v = 'D';
} else {
len = 4;
v = 'Y';
} // endif len
break;
case 92: // TYPE_TIME
case 92: // TIME
type = TYPE_DATE;
len = 8 + ((prec) ? (prec+1) : 0);
v = 'T';
@ -174,42 +193,20 @@ int TranslateJDBCType(int stp, int prec, int& len, char& v)
static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, char *db,
char *tab, PQRYRES qrp)
{
//size_t m, n;
JCATPARM *cap;
#if defined(_DEBUG)
assert(qrp);
#endif
// 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 ((cap = (JCATPARM *)PlgDBSubAlloc(g, NULL, sizeof(JCATPARM)))) {
memset(cap, 0, sizeof(JCATPARM));
cap->Id = fid;
cap->Qrp = qrp;
cap->DB = db;
cap->Tab = tab;
} // endif cap
if (setjmp(g->jumper[++g->jump_level]) != 0) {
printf("%s\n", g->Message);
cap = NULL;
goto fin;
} // endif rc
//m = (size_t)qrp->Maxres;
//n = (size_t)qrp->Nbcol;
cap = (JCATPARM *)PlugSubAlloc(g, NULL, sizeof(JCATPARM));
memset(cap, 0, sizeof(JCATPARM));
cap->Id = fid;
cap->Qrp = qrp;
cap->DB = (PUCHAR)db;
cap->Tab = (PUCHAR)tab;
//cap->Vlen = (SQLLEN* *)PlugSubAlloc(g, NULL, n * sizeof(SQLLEN *));
//for (i = 0; i < n; i++)
// cap->Vlen[i] = (SQLLEN *)PlugSubAlloc(g, NULL, m * sizeof(SQLLEN));
//cap->Status = (UWORD *)PlugSubAlloc(g, NULL, m * sizeof(UWORD));
fin:
g->jump_level--;
return cap;
} // end of AllocCatInfo
@ -291,7 +288,8 @@ PQRYRES JDBCColumns(PGLOBAL g, char *db, char *table, char *colpat,
if (!(cap = AllocCatInfo(g, CAT_COL, db, table, qrp)))
return NULL;
cap->Pat = (PUCHAR)colpat;
// Colpat cannot be null or empty for some drivers
cap->Pat = (colpat && *colpat) ? colpat : PlugDup(g, "%");
/************************************************************************/
/* Now get the results into blocks. */
@ -399,10 +397,12 @@ PQRYRES JDBCTables(PGLOBAL g, char *db, char *tabpat, char *tabtyp,
if (info || !qrp)
return qrp;
if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp)))
// Tabpat cannot be null or empty for some drivers
if (!(cap = AllocCatInfo(g, CAT_TAB, db,
(tabpat && *tabpat) ? tabpat : PlugDup(g, "%"), qrp)))
return NULL;
cap->Pat = (PUCHAR)tabtyp;
cap->Pat = tabtyp;
if (trace)
htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol);
@ -650,11 +650,20 @@ JDBConn::JDBConn(PGLOBAL g, TDBJDBC *tdbp)
job = nullptr; // The java wrapper class object
xqid = xuid = xid = grs = readid = fetchid = typid = errid = nullptr;
prepid = xpid = pcid = nullptr;
chrfldid = intfldid = dblfldid = fltfldid = datfldid = bigfldid = nullptr;
//m_LoginTimeout = DEFAULT_LOGIN_TIMEOUT;
chrfldid = intfldid = dblfldid = fltfldid = bigfldid = nullptr;
datfldid = timfldid = tspfldid = nullptr;
//m_LoginTimeout = DEFAULT_LOGIN_TIMEOUT;
//m_QueryTimeout = DEFAULT_QUERY_TIMEOUT;
//m_UpdateOptions = 0;
Msg = NULL;
m_Wrap = (tdbp && tdbp->WrapName) ? tdbp->WrapName : GetJavaWrapper();
if (!strchr(m_Wrap, '/')) {
// Add the wrapper package name
char *wn = (char*)PlugSubAlloc(g, NULL, strlen(m_Wrap) + 10);
m_Wrap = strcat(strcpy(wn, "wrappers/"), m_Wrap);
} // endif m_Wrap
m_Driver = NULL;
m_Url = NULL;
m_User = NULL;
@ -830,17 +839,52 @@ void JDBConn::ResetJVM(void)
/***********************************************************************/
bool JDBConn::GetJVM(PGLOBAL g)
{
int ntry;
if (!LibJvm) {
char soname[512];
#if defined(__WIN__)
if (JvmPath)
strcat(strcpy(soname, JvmPath), "\\jvm.dll");
else
strcpy(soname, "jvm.dll");
for (ntry = 0; !LibJvm && ntry < 3; ntry++) {
if (!ntry && JvmPath) {
strcat(strcpy(soname, JvmPath), "\\jvm.dll");
ntry = 3; // No other try
} else if (ntry < 2 && getenv("JAVA_HOME")) {
strcpy(soname, getenv("JAVA_HOME"));
// Load the desired shared library
if (!(LibJvm = LoadLibrary(soname))) {
if (ntry == 1)
strcat(soname, "\\jre");
strcat(soname, "\\bin\\client\\jvm.dll");
} else {
// Try to find it through the registry
char version[16];
char javaKey[64] = "SOFTWARE\\JavaSoft\\Java Runtime Environment";
LONG rc;
DWORD BufferSize = 16;
strcpy(soname, "jvm.dll"); // In case it fails
if ((rc = RegGetValue(HKEY_LOCAL_MACHINE, javaKey, "CurrentVersion",
RRF_RT_ANY, NULL, (PVOID)&version, &BufferSize)) == ERROR_SUCCESS) {
strcat(strcat(javaKey, "\\"), version);
BufferSize = sizeof(soname);
if ((rc = RegGetValue(HKEY_LOCAL_MACHINE, javaKey, "RuntimeLib",
RRF_RT_ANY, NULL, (PVOID)&soname, &BufferSize)) != ERROR_SUCCESS)
printf("RegGetValue: rc=%ld\n", rc);
} // endif rc
ntry = 3; // Try this only once
} // endelse
// Load the desired shared library
LibJvm = LoadLibrary(soname);
} // endfor ntry
// Get the needed entries
if (!LibJvm) {
char buf[256];
DWORD rc = GetLastError();
@ -871,13 +915,23 @@ bool JDBConn::GetJVM(PGLOBAL g)
#else // !__WIN__
const char *error = NULL;
if (JvmPath)
strcat(strcpy(soname, JvmPath), "/libjvm.so");
else
strcpy(soname, "libjvm.so");
for (ntry = 0; !LibJvm && ntry < 2; ntry++) {
if (!ntry && JvmPath) {
strcat(strcpy(soname, JvmPath), "/libjvm.so");
ntry = 2;
} else if (!ntry && getenv("JAVA_HOME")) {
// TODO: Replace i386 by a better guess
strcat(strcpy(soname, getenv("JAVA_HOME")), "/jre/lib/i386/client/libjvm.so");
} else { // Will need LD_LIBRARY_PATH to be set
strcpy(soname, "libjvm.so");
ntry = 2;
} // endelse
LibJvm = dlopen(soname, RTLD_LAZY);
} // endfor ntry
// Load the desired shared library
if (!(LibJvm = dlopen(soname, RTLD_LAZY))) {
if (!LibJvm) {
error = dlerror();
sprintf(g->Message, MSG(SHARED_LIB_ERR), soname, SVP(error));
} else if (!(CreateJavaVM = (CRTJVM)dlsym(LibJvm, "JNI_CreateJavaVM"))) {
@ -911,7 +965,9 @@ bool JDBConn::GetJVM(PGLOBAL g)
/***********************************************************************/
int JDBConn::Open(PJPARM sop)
{
bool err = false;
jboolean jt = (trace > 0);
PGLOBAL& g = m_G;
// Link or check whether jvm library was linked
@ -951,6 +1007,11 @@ int JDBConn::Open(PJPARM sop)
#define N 1
#endif
// Java source will be compiled as ajar file installed in the plugin dir
jpop->Append(sep);
jpop->Append(GetPluginDir());
jpop->Append("JdbcInterface.jar");
//================== prepare loading of Java VM ============================
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[N]; // JVM invocation options
@ -1021,19 +1082,16 @@ int JDBConn::Open(PJPARM sop)
return RC_FX;
} // endswitch rc
//=============== Display JVM version ===============
jint ver = env->GetVersion();
printf("JVM Version %d.%d\n", ((ver>>16)&0x0f), (ver&0x0f));
} // endif rc
//=============== Display JVM version =======================================
#if defined(_DEBUG)
jint ver = env->GetVersion();
printf("JVM Version %d.%d\n", ((ver>>16)&0x0f), (ver&0x0f));
#endif //_DEBUG
// try to find the java wrapper class
jdi = env->FindClass(Wrapper);
jdi = env->FindClass(m_Wrap);
if (jdi == nullptr) {
sprintf(g->Message, "ERROR: class %s not found!", Wrapper);
sprintf(g->Message, "ERROR: class %s not found!", m_Wrap);
return RC_FX;
} // endif jdi
@ -1076,19 +1134,19 @@ int JDBConn::Open(PJPARM sop)
#endif // 0
// if class found, continue
jmethodID ctor = env->GetMethodID(jdi, "<init>", "()V");
jmethodID ctor = env->GetMethodID(jdi, "<init>", "(Z)V");
if (ctor == nullptr) {
sprintf(g->Message, "ERROR: %s constructor not found!", Wrapper);
sprintf(g->Message, "ERROR: %s constructor not found!", m_Wrap);
return RC_FX;
} else
job = env->NewObject(jdi, ctor);
job = env->NewObject(jdi, ctor, jt);
// If the object is successfully constructed,
// we can then search for the method we want to call,
// and invoke it for the object:
if (job == nullptr) {
sprintf(g->Message, "%s class object not constructed!", Wrapper);
sprintf(g->Message, "%s class object not constructed!", m_Wrap);
return RC_FX;
} // endif job
@ -1289,9 +1347,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
{
PGLOBAL& g = m_G;
jint ctyp;
jlong dtv;
jstring cn, jn = nullptr;
jobject dob;
if (rank == 0)
if (!name || (jn = env->NewStringUTF(name)) == nullptr) {
@ -1354,31 +1410,22 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
break;
case 91: // DATE
if (!gmID(g, datfldid, "DateField", "(ILjava/lang/String;)I")) {
val->SetValue((int)env->CallIntMethod(job, datfldid, (jint)rank, jn));
} else
val->Reset();
break;
case 92: // TIME
if (!gmID(g, timfldid, "TimeField", "(ILjava/lang/String;)I")) {
val->SetValue((int)env->CallIntMethod(job, timfldid, (jint)rank, jn));
} else
val->Reset();
break;
case 93: // TIMESTAMP
if (!gmID(g, datfldid, "TimestampField",
"(ILjava/lang/String;)Ljava/sql/Timestamp;")) {
dob = env->CallObjectMethod(job, datfldid, (jint)rank, jn);
if (dob) {
jclass jts = env->FindClass("java/sql/Timestamp");
if (env->ExceptionCheck()) {
val->Reset();
} else {
jmethodID getTime = env->GetMethodID(jts, "getTime", "()J");
if (getTime != nullptr) {
dtv = env->CallLongMethod(dob, getTime);
val->SetValue((int)(dtv / 1000));
} else
val->Reset();
} // endif check
} else
val->Reset();
if (!gmID(g, tspfldid, "TimestampField", "(ILjava/lang/String;)I")) {
val->SetValue((int)env->CallIntMethod(job, tspfldid, (jint)rank, jn));
} else
val->Reset();
@ -1931,9 +1978,9 @@ bool JDBConn::SetParam(JDBCCOL *colp)
{
PGLOBAL& g = m_G;
// void *buffer;
int i;
int i, ncol;
PSZ fnc = "Unknown";
uint n, ncol;
uint n;
short len, tp;
int crow = 0;
PQRYRES qrp = cap->Qrp;
@ -1956,9 +2003,7 @@ bool JDBConn::SetParam(JDBCCOL *colp)
env->SetObjectArrayElement(parms, 0, env->NewStringUTF(name.ptr(2)));
env->SetObjectArrayElement(parms, 1, env->NewStringUTF(name.ptr(1)));
env->SetObjectArrayElement(parms, 2, env->NewStringUTF(name.ptr(0)));
if (cap->Pat)
env->SetObjectArrayElement(parms, 3, env->NewStringUTF((const char*)cap->Pat));
env->SetObjectArrayElement(parms, 3, env->NewStringUTF((const char*)cap->Pat));
// Now do call the proper JDBC API
switch (cap->Id) {

View File

@ -24,7 +24,7 @@
//efine MAX_FNAME_LEN 256 // Max size of field names
//efine MAX_STRING_INFO 256 // Max size of string from SQLGetInfo
//efine MAX_DNAME_LEN 256 // Max size of Recordset names
#define MAX_CONNECT_LEN 512 // Max size of Connect string
//efine MAX_CONNECT_LEN 512 // Max size of Connect string
//efine MAX_CURSOR_NAME 18 // Max size of a cursor name
#define DEFAULT_FIELD_TYPE 0 // TYPE_NULL
@ -46,9 +46,9 @@ enum JCATINFO {
typedef struct tagJCATPARM {
JCATINFO Id; // Id to indicate function
PQRYRES Qrp; // Result set pointer
PUCHAR DB; // Database (Schema)
PUCHAR Tab; // Table name or pattern
PUCHAR Pat; // Table type or column pattern
char *DB; // Database (Schema)
char *Tab; // Table name or pattern
char *Pat; // Table type or column pattern
} JCATPARM;
typedef jint(JNICALL *CRTJVM) (JavaVM **, void **, void *);
@ -169,12 +169,15 @@ protected:
jmethodID intfldid; // The IntField method ID
jmethodID dblfldid; // The DoubleField method ID
jmethodID fltfldid; // The FloatField method ID
jmethodID datfldid; // The TimestampField method ID
jmethodID datfldid; // The DateField method ID
jmethodID timfldid; // The TimeField method ID
jmethodID tspfldid; // The TimestampField method ID
jmethodID bigfldid; // The BigintField method ID
//DWORD m_LoginTimeout;
//DWORD m_QueryTimeout;
//DWORD m_UpdateOptions;
char *Msg;
char *m_Wrap;
char m_IDQuoteChar[2];
PSZ m_Driver;
PSZ m_Url;

View File

@ -30,6 +30,10 @@
uint GetJsonGrpSize(void);
static int IsJson(UDF_ARGS *args, uint i);
static PSZ MakePSZ(PGLOBAL g, UDF_ARGS *args, int i);
static char *handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error);
static char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *is_null, char *error);
static uint JsonGrpSize = 10;
@ -1302,7 +1306,7 @@ static my_bool CalcLen(UDF_ARGS *args, my_bool obj,
{
char fn[_MAX_PATH];
unsigned long i, k, m, n;
long fl= 0, j = -1;
long fl = 0, j = -1;
reslen = args->arg_count + 2;
@ -2126,7 +2130,7 @@ my_bool json_object_nonull_init(UDF_INIT *initid, UDF_ARGS *args,
char *json_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
unsigned long *res_length, char *, char *)
{
char *str= 0;
char *str = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr;
if (!g->Xchk) {
@ -2699,7 +2703,7 @@ char *json_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif Xchk
if (!CheckMemory(g, initid, args, 2, false, false, true)) {
PJSON top= 0;
PJSON top = NULL;
PJVAL jvp;
PJSON jsp[2] = {NULL, NULL};
@ -4899,7 +4903,7 @@ char *bin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
my_bool b = true;
PJSON jsp;
PJSNX jsx;
PJVAL jvp= 0;
PJVAL jvp = NULL;
PBSON bsp = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr;
PGLOBAL gb = GetMemPtr(g, args, 0);

View File

@ -1,3 +1,4 @@
SET GLOBAL time_zone='+1:00';
CREATE DATABASE connect;
USE connect;
CREATE TABLE t2 (
@ -99,8 +100,8 @@ George San Jose 1981-08-10 2010-06-02
Sam Chicago 1979-11-22 2007-10-10
James Dallas 1992-05-13 2009-12-14
Bill Boston 1986-09-11 2008-02-10
Donald Atlanta 1999-04-01 2016-03-31
Mick New York 1980-01-20 2002-09-11
Donald Atlanta 1999-03-31 2016-03-30
Mick New York 1980-01-20 2002-09-10
Tom Seatle 2002-03-15 1970-01-01
DROP TABLE t3;
#
@ -110,7 +111,7 @@ CREATE TABLE t3 (
name CHAR(9) NOT NULL,
city CHAR(12) NOT NULL,
age INT(2))
engine=CONNECT table_type=FIX file_name='girls.txt';
ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='girls.txt' ENDING=1;
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN connect.boys b where g.city = b.city;
name name city
Mary John Boston
@ -167,8 +168,11 @@ serialno name sex title manager department secretary salary
00137 BROWNY 1 ENGINEER 40567 0319 12345 10500.00
73111 WHEELFOR 1 SALESMAN 70012 0318 24888 10030.00
00023 MARTIN 1 ENGINEER 40567 0319 12345 10000.00
#
# Option Driver is required to find the Driver class inside the executable jar file
#
USE test;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=emp CONNECTION='jdbc:mariadb://localhost:PORT/connect?user=root';
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=emp CONNECTION='jdbc:mariadb://localhost:PORT/connect?user=root' OPTION_LIST='Driver=org.mariadb.jdbc.Driver';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
@ -180,7 +184,7 @@ t1 CREATE TABLE `t1` (
`department` char(4) NOT NULL,
`secretary` char(5) NOT NULL,
`salary` double(12,2) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mariadb://localhost:PORT/connect?user=root' `TABLE_TYPE`='JDBC' `TABNAME`='emp'
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mariadb://localhost:PORT/connect?user=root' `TABLE_TYPE`='JDBC' `TABNAME`='emp' `OPTION_LIST`='Driver=org.mariadb.jdbc.Driver'
SELECT * FROM t1;
serialno name sex title manager department secretary salary
74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00
@ -260,10 +264,8 @@ DROP TABLE t2;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables CONNECTION='jdbc:mariadb://localhost:PORT/connect' option_list='User=root,Maxres=50';
SELECT * FROM t1;
Table_Cat Table_Schema Table_Name Table_Type Remark
connect NULL tx1 BASE TABLE
connect NULL tx1 TABLE
DROP TABLE t1;
DROP TABLE connect.tx1;
DROP DATABASE connect;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;
SET GLOBAL time_zone=SYSTEM;

View File

@ -1,3 +1,4 @@
SET GLOBAL time_zone='+1:00';
CREATE TABLE t1 (a int, b char(10));
INSERT INTO t1 VALUES (NULL,NULL),(0,'test00'),(1,'test01'),(2,'test02'),(3,'test03');
SELECT * FROM t1;
@ -10,6 +11,7 @@ NULL NULL
#
# Testing errors
#
SET GLOBAL time_zone='+1:00';
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=unknown';
SELECT * FROM t1;
@ -32,15 +34,13 @@ t1 CREATE TABLE `t1` (
`y` char(10) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`=JDBC
SELECT * FROM t1;
ERROR HY000: Got error 174 'ExecuteQuery: java.sql.SQLSyntaxErrorException: Unknown column 'x' in 'field list'
Query is : SELECT x, y FROM t1' from CONNECT
ERROR HY000: Got error 174 'ExecuteQuery: java.sql.SQLSyntaxErrorException: Unknown column 'x' in 'field list'' from CONNECT
DROP TABLE t1;
CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=JDBC
CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root';
ALTER TABLE t1 RENAME t1backup;
SELECT * FROM t1;
ERROR HY000: Got error 174 'ExecuteQuery: java.sql.SQLSyntaxErrorException: Table 'test.t1' doesn't exist
Query is : SELECT a, b FROM t1' from CONNECT
ERROR HY000: Got error 174 'ExecuteQuery: java.sql.SQLSyntaxErrorException: Table 'test.t1' doesn't exist' from CONNECT
ALTER TABLE t1backup RENAME t1;
DROP TABLE t1;
#
@ -201,16 +201,15 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`b` datetime DEFAULT NULL,
`c` time DEFAULT NULL,
`d` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`e` date DEFAULT NULL
`d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`e` year(4) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='jdbc:mysql://127.0.0.1:SLAVE_PORT/test?user=root' `TABLE_TYPE`='JDBC'
SELECT * FROM t1;
a b c d e
2003-05-27 2003-05-27 10:45:23 10:45:23 2003-05-27 10:45:23 1970-01-01
2003-05-27 2003-05-27 11:45:23 10:45:23 2003-05-27 10:45:23 2003
DROP TABLE t1;
DROP TABLE t1;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;
SET GLOBAL time_zone=SYSTEM;
SET GLOBAL time_zone=SYSTEM;

View File

@ -1,4 +1,5 @@
-- source jdbconn.inc
SET GLOBAL time_zone='+1:00';
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MTR_SUITE_DIR/std_data/girls.txt $MYSQLD_DATADIR/test/girls.txt
@ -80,7 +81,7 @@ CREATE TABLE t3 (
name CHAR(9) NOT NULL,
city CHAR(12) NOT NULL,
age INT(2))
engine=CONNECT table_type=FIX file_name='girls.txt';
ENGINE=CONNECT TABLE_TYPE=FIX FILE_NAME='girls.txt' ENDING=1;
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN connect.boys b where g.city = b.city;
SELECT g.name, b.name, g.city FROM t3 g STRAIGHT_JOIN t1 b where g.city = b.city;
DROP TABLE t1, t3, connect.boys;
@ -102,9 +103,12 @@ CREATE TABLE emp (
ENGINE=connect TABLE_TYPE=fix FILE_NAME='employee.dat' ENDING=1;
SELECT * FROM emp;
--echo #
--echo # Option Driver is required to find the Driver class inside the executable jar file
--echo #
USE test;
--replace_result $PORT PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=emp CONNECTION='jdbc:mariadb://localhost:$PORT/connect?user=root'
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC TABNAME=emp CONNECTION='jdbc:mariadb://localhost:$PORT/connect?user=root' OPTION_LIST='Driver=org.mariadb.jdbc.Driver'
--replace_result $PORT PORT
--eval SHOW CREATE TABLE t1
SELECT * FROM t1;
@ -113,7 +117,7 @@ SELECT name, title, salary FROM t1 WHERE sex = 1;
DROP TABLE t1, connect.emp;
#
# Testing remote command execution
# Testing remote command execution (Driver option is no more necessary)
#
--replace_result $PORT PORT
--eval CREATE TABLE t2 (command varchar(128) not null,number int(5) not null flag=1,message varchar(255) flag=2) ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:mariadb://localhost:$PORT/connect' OPTION_LIST='User=root,Execsrc=1'
@ -139,5 +143,5 @@ DROP TABLE connect.tx1;
--remove_file $MYSQLD_DATADIR/connect/employee.dat
DROP DATABASE connect;
--remove_file $MYSQLD_DATADIR/test/girls.txt
SET GLOBAL time_zone=SYSTEM;
-- source jdbconn_cleanup.inc

View File

@ -8,6 +8,8 @@ connection master;
-- source jdbconn.inc
connection slave;
SET GLOBAL time_zone='+1:00';
CREATE TABLE t1 (a int, b char(10));
INSERT INTO t1 VALUES (NULL,NULL),(0,'test00'),(1,'test01'),(2,'test02'),(3,'test03');
SELECT * FROM t1;
@ -16,6 +18,7 @@ SELECT * FROM t1;
--echo # Testing errors
--echo #
connection master;
SET GLOBAL time_zone='+1:00';
# Bad user name
# Suppress "mysql_real_connect failed:" (printed in _DEBUG build)
@ -173,7 +176,9 @@ DROP TABLE t1;
connection slave;
DROP TABLE t1;
SET GLOBAL time_zone=SYSTEM;
connection master;
SET GLOBAL time_zone=SYSTEM;
-- source jdbconn_cleanup.inc

View File

@ -12,19 +12,20 @@ if (!`SELECT count(*) FROM INFORMATION_SCHEMA.TABLES
}
DROP TABLE t1;
# This is specific and explains why this test is disabled.
# You should edit this file to reflect what is the required files location on your machine.
# You cand edit this file to reflect what is the required files location on your machine.
# This is the path to the JVM library (dll or so)
SET GLOBAL connect_jvm_path='C:\\Program Files\\Java\\jdk1.8.0_77\\jre\\bin\\client';
# If not set CONNECT will try to use the JAVA_HOME environment variable
# and if not found try to find it in the registers (Windows only)
#SET GLOBAL connect_jvm_path='C:\\Program Files\\Java\\jdk1.8.0_77\\jre\\bin\\client';
# The complete class path send when creating the Java Virtual Machine is, in that order:
# 1 - The current directory.
# 2 - The paths of the connect_class_path global variable.
# 3 - The paths of the CLASSPATH environment variable.
# These are the paths to the needed classes or jar files. The Apache ones are only for the JdbcApacheInterface wrapper.
SET GLOBAL connect_class_path='E:\\MariaDB-10.1\\Connect\\storage\\connect;E:\\MariaDB-10.1\\Connect\\sql\\data\\postgresql-9.4.1208.jar;E:\\Oracle\\ojdbc6.jar;E:\\Apache\\commons-dbcp2-2.1.1\\commons-dbcp2-2.1.1.jar;E:\\Apache\\commons-pool2-2.4.2\\commons-pool2-2.4.2.jar;E:\\Apache\\commons-logging-1.2\\commons-logging-1.2.jar';
# In this test we use an executable jar file that contains all what is needed.
eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/JdbcMariaDB.jar';
# On my machine, paths to the JDK classes and to the MySQL and MariaDB drivers are defined in the CLASSPATH environment variable
# Paths to the JDK classes and to the MySQL and MariaDB drivers can be defined in the CLASSPATH environment variable
#CREATE FUNCTION envar RETURNS STRING SONAME 'ha_connect.dll';
#SELECT envar('CLASSPATH');

View File

@ -1,6 +1,8 @@
--disable_query_log
--disable_warnings
#DROP FUNCTION envar;
SET GLOBAL connect_jvm_path=NULL;
SET GLOBAL connect_class_path=NULL;
SET GLOBAL time_zone = SYSTEM;
--enable_warnings
--enable_query_log

View File

@ -21,5 +21,5 @@ PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *db, char *table,
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, bool info, POPARM sop);
char *tabtyp, int maxres, bool info, POPARM sop);
PQRYRES ODBCDrivers(PGLOBAL g, int maxres, bool info);

View File

@ -53,6 +53,7 @@
extern "C" HINSTANCE s_hModule; // Saved module handle
#endif // __WIN__
TYPCONV GetTypeConv();
int GetConvSize();
/***********************************************************************/
@ -135,9 +136,13 @@ int TranslateSQLType(int stp, int prec, int& len, char& v, bool& w)
case SQL_WLONGVARCHAR: // (-10)
w = true;
case SQL_LONGVARCHAR: // (-1)
v = 'V';
type = TYPE_STRING;
len = MY_MIN(abs(len), GetConvSize());
if (GetTypeConv() == TPC_YES) {
v = 'V';
type = TYPE_STRING;
len = MY_MIN(abs(len), GetConvSize());
} else
type = TYPE_ERROR;
break;
case SQL_NUMERIC: // 2
case SQL_DECIMAL: // 3
@ -606,7 +611,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, bool info, POPARM sop)
char *tabtyp, int maxres, bool info, POPARM sop)
{
int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_STRING};
@ -668,7 +673,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *db, char *tabpat,
if (!(cap = AllocCatInfo(g, CAT_TAB, db, tabpat, qrp)))
return NULL;
//cap->Pat = (PUCHAR)tabtyp;
cap->Pat = (PUCHAR)tabtyp;
if (trace)
htrc("Getting table results ncol=%d\n", cap->Qrp->Nbcol);
@ -1752,7 +1757,7 @@ bool ODBConn::BindParam(ODBCCOL *colp)
void *buf;
int buftype = colp->GetResultType();
SQLUSMALLINT n = colp->GetRank();
SQLSMALLINT ct, sqlt, dec, nul;
SQLSMALLINT ct, sqlt, dec, nul __attribute__((unused));
SQLULEN colsize;
SQLLEN len;
SQLLEN *strlen = colp->GetStrLen();

View File

@ -25,7 +25,7 @@
//efine MAX_FNAME_LEN 256 // Max size of field names
#define MAX_STRING_INFO 256 // Max size of string from SQLGetInfo
//efine MAX_DNAME_LEN 256 // Max size of Recordset names
#define MAX_CONNECT_LEN 512 // Max size of Connect string
#define MAX_CONNECT_LEN 1024 // Max size of Connect string
//efine MAX_CURSOR_NAME 18 // Max size of a cursor name
#define DEFAULT_FIELD_TYPE SQL_TYPE_NULL // pick "C" data type to match SQL data type

View File

@ -96,7 +96,7 @@ bool ExactInfo(void);
/***********************************************************************/
JDBCDEF::JDBCDEF(void)
{
Driver = Url = Tabname = Tabschema = Username = NULL;
Driver = Url = Wrapname =Tabname = Tabschema = Username = Colpat = NULL;
Password = Tabcat = Tabtype = Srcdef = Qchar = Qrystr = Sep = NULL;
Options = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = false;
@ -233,11 +233,18 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
Read_Only = true;
Wrapname = GetStringCatInfo(g, "Wrapper", NULL);
Tabcat = GetStringCatInfo(g, "Qualifier", NULL);
Tabcat = GetStringCatInfo(g, "Catalog", Tabcat);
Tabschema = GetStringCatInfo(g, "Dbname", NULL);
Tabschema = GetStringCatInfo(g, "Schema", Tabschema);
Tabtype = GetStringCatInfo(g, "Tabtype", NULL);
if (Catfunc == FNC_COL)
Colpat = GetStringCatInfo(g, "Colpat", NULL);
if (Catfunc == FNC_TABLE)
Tabtype = GetStringCatInfo(g, "Tabtype", NULL);
Qrystr = GetStringCatInfo(g, "Query_String", "?");
Sep = GetStringCatInfo(g, "Separator", NULL);
Xsrc = GetBoolCatInfo("Execsrc", FALSE);
@ -325,6 +332,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
if (tdp) {
Ops.Driver = tdp->Driver;
Ops.Url = tdp->Url;
WrapName = tdp->Wrapname;
TableName = tdp->Tabname;
Schema = tdp->Tabschema;
Ops.User = tdp->Username;
@ -341,6 +349,7 @@ TDBJDBC::TDBJDBC(PJDBCDEF tdp) : TDBASE(tdp)
Memory = tdp->Memory;
Ops.Scrollable = tdp->Scrollable;
} else {
WrapName = NULL;
TableName = NULL;
Schema = NULL;
Ops.Driver = NULL;
@ -386,6 +395,7 @@ TDBJDBC::TDBJDBC(PTDBJDBC tdbp) : TDBASE(tdbp)
{
Jcp = tdbp->Jcp; // is that right ?
Cnp = tdbp->Cnp;
WrapName = tdbp->WrapName;
TableName = tdbp->TableName;
Schema = tdbp->Schema;
Ops = tdbp->Ops;
@ -512,9 +522,10 @@ bool TDBJDBC::MakeSQL(PGLOBAL g, bool cnt)
if (Catalog && *Catalog)
catp = Catalog;
if (tablep->GetSchema())
schmp = (char*)tablep->GetSchema();
else if (Schema && *Schema)
//if (tablep->GetSchema())
// schmp = (char*)tablep->GetSchema();
//else
if (Schema && *Schema)
schmp = Schema;
if (catp) {
@ -596,9 +607,10 @@ bool TDBJDBC::MakeInsert(PGLOBAL g)
if (catp)
len += strlen(catp) + 1;
if (tablep->GetSchema())
schmp = (char*)tablep->GetSchema();
else if (Schema && *Schema)
//if (tablep->GetSchema())
// schmp = (char*)tablep->GetSchema();
//else
if (Schema && *Schema)
schmp = Schema;
if (schmp)
@ -1787,12 +1799,20 @@ PQRYRES TDBJTB::GetResult(PGLOBAL g)
/* --------------------------TDBJDBCL class -------------------------- */
/***********************************************************************/
/* TDBJDBCL class constructor. */
/***********************************************************************/
TDBJDBCL::TDBJDBCL(PJDBCDEF tdp) : TDBJTB(tdp)
{
Colpat = tdp->Colpat;
} // end of TDBJDBCL constructor
/***********************************************************************/
/* GetResult: Get the list of JDBC table columns. */
/***********************************************************************/
PQRYRES TDBJDBCL::GetResult(PGLOBAL g)
{
return JDBCColumns(g, Schema, Tab, NULL, Maxres, false, &Ops);
return JDBCColumns(g, Schema, Tab, Colpat, Maxres, false, &Ops);
} // end of GetResult
#if 0

View File

@ -26,6 +26,7 @@ class DllExport JDBCDEF : public TABDEF { /* Logical table description */
friend class TDBXJDC;
friend class TDBJDRV;
friend class TDBJTB;
friend class TDBJDBCL;
public:
// Constructor
JDBCDEF(void);
@ -53,11 +54,13 @@ protected:
PSZ Driver; /* JDBC driver */
PSZ Url; /* JDBC driver URL */
PSZ Tabname; /* External table name */
PSZ Wrapname; /* Java wrapper name */
PSZ Tabschema; /* External table schema */
PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */
PSZ Tabtype; /* External table type */
PSZ Colpat; /* Catalog column pattern */
PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */
PSZ Qrystr; /* The original query */
@ -131,6 +134,7 @@ protected:
JDBCCOL *Cnp; // Points to count(*) column
JDBCPARM Ops; // Additional parameters
PSTRG Query; // Constructed SQL query
char *WrapName; // Points to Java wrapper name
char *TableName; // Points to JDBC table name
char *Schema; // Points to JDBC table Schema
char *User; // User connect info
@ -317,14 +321,15 @@ protected:
class TDBJDBCL : public TDBJTB {
public:
// Constructor
TDBJDBCL(PJDBCDEF tdp) : TDBJTB(tdp) {}
TDBJDBCL(PJDBCDEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);
// No additional Members
}; // end of class TDBJCL
// Members
char *Colpat; // Points to catalog column pattern
}; // end of class TDBJDBCL
#if 0
/***********************************************************************/

View File

@ -1,7 +1,7 @@
/************* Tabodbc C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: TABODBC */
/* ------------- */
/* Version 3.0 */
/* Version 3.1 */
/* */
/* COPYRIGHT: */
/* ---------- */
@ -96,7 +96,7 @@ bool ExactInfo(void);
ODBCDEF::ODBCDEF(void)
{
Connect = Tabname = Tabschema = Username = Password = NULL;
Tabcat = Srcdef = Qchar = Qrystr = Sep = NULL;
Tabcat = Colpat = Srcdef = Qchar = Qrystr = Sep = NULL;
Catver = Options = Cto = Qto = Quoted = Maxerr = Maxres = Memory = 0;
Scrollable = Xsrc = UseCnc = false;
} // end of ODBCDEF constructor
@ -120,7 +120,7 @@ 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);
Username = GetStringCatInfo(g, "User", NULL);
Password = GetStringCatInfo(g, "Password", NULL);
if ((Srcdef = GetStringCatInfo(g, "Srcdef", NULL)))
@ -141,7 +141,13 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if ((Scrollable = GetBoolCatInfo("Scrollable", false)) && !Elemt)
Elemt = 1; // Cannot merge SQLFetch and SQLExtendedFetch
UseCnc = GetBoolCatInfo("UseDSN", false);
if (Catfunc == FNC_COL)
Colpat = GetStringCatInfo(g, "Colpat", NULL);
if (Catfunc == FNC_TABLE)
Tabtyp = GetStringCatInfo(g, "Tabtype", NULL);
UseCnc = GetBoolCatInfo("UseDSN", false);
// Memory was Boolean, it is now integer
if (!(Memory = GetIntCatInfo("Memory", 0)))
@ -452,9 +458,14 @@ bool TDBODBC::MakeSQL(PGLOBAL g, bool cnt)
if (Catalog && *Catalog)
catp = Catalog;
if (tablep->GetSchema())
schmp = (char*)tablep->GetSchema();
else if (Schema && *Schema)
// Following lines are commented because of MSDEV-10520
// Indeed the schema in the tablep is the local table database and
// is normally not related to the remote table database.
// TODO: Try to remember why this was done and if it was useful in some case.
//if (tablep->GetSchema())
// schmp = (char*)tablep->GetSchema();
//else
if (Schema && *Schema)
schmp = Schema;
if (catp) {
@ -535,9 +546,10 @@ bool TDBODBC::MakeInsert(PGLOBAL g)
if (catp)
len += strlen(catp) + 1;
if (tablep->GetSchema())
schmp = (char*)tablep->GetSchema();
else if (Schema && *Schema)
//if (tablep->GetSchema())
// schmp = (char*)tablep->GetSchema();
//else
if (Schema && *Schema)
schmp = Schema;
if (schmp)
@ -681,7 +693,7 @@ bool TDBODBC::MakeCommand(PGLOBAL g)
} else {
sprintf(g->Message, "Cannot use this %s command",
(Mode == MODE_UPDATE) ? "UPDATE" : "DELETE");
return NULL;
return false;
} // endif p
Query = new(g) STRING(g, 0, stmt);
@ -1768,6 +1780,7 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
Dsn = tdp->GetConnect();
Schema = tdp->GetTabschema();
Tab = tdp->GetTabname();
Tabtyp = tdp->Tabtyp;
Ops.User = tdp->Username;
Ops.Pwd = tdp->Password;
Ops.Cto = tdp->Cto;
@ -1780,17 +1793,25 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp)
/***********************************************************************/
PQRYRES TDBOTB::GetResult(PGLOBAL g)
{
return ODBCTables(g, Dsn, Schema, Tab, Maxres, false, &Ops);
return ODBCTables(g, Dsn, Schema, Tab, Tabtyp, Maxres, false, &Ops);
} // end of GetResult
/* ---------------------------TDBOCL class --------------------------- */
/***********************************************************************/
/* TDBOCL class constructor. */
/***********************************************************************/
TDBOCL::TDBOCL(PODEF tdp) : TDBOTB(tdp)
{
Colpat = tdp->Colpat;
} // end of TDBOTB constructor
/***********************************************************************/
/* GetResult: Get the list of ODBC table columns. */
/***********************************************************************/
PQRYRES TDBOCL::GetResult(PGLOBAL g)
{
return ODBCColumns(g, Dsn, Schema, Tab, NULL, Maxres, false, &Ops);
return ODBCColumns(g, Dsn, Schema, Tab, Colpat, Maxres, false, &Ops);
} // end of GetResult
/* ------------------------ End of Tabodbc --------------------------- */

View File

@ -25,7 +25,8 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
friend class TDBXDBC;
friend class TDBDRV;
friend class TDBOTB;
public:
friend class TDBOCL;
public:
// Constructor
ODBCDEF(void);
@ -54,7 +55,9 @@ class DllExport ODBCDEF : public TABDEF { /* Logical table description */
PSZ Username; /* User connect name */
PSZ Password; /* Password connect info */
PSZ Tabcat; /* External table catalog */
PSZ Srcdef; /* The source table SQL definition */
PSZ Tabtyp; /* Catalog table type */
PSZ Colpat; /* Catalog column pattern */
PSZ Srcdef; /* The source table SQL definition */
PSZ Qchar; /* Identifier quoting character */
PSZ Qrystr; /* The original query */
PSZ Sep; /* Decimal separator */
@ -326,7 +329,8 @@ 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
ODBCPARM Ops; // Additional parameters
char *Tabtyp; // Points to ODBC table type
ODBCPARM Ops; // Additional parameters
}; // end of class TDBOTB
/***********************************************************************/
@ -335,13 +339,14 @@ class TDBOTB : public TDBDRV {
class TDBOCL : public TDBOTB {
public:
// Constructor
TDBOCL(PODEF tdp) : TDBOTB(tdp) {}
TDBOCL(PODEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);
// No additional Members
// Members
char *Colpat; // Points to column pattern
}; // end of class TDBOCL
#endif // !NODBC

View File

@ -1198,7 +1198,7 @@ bool XINDEX::MapInit(PGLOBAL g)
const char *ftype;
BYTE *mbase;
char fn[_MAX_PATH];
int *nv, k, n, id = -1;
int *nv, nv0, k, n, id = -1;
bool estim;
PCOL colp;
PXCOL prev = NULL, kcp = NULL;
@ -1288,25 +1288,26 @@ bool XINDEX::MapInit(PGLOBAL g)
if (nv[0] >= MAX_INDX) {
// New index format
Srtd = nv[7] != 0;
nv[0] -= MAX_INDX;
nv0 = nv[0] - MAX_INDX;
mbase += NZ * sizeof(int);
} else {
Srtd = false;
mbase += (NZ - 1) * sizeof(int);
nv0 = nv[0];
} // endif nv
if (trace)
htrc("nv=%d %d %d %d %d %d %d %d\n",
nv[0], nv[1], nv[2], nv[3], nv[4], nv[5], nv[6], Srtd);
nv0, nv[1], nv[2], nv[3], nv[4], nv[5], nv[6], Srtd);
// The test on ID was suppressed because MariaDB can change an index ID
// when other indexes are added or deleted
if (/*nv[0] != ID ||*/ nv[1] != Nk) {
if (/*nv0 != ID ||*/ nv[1] != Nk) {
// Not this index
sprintf(g->Message, MSG(BAD_INDEX_FILE), fn);
if (trace)
htrc("nv[0]=%d ID=%d nv[1]=%d Nk=%d\n", nv[0], ID, nv[1], Nk);
htrc("nv0=%d ID=%d nv[1]=%d Nk=%d\n", nv0, ID, nv[1], Nk);
goto err;
} // endif nv

View File

@ -265,13 +265,15 @@ FTS auxiliary INDEX table and clear the cache at the end.
@param[in,out] sync sync state
@param[in] unlock_cache whether unlock cache lock when write node
@param[in] wait whether wait when a sync is in progress
@param[in] has_dict whether has dict operation lock
@return DB_SUCCESS if all OK */
static
dberr_t
fts_sync(
fts_sync_t* sync,
bool unlock_cache,
bool wait);
bool wait,
bool has_dict);
/****************************************************************//**
Release all resources help by the words rb tree e.g., the node ilist. */
@ -3567,7 +3569,7 @@ fts_add_doc_by_id(
DBUG_EXECUTE_IF(
"fts_instrument_sync_debug",
fts_sync(cache->sync, true, true);
fts_sync(cache->sync, true, true, false);
);
DEBUG_SYNC_C("fts_instrument_sync_request");
@ -4379,13 +4381,11 @@ fts_sync_index(
}
/** Check if index cache has been synced completely
@param[in,out] sync sync state
@param[in,out] index_cache index cache
@return true if index is synced, otherwise false. */
static
bool
fts_sync_index_check(
fts_sync_t* sync,
fts_index_cache_t* index_cache)
{
const ib_rbt_node_t* rbt_node;
@ -4408,14 +4408,36 @@ fts_sync_index_check(
return(true);
}
/*********************************************************************//**
Commit the SYNC, change state of processed doc ids etc.
/** Reset synced flag in index cache when rollback
@param[in,out] index_cache index cache */
static
void
fts_sync_index_reset(
fts_index_cache_t* index_cache)
{
const ib_rbt_node_t* rbt_node;
for (rbt_node = rbt_first(index_cache->words);
rbt_node != NULL;
rbt_node = rbt_next(index_cache->words, rbt_node)) {
fts_tokenizer_word_t* word;
word = rbt_value(fts_tokenizer_word_t, rbt_node);
fts_node_t* fts_node;
fts_node = static_cast<fts_node_t*>(ib_vector_last(word->nodes));
fts_node->synced = false;
}
}
/** Commit the SYNC, change state of processed doc ids etc.
@param[in,out] sync sync state
@return DB_SUCCESS if all OK */
static MY_ATTRIBUTE((nonnull, warn_unused_result))
dberr_t
fts_sync_commit(
/*============*/
fts_sync_t* sync) /*!< in: sync state */
fts_sync_t* sync)
{
dberr_t error;
trx_t* trx = sync->trx;
@ -4468,6 +4490,8 @@ fts_sync_commit(
(double) n_nodes/ (double) elapsed_time);
}
/* Avoid assertion in trx_free(). */
trx->dict_operation_lock_mode = 0;
trx_free_for_background(trx);
return(error);
@ -4490,6 +4514,10 @@ fts_sync_rollback(
index_cache = static_cast<fts_index_cache_t*>(
ib_vector_get(cache->indexes, i));
/* Reset synced flag so nodes will not be skipped
in the next sync, see fts_sync_write_words(). */
fts_sync_index_reset(index_cache);
for (j = 0; fts_index_selector[j].value; ++j) {
if (index_cache->ins_graph[j] != NULL) {
@ -4515,6 +4543,9 @@ fts_sync_rollback(
rw_lock_x_unlock(&cache->lock);
fts_sql_rollback(trx);
/* Avoid assertion in trx_free(). */
trx->dict_operation_lock_mode = 0;
trx_free_for_background(trx);
}
@ -4523,13 +4554,15 @@ FTS auxiliary INDEX table and clear the cache at the end.
@param[in,out] sync sync state
@param[in] unlock_cache whether unlock cache lock when write node
@param[in] wait whether wait when a sync is in progress
@param[in] has_dict whether has dict operation lock
@return DB_SUCCESS if all OK */
static
dberr_t
fts_sync(
fts_sync_t* sync,
bool unlock_cache,
bool wait)
bool wait,
bool has_dict)
{
ulint i;
dberr_t error = DB_SUCCESS;
@ -4558,6 +4591,12 @@ fts_sync(
DEBUG_SYNC_C("fts_sync_begin");
fts_sync_begin(sync);
/* When sync in background, we hold dict operation lock
to prevent DDL like DROP INDEX, etc. */
if (has_dict) {
sync->trx->dict_operation_lock_mode = RW_S_LATCH;
}
begin_sync:
if (cache->total_size > fts_max_cache_size) {
/* Avoid the case: sync never finish when
@ -4598,7 +4637,7 @@ begin_sync:
ib_vector_get(cache->indexes, i));
if (index_cache->index->to_be_dropped
|| fts_sync_index_check(sync, index_cache)) {
|| fts_sync_index_check(index_cache)) {
continue;
}
@ -4613,6 +4652,7 @@ end_sync:
}
rw_lock_x_lock(&cache->lock);
sync->interrupted = false;
sync->in_progress = false;
os_event_set(sync->event);
rw_lock_x_unlock(&cache->lock);
@ -4636,20 +4676,23 @@ FTS auxiliary INDEX table and clear the cache at the end.
@param[in,out] table fts table
@param[in] unlock_cache whether unlock cache when write node
@param[in] wait whether wait for existing sync to finish
@param[in] has_dict whether has dict operation lock
@return DB_SUCCESS on success, error code on failure. */
UNIV_INTERN
dberr_t
fts_sync_table(
dict_table_t* table,
bool unlock_cache,
bool wait)
bool wait,
bool has_dict)
{
dberr_t err = DB_SUCCESS;
ut_ad(table->fts);
if (!dict_table_is_discarded(table) && table->fts->cache) {
err = fts_sync(table->fts->cache->sync, unlock_cache, wait);
err = fts_sync(table->fts->cache->sync,
unlock_cache, wait, has_dict);
}
return(err);

View File

@ -2986,7 +2986,7 @@ fts_optimize_sync_table(
if (table) {
if (dict_table_has_fts_index(table) && table->fts->cache) {
fts_sync_table(table, true, false);
fts_sync_table(table, true, false, true);
}
dict_table_close(table, FALSE, FALSE);

View File

@ -6966,6 +6966,7 @@ dberr_t
ha_innobase::innobase_lock_autoinc(void)
/*====================================*/
{
DBUG_ENTER("ha_innobase::innobase_lock_autoinc");
dberr_t error = DB_SUCCESS;
ut_ad(!srv_read_only_mode);
@ -7005,6 +7006,8 @@ ha_innobase::innobase_lock_autoinc(void)
/* Fall through to old style locking. */
case AUTOINC_OLD_STYLE_LOCKING:
DBUG_EXECUTE_IF("die_if_autoinc_old_lock_style_used",
ut_ad(0););
error = row_lock_table_autoinc_for_mysql(prebuilt);
if (error == DB_SUCCESS) {
@ -7018,7 +7021,7 @@ ha_innobase::innobase_lock_autoinc(void)
ut_error;
}
return(error);
DBUG_RETURN(error);
}
/********************************************************************//**
@ -11895,7 +11898,7 @@ ha_innobase::optimize(
if (innodb_optimize_fulltext_only) {
if (prebuilt->table->fts && prebuilt->table->fts->cache
&& !dict_table_is_discarded(prebuilt->table)) {
fts_sync_table(prebuilt->table, false, true);
fts_sync_table(prebuilt->table, false, true, false);
fts_optimize_table(prebuilt->table);
}
return(HA_ADMIN_OK);

View File

@ -1,6 +1,6 @@
/*****************************************************************************
Copyright (c) 2007, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2007, 2016, 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
@ -2963,15 +2963,26 @@ i_s_fts_deleted_generic_fill(
DBUG_RETURN(0);
}
deleted = fts_doc_ids_create();
/* Prevent DDL to drop fts aux tables. */
rw_lock_s_lock(&dict_operation_lock);
user_table = dict_table_open_on_name(
fts_internal_tbl_name, FALSE, FALSE, DICT_ERR_IGNORE_NONE);
if (!user_table) {
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
} else if (!dict_table_has_fts_index(user_table)) {
dict_table_close(user_table, FALSE, FALSE);
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
}
deleted = fts_doc_ids_create();
trx = trx_allocate_for_background();
trx->op_info = "Select for FTS DELETE TABLE";
@ -2999,6 +3010,8 @@ i_s_fts_deleted_generic_fill(
dict_table_close(user_table, FALSE, FALSE);
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
}
@ -3372,6 +3385,12 @@ i_s_fts_index_cache_fill(
DBUG_RETURN(0);
}
if (user_table->fts == NULL || user_table->fts->cache == NULL) {
dict_table_close(user_table, FALSE, FALSE);
DBUG_RETURN(0);
}
cache = user_table->fts->cache;
ut_a(cache);
@ -3806,10 +3825,15 @@ i_s_fts_index_table_fill(
DBUG_RETURN(0);
}
/* Prevent DDL to drop fts aux tables. */
rw_lock_s_lock(&dict_operation_lock);
user_table = dict_table_open_on_name(
fts_internal_tbl_name, FALSE, FALSE, DICT_ERR_IGNORE_NONE);
if (!user_table) {
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
}
@ -3822,6 +3846,8 @@ i_s_fts_index_table_fill(
dict_table_close(user_table, FALSE, FALSE);
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
}
@ -3957,14 +3983,21 @@ i_s_fts_config_fill(
fields = table->field;
/* Prevent DDL to drop fts aux tables. */
rw_lock_s_lock(&dict_operation_lock);
user_table = dict_table_open_on_name(
fts_internal_tbl_name, FALSE, FALSE, DICT_ERR_IGNORE_NONE);
if (!user_table) {
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
} else if (!dict_table_has_fts_index(user_table)) {
dict_table_close(user_table, FALSE, FALSE);
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
}
@ -4020,6 +4053,8 @@ i_s_fts_config_fill(
dict_table_close(user_table, FALSE, FALSE);
rw_lock_s_unlock(&dict_operation_lock);
DBUG_RETURN(0);
}

View File

@ -840,13 +840,15 @@ FTS auxiliary INDEX table and clear the cache at the end.
@param[in,out] table fts table
@param[in] unlock_cache whether unlock cache when write node
@param[in] wait whether wait for existing sync to finish
@param[in] has_dict whether has dict operation lock
@return DB_SUCCESS on success, error code on failure. */
UNIV_INTERN
dberr_t
fts_sync_table(
dict_table_t* table,
bool unlock_cache,
bool wait);
bool wait,
bool has_dict);
/****************************************************************//**
Free the query graph but check whether dict_sys->mutex is already

View File

@ -479,20 +479,13 @@ os_atomic_test_and_set(volatile lock_word_t* ptr)
}
/** Do an atomic release.
In theory __sync_lock_release should be used to release the lock.
Unfortunately, it does not work properly alone. The workaround is
that more conservative __sync_lock_test_and_set is used instead.
Performance regression was observed at some conditions for Intel
architecture. Disable release barrier on Intel architecture for now.
@param[in,out] ptr Memory location to write to
@return the previous value */
inline
lock_word_t
void
os_atomic_clear(volatile lock_word_t* ptr)
{
return(__sync_lock_test_and_set(ptr, 0));
__sync_lock_release(ptr);
}
# elif defined(HAVE_IB_GCC_ATOMIC_TEST_AND_SET)
@ -861,7 +854,7 @@ for synchronization */
architecture. Disable memory barrier for Intel architecture for now. */
# define os_rmb do { } while(0)
# define os_wmb do { } while(0)
# define os_isync do { } while(0)
# define os_mb do { } while(0)
# define IB_MEMORY_BARRIER_STARTUP_MSG \
"Memory barrier is not used"
#elif defined(HAVE_IB_GCC_ATOMIC_THREAD_FENCE)

View File

@ -178,6 +178,11 @@ mutex_exit_func(
to wake up possible hanging threads if
they are missed in mutex_signal_object. */
/* We add a memory barrier to prevent reading of the
number of waiters before releasing the lock. */
os_mb;
if (mutex_get_waiters(mutex) != 0) {
mutex_signal_object(mutex);

View File

@ -44,7 +44,7 @@ Created 1/20/1994 Heikki Tuuri
#define INNODB_VERSION_MAJOR 5
#define INNODB_VERSION_MINOR 6
#define INNODB_VERSION_BUGFIX 31
#define INNODB_VERSION_BUGFIX 32
/* The following is the InnoDB version as shown in
SELECT plugin_version FROM information_schema.plugins;

View File

@ -1055,6 +1055,26 @@ use_heap:
insert_rec = rec_copy(insert_buf, rec, offsets);
rec_offs_make_valid(insert_rec, index, offsets);
/* This is because assertion below is debug assertion */
#ifdef UNIV_DEBUG
if (UNIV_UNLIKELY(current_rec == insert_rec)) {
ulint extra_len, data_len;
extra_len = rec_offs_extra_size(offsets);
data_len = rec_offs_data_size(offsets);
fprintf(stderr, "InnoDB: Error: current_rec == insert_rec "
" extra_len %lu data_len %lu insert_buf %p rec %p\n",
extra_len, data_len, insert_buf, rec);
fprintf(stderr, "InnoDB; Physical record: \n");
rec_print(stderr, rec, index);
fprintf(stderr, "InnoDB: Inserted record: \n");
rec_print(stderr, insert_rec, index);
fprintf(stderr, "InnoDB: Current record: \n");
rec_print(stderr, current_rec, index);
ut_a(current_rec != insert_rec);
}
#endif /* UNIV_DEBUG */
/* 4. Insert the record in the linked list of records */
ut_ad(current_rec != insert_rec);

View File

@ -1987,7 +1987,7 @@ wait_again:
/* Sync fts cache for other fts indexes to keep all
fts indexes consistent in sync_doc_id. */
err = fts_sync_table(const_cast<dict_table_t*>(new_table),
false, true);
false, true, false);
if (err == DB_SUCCESS) {
fts_update_next_doc_id(

Some files were not shown because too many files have changed in this diff Show More