Commit aaa982e7 authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix good recognition of MYSQL table column types.

modified:
  storage/connect/ha_connect.cc
  storage/connect/myconn.cpp
  storage/connect/myutil.cpp
  storage/connect/odbccat.h
  storage/connect/odbconn.cpp
  storage/connect/tabmysql.cpp

- Add tests on new MYSQL features

added:
  storage/connect/mysql-test/connect/my.cnf
  storage/connect/mysql-test/connect/r/mysql_discovery.result
  storage/connect/mysql-test/connect/r/mysql_exec.result
  storage/connect/mysql-test/connect/r/mysql_new.result
  storage/connect/mysql-test/connect/t/myconn.inc
  storage/connect/mysql-test/connect/t/myconn_cleanup.inc
  storage/connect/mysql-test/connect/t/mysql_discovery.test
  storage/connect/mysql-test/connect/t/mysql_exec.test
  storage/connect/mysql-test/connect/t/mysql_new.test
parent 8780e1ab
......@@ -1308,6 +1308,9 @@ int ha_connect::MakeRecord(char *buf)
case MYSQL_TYPE_TIME:
fmt= "%H:%M:%S";
break;
case MYSQL_TYPE_YEAR:
fmt= "%Y";
break;
default:
fmt= "%Y-%m-%d %H:%M:%S";
break;
......@@ -1409,7 +1412,7 @@ int ha_connect::ScanRecord(PGLOBAL g, uchar *buf)
value->SetValue(fp->val_real());
break;
case TYPE_DATE:
if (!sdvalin) {
if (!sdvalin)
sdvalin= (DTVAL*)AllocateValue(xp->g, TYPE_DATE, 19);
// Get date in the format produced by MySQL fields
......@@ -1420,13 +1423,14 @@ int ha_connect::ScanRecord(PGLOBAL g, uchar *buf)
case MYSQL_TYPE_TIME:
fmt= "hh:mm:ss";
break;
case MYSQL_TYPE_YEAR:
fmt= "YYYY";
break;
default:
fmt= "YYYY-MM-DD hh:mm:ss";
} // endswitch type
((DTVAL*)sdvalin)->SetFormat(g, fmt, strlen(fmt));
} // endif sdvalin
fp->val_str(&attribute);
sdvalin->SetValue_psz(attribute.c_ptr_safe());
value->SetValue_pval(sdvalin);
......@@ -3867,7 +3871,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
#endif // WIN32
port= atoi(GetListOption(g, "port", topt->oplist, "0"));
mxr= atoi(GetListOption(g,"maxerr", topt->oplist, "0"));
#if defined(PROMPT_OK)
cop= atoi(GetListOption(g, "checkdsn", topt->oplist, "0"));
#endif // PROMPT_OK
} else {
host= "localhost";
user= "root";
......@@ -3925,14 +3931,16 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
case TAB_ODBC:
dsn= create_info->connect_string.str;
if (fnc & (FNC_DSN | FNC_DRIVER))
if (fnc & (FNC_DSN | FNC_DRIVER)) {
ok= true;
else if (!stricmp(thd->main_security_ctx.host, "localhost")
#if defined(PROMPT_OK)
} else if (!stricmp(thd->main_security_ctx.host, "localhost")
&& cop == 1) {
if ((dsn = ODBCCheckConnection(g, dsn, cop)) != NULL) {
thd->make_lex_string(&create_info->connect_string, dsn, strlen(dsn));
ok= true;
} // endif dsn
#endif // PROMPT_OK
} else if (!dsn)
sprintf(g->Message, "Missing %s connection string", topt->type);
......@@ -4224,7 +4232,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
rc= add_fields(g, thd, &alter_info, cnm, typ, len, dec,
tm, rem, 0, true);
#else // !NEW_WAY
if (add_field(&sql, cnm, typ, len, dec, tm, rem, 0, true, v))
if (add_field(&sql, cnm, typ, len, dec, tm, rem, 0, dbf, v))
rc= HA_ERR_OUT_OF_MEM;
#endif // !NEW_WAY
} // endfor i
......
......@@ -182,7 +182,7 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
myc.Close();
return NULL;
} else if (type == TYPE_STRING)
len = min(len, 255);
len = min(len, 4096);
crp = crp->Next; // Data_Type
crp->Kdata->SetValue(type, i);
......
# Use default setting for mysqld processes
!include include/default_mysqld.cnf
!include include/default_client.cnf
[mysqld.1]
#log-bin= master-bin
[mysqld.2]
[ENV]
MASTER_MYPORT= @mysqld.1.port
MASTER_MYSOCK= @mysqld.1.socket
SLAVE_MYPORT= @mysqld.2.port
SLAVE_MYSOCK= @mysqld.2.socket
CREATE DATABASE connect;
CREATE DATABASE connect;
CREATE TABLE t1 (
`id` int(20) primary key,
`group` int NOT NULL default 1,
`a\\b` int NOT NULL default 2,
`a\\` int unsigned,
`name` varchar(32) default 'name')
DEFAULT CHARSET=latin1;
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(20) NOT NULL,
`group` int(11) NOT NULL,
`a\\b` int(11) NOT NULL,
`a\\` int(10) DEFAULT NULL,
`name` varchar(32) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1' `TABLE_TYPE`='MYSQL'
INSERT INTO t1 (id, name) VALUES (1, 'foo');
Warnings:
Warning 1364 Field 'group' doesn't have a default value
Warning 1364 Field 'a\\b' doesn't have a default value
INSERT INTO t1 (id, name) VALUES (2, 'fee');
Warnings:
Warning 1364 Field 'group' doesn't have a default value
Warning 1364 Field 'a\\b' doesn't have a default value
SELECT * FROM t1;
id group a\\b a\\ name
1 1 2 NULL foo
2 1 2 NULL fee
DROP TABLE t1;
SELECT * FROM t1;
id group a\\b a\\ name
1 1 2 NULL foo
2 1 2 NULL fee
DROP TABLE t1;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
CREATE DATABASE connect;
CREATE DATABASE connect;
#
# Checking Sending Commands
#
CREATE TABLE t1 (
command VARCHAR(128) NOT NULL,
warnings INT(4) NOT NULL FLAG=3,
number INT(5) NOT NULL FLAG=1,
message VARCHAR(255) FLAG=2)
ENGINE=CONNECT TABLE_TYPE=MYSQL CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test' OPTION_LIST='Execsrc=1,maxerr=2';
SELECT * FROM t1 WHERE command IN ('Warning','Note',
'drop table if exists t1',
'create table t1 (id int key auto_increment, msg varchar(32) not null)',
"insert into t1(msg) values('One'),(NULL),('Three')",
"insert into t1 values(2,'Deux') on duplicate key update msg = 'Two'",
"insert into t1(message) values('Four'),('Five'),('Six')",
'insert into t1(id) values(NULL)',
"update t1 set msg = 'Four' where id = 4",
'select * from t1');
command warnings number message
drop table if exists t1 1 0 Affected rows
Note 0 1051 Unknown table 'test.t1'
create table t1 (id int key auto_increment, msg varchar(32) not null) 0 0 Affected rows
insert into t1(msg) values('One'),(NULL),('Three') 1 3 Affected rows
Warning 0 1048 Column 'msg' cannot be null
insert into t1 values(2,'Deux') on duplicate key update msg = 'Two' 0 2 Affected rows
insert into t1(message) values('Four'),('Five'),('Six') 0 1054 Remote: Unknown column 'message' in 'field list'
insert into t1(id) values(NULL) 1 1 Affected rows
Warning 0 1364 Field 'msg' doesn't have a default value
update t1 set msg = 'Four' where id = 4 0 1 Affected rows
select * from t1 0 2 Result set columns
#
# Checking Using Procedure
#
DROP PROCEDURE IF EXISTS p1;
Warnings:
Note 1305 PROCEDURE test.p1 does not exist
CREATE PROCEDURE p1(cmd varchar(512))
READS SQL DATA
SELECT * FROM t1 WHERE command IN ('Warning','Note',cmd);
CALL p1('insert into t1(id) values(NULL)');
command warnings number message
insert into t1(id) values(NULL) 1 1 Affected rows
Warning 0 1364 Field 'msg' doesn't have a default value
CALL p1('update t1 set msg = "Five" where id = 5');
command warnings number message
update t1 set msg = "Five" where id = 5 0 1 Affected rows
DROP PROCEDURE p1;
DROP TABLE t1;
SELECT * FROM t1;
id msg
1 One
2 Two
3 Three
4 Four
5 Five
DROP TABLE t1;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
CREATE DATABASE connect;
CREATE DATABASE connect;
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;
a b
NULL NULL
0 test00
1 test01
2 test02
3 test03
#
# Testing errors
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://unknown@127.0.0.1:SLAVE_PORT/test/t1';
ERROR HY000: (1045) Access denied for user 'unknown'@'localhost' (using password: NO)
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/unknown/t1';
ERROR HY000: (1049) Unknown database 'unknown'
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
OPTION_LIST='host=127.0.0.1,user=root,port=SLAVE_PORT' DBNAME='unknown' TABNAME='t1';
ERROR HY000: (1049) Unknown database 'unknown'
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/unknown';
ERROR HY000: (1146) Table 'test.unknown' doesn't exist [SHOW FULL COLUMNS FROM unknown FROM test]
SHOW CREATE TABLE t1;
ERROR 42S02: Table 'test.t1' doesn't exist
CREATE TABLE t1 (x int, y char(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`x` int(11) DEFAULT NULL,
`y` char(10) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1' `TABLE_TYPE`=MYSQL
SELECT * FROM t1;
ERROR HY000: Got error 174 '(1054) Unknown column 'x' in 'field list' [SELECT `x`, `y` FROM `t1`]' from CONNECT
DROP TABLE t1;
CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1';
ALTER TABLE t1 RENAME t1backup;
SELECT * FROM t1;
ERROR HY000: Got error 174 '(1146) Table 'test.t1' doesn't exist [SELECT `a`, `b` FROM `t1`]' from CONNECT
ALTER TABLE t1backup RENAME t1;
DROP TABLE t1;
#
# Testing SELECT, etc.
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(10) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1' `TABLE_TYPE`='MYSQL'
SELECT * FROM t1;
a b
NULL NULL
0 test00
1 test01
2 test02
3 test03
DROP TABLE t1;
CREATE TABLE t1 (a int, b char(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL TABNAME='t1'
OPTION_LIST='host=127.0.0.1,user=root,port=SLAVE_PORT';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(10) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=MYSQL `TABNAME`='t1' `OPTION_LIST`='host=127.0.0.1,user=root,port=SLAVE_PORT'
SELECT * FROM t1;
a b
NULL NULL
0 test00
1 test01
2 test02
3 test03
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL, b CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=MYSQL
OPTION_LIST='host=127.0.0.1,user=root,port=SLAVE_PORT';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` char(10) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=MYSQL `OPTION_LIST`='host=127.0.0.1,user=root,port=SLAVE_PORT'
SELECT * FROM t1;
a b
0
0 test00
1 test01
2 test02
3 test03
DROP TABLE t1;
CREATE TABLE t1 (a char(10), b int) ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/test/t1' `TABLE_TYPE`=MYSQL
SELECT * FROM t1;
a b
NULL NULL
0 0
1 0
2 0
3 0
DROP TABLE t1;
DROP TABLE t1;
#
# Testing numeric data types
#
CREATE TABLE t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float, g double, h decimal(20,5));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` tinyint(4) DEFAULT NULL,
`b` smallint(6) DEFAULT NULL,
`c` mediumint(9) DEFAULT NULL,
`d` int(11) DEFAULT NULL,
`e` bigint(20) DEFAULT NULL,
`f` float DEFAULT NULL,
`g` double DEFAULT NULL,
`h` decimal(20,5) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES(100,3333,41235,1234567890,235000000000,3.14159265,3.14159265,3141.59265);
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
OPTION_LIST='host=127.0.0.1,user=root,port=SLAVE_PORT';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` tinyint(4) DEFAULT NULL,
`b` smallint(6) DEFAULT NULL,
`c` int(9) DEFAULT NULL,
`d` int(11) DEFAULT NULL,
`e` bigint(20) DEFAULT NULL,
`f` double DEFAULT NULL,
`g` double DEFAULT NULL,
`h` double(20,5) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MYSQL' `OPTION_LIST`='host=127.0.0.1,user=root,port=SLAVE_PORT'
SELECT * FROM t1;
a b c d e f g h
100 3333 41235 1234567890 235000000000 3.14159 3.14159265 3141.59265
DROP TABLE t1;
DROP TABLE t1;
#
# Testing character data types
#
CREATE TABLE t1 (a char(12), b varchar(12));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(12) DEFAULT NULL,
`b` varchar(12) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES('Welcome','Hello, World');
SELECT * FROM t1;
a b
Welcome Hello, World
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(12) DEFAULT NULL,
`b` varchar(12) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT' `TABLE_TYPE`='MYSQL'
SELECT * FROM t1;
a b
Welcome Hello, World
DROP TABLE t1;
DROP TABLE t1;
#
# Testing temporal data types
#
CREATE TABLE t1 (a date, b datetime, c time, d timestamp, e year);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` datetime DEFAULT NULL,
`c` time DEFAULT NULL,
`d` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`e` year(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 VALUES('2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23','2003-05-27 10:45:23');
Warnings:
Note 1265 Data truncated for column 'a' at row 1
Note 1265 Data truncated for column 'c' at row 1
Warning 1265 Data truncated for column 'e' at row 1
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 2003
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` date DEFAULT NULL,
`b` datetime DEFAULT NULL,
`c` time DEFAULT NULL,
`d` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`e` year(4) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT' `TABLE_TYPE`='MYSQL'
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 2003
DROP TABLE t1;
DROP TABLE t1;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
--source include/not_embedded.inc
let $PORT= `select @@port`;
--disable_query_log
--replace_result $PORT PORT
--error 0,ER_UNKNOWN_ERROR
eval CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/tx1';
if (!`SELECT count(*) FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1'
AND ENGINE='CONNECT'
AND CREATE_OPTIONS LIKE '%`table_type`=MySQL%'`)
{
Skip Need MySQL support;
}
DROP TABLE t1;
--enable_query_log
connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,);
connection master;
CREATE DATABASE connect;
connection slave;
CREATE DATABASE connect;
connection master;
--disable_warnings
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
connection slave;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
--enable_warnings
-- source myconn.inc
connection slave;
CREATE TABLE t1 (
`id` int(20) primary key,
`group` int NOT NULL default 1,
`a\\b` int NOT NULL default 2,
`a\\` int unsigned,
`name` varchar(32) default 'name')
DEFAULT CHARSET=latin1;
connection master;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test/t1';
--replace_result $SLAVE_MYPORT SLAVE_PORT
SHOW CREATE TABLE t1;
INSERT INTO t1 (id, name) VALUES (1, 'foo');
INSERT INTO t1 (id, name) VALUES (2, 'fee');
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
connection slave;
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
-- source myconn_cleanup.inc
-- source myconn.inc
--echo #
--echo # Checking Sending Commands
--echo #
connection master;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t1 (
command VARCHAR(128) NOT NULL,
warnings INT(4) NOT NULL FLAG=3,
number INT(5) NOT NULL FLAG=1,
message VARCHAR(255) FLAG=2)
ENGINE=CONNECT TABLE_TYPE=MYSQL CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/test' OPTION_LIST='Execsrc=1,maxerr=2';
SELECT * FROM t1 WHERE command IN ('Warning','Note',
'drop table if exists t1',
'create table t1 (id int key auto_increment, msg varchar(32) not null)',
"insert into t1(msg) values('One'),(NULL),('Three')",
"insert into t1 values(2,'Deux') on duplicate key update msg = 'Two'",
"insert into t1(message) values('Four'),('Five'),('Six')",
'insert into t1(id) values(NULL)',
"update t1 set msg = 'Four' where id = 4",
'select * from t1');
--echo #
--echo # Checking Using Procedure
--echo #
DROP PROCEDURE IF EXISTS p1;
CREATE PROCEDURE p1(cmd varchar(512))
READS SQL DATA
SELECT * FROM t1 WHERE command IN ('Warning','Note',cmd);
CALL p1('insert into t1(id) values(NULL)');
CALL p1('update t1 set msg = "Five" where id = 5');
DROP PROCEDURE p1;
DROP TABLE t1;
connection slave;
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
-- source myconn_cleanup.inc
This diff is collapsed.
......@@ -56,10 +56,28 @@ int MYSQLtoPLG(char *typname, char *var)
else
type = TYPE_ERROR;
if (var) {
// This is to make the difference between CHAR and VARCHAR
if (var && type == TYPE_STRING && stricmp(typname, "char"))
if (type == TYPE_STRING && stricmp(typname, "char"))
*var = 'V';
// This is to make the difference between temporal values
if (type == TYPE_DATE) {
if (!stricmp(typname, "date"))
*var = 'D';
else if (!stricmp(typname, "datetime"))
*var = 'A';
else if (!stricmp(typname, "timestamp"))
*var = 'S';
else if (!stricmp(typname, "time"))
*var = 'T';
else if (!stricmp(typname, "year"))
*var = 'Y';
} // endif type
} // endif var
return type;
} // end of MYSQLtoPLG
......@@ -102,14 +120,18 @@ enum enum_field_types PLGtoMYSQL(int type, bool dbf)
/************************************************************************/
/* Convert from PlugDB type to MySQL type name */
/************************************************************************/
const char *PLGtoMYSQLtype(int type, bool dbf, char var)
const char *PLGtoMYSQLtype(int type, bool dbf, char v)
{
switch (type) {
case TYPE_INT: return "INT";
case TYPE_SHORT: return "SMALLINT";
case TYPE_FLOAT: return "DOUBLE";
case TYPE_DATE: return dbf ? "DATE" : "DATETIME";
case TYPE_STRING: return var ? "VARCHAR" : "CHAR";
case TYPE_DATE: return dbf ? "DATE" :
(v == 'S') ? "TIMESTAMP" :
(v == 'D') ? "DATE" :
(v == 'T') ? "TIME" :
(v == 'Y') ? "YEAR" : "DATETIME";
case TYPE_STRING: return v ? "VARCHAR" : "CHAR";
case TYPE_BIGINT: return "BIGINT";
case TYPE_TINY: return "TINYINT";
default: return "CHAR(0)";
......
/***********************************************************************/
/* ODBC catalog function prototypes. */
/***********************************************************************/
#if defined(PROMPT_OK)
char *ODBCCheckConnection(PGLOBAL g, char *dsn, int cop);
#endif // PROMPT_OK
PQRYRES ODBCDataSources(PGLOBAL g, bool info);
PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table,
char *colpat, bool info);
......
......@@ -174,6 +174,7 @@ int TranslateSQLType(int stp, int prec, int& len, char& v)
return type;
} // end of TranslateSQLType
#if defined(PROMPT_OK)
/***********************************************************************/
/* ODBCCheckConnection: Check completeness of connection string. */
/***********************************************************************/
......@@ -205,6 +206,7 @@ char *ODBCCheckConnection(PGLOBAL g, char *dsn, int cop)
ocp->Close();
return newdsn; // Return complete connection string
} // end of ODBCCheckConnection
#endif // PROMPT_OK
/***********************************************************************/
/* Allocate the structure used to refer to the result set. */
......
......@@ -1263,7 +1263,7 @@ void MYSQLCOL::InitBind(PGLOBAL g)
/***********************************************************************/
void MYSQLCOL::ReadColumn(PGLOBAL g)
{
char *buf;
char *p, *buf, tim[20];
int rc;
PTDBMY tdbp = (PTDBMY)To_Tdb;
......@@ -1283,7 +1283,14 @@ void MYSQLCOL::ReadColumn(PGLOBAL g)
if (trace)
htrc("MySQL ReadColumn: name=%s buf=%s\n", Name, buf);
Value->SetValue_char(buf, min((unsigned)Long, strlen(buf)));
// TODO: have a true way to differenciate temporal values
if (strlen(buf) == 8)
// This is a TIME value
p = strcat(strcpy(tim, "1970-01-01 "), buf);
else
p = buf;
Value->SetValue_char(p, strlen(p));
} else {
if (Nullable)
Value->SetNull(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment