Commit 40b653e0 authored by unknown's avatar unknown

Merge paul@bk-internal.mysql.com:/home/bk/mysql-4.1

into ice.snake.net:/Users/paul/mysql-4.1
parents f21b944d 6ec78002
...@@ -566,6 +566,7 @@ unsigned long STDCALL mysql_param_count(MYSQL_STMT * stmt); ...@@ -566,6 +566,7 @@ unsigned long STDCALL mysql_param_count(MYSQL_STMT * stmt);
my_bool STDCALL mysql_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
my_bool STDCALL mysql_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd);
my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt);
my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt);
my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt);
unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt);
const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt); const char *STDCALL mysql_stmt_error(MYSQL_STMT * stmt);
......
...@@ -44,6 +44,7 @@ enum enum_server_command ...@@ -44,6 +44,7 @@ enum enum_server_command
COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP, COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE, COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
COM_PREPARE, COM_EXECUTE, COM_LONG_DATA, COM_CLOSE_STMT, COM_PREPARE, COM_EXECUTE, COM_LONG_DATA, COM_CLOSE_STMT,
COM_RESET_STMT,
COM_END /* Must be last */ COM_END /* Must be last */
}; };
......
...@@ -3316,6 +3316,7 @@ mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong row) ...@@ -3316,6 +3316,7 @@ mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong row)
} }
else else
DBUG_PRINT("exit", ("stmt doesn't contain any resultset")); DBUG_PRINT("exit", ("stmt doesn't contain any resultset"));
DBUG_VOID_RETURN;
} }
...@@ -3421,6 +3422,28 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) ...@@ -3421,6 +3422,28 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
return stmt_close(stmt, 0); return stmt_close(stmt, 0);
} }
/*
Reset the statement buffers in server
*/
my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt)
{
char buff[MYSQL_STMT_HEADER];
MYSQL *mysql;
DBUG_ENTER("mysql_stmt_reset");
DBUG_ASSERT(stmt != 0);
mysql= stmt->mysql->last_used_con;
int4store(buff, stmt->stmt_id); /* Send stmt id to server */
if (advanced_command(mysql, COM_RESET_STMT,buff,MYSQL_STMT_HEADER,0,0,1))
{
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
mysql->net.sqlstate);
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
/* /*
Return statement error code Return statement error code
*/ */
......
...@@ -98,6 +98,7 @@ EXPORTS ...@@ -98,6 +98,7 @@ EXPORTS
mysql_stat mysql_stat
mysql_stmt_affected_rows mysql_stmt_affected_rows
mysql_stmt_close mysql_stmt_close
mysql_stmt_reset
mysql_stmt_data_seek mysql_stmt_data_seek
mysql_stmt_errno mysql_stmt_errno
mysql_stmt_error mysql_stmt_error
......
...@@ -44,10 +44,10 @@ t1 CREATE TABLE `t1` ( ...@@ -44,10 +44,10 @@ t1 CREATE TABLE `t1` (
drop table t1; drop table t1;
select cast("2001-1-1" as date) = "2001-01-01"; select cast("2001-1-1" as date) = "2001-01-01";
cast("2001-1-1" as date) = "2001-01-01" cast("2001-1-1" as date) = "2001-01-01"
0 1
select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"; select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00";
cast("2001-1-1" as datetime) = "2001-01-01 00:00:00" cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"
0 1
select cast("1:2:3" as TIME) = "1:02:03"; select cast("1:2:3" as TIME) = "1:02:03";
cast("1:2:3" as TIME) = "1:02:03" cast("1:2:3" as TIME) = "1:02:03"
0 0
......
drop table if exists t1, test;
select extract(DAY_MICROSECOND FROM "1999-01-02 10:11:12.000123");
extract(DAY_MICROSECOND FROM "1999-01-02 10:11:12.000123")
2101112000123
select extract(HOUR_MICROSECOND FROM "1999-01-02 10:11:12.000123");
extract(HOUR_MICROSECOND FROM "1999-01-02 10:11:12.000123")
101112000123
select extract(MINUTE_MICROSECOND FROM "1999-01-02 10:11:12.000123");
extract(MINUTE_MICROSECOND FROM "1999-01-02 10:11:12.000123")
1112000123
select extract(SECOND_MICROSECOND FROM "1999-01-02 10:11:12.000123");
extract(SECOND_MICROSECOND FROM "1999-01-02 10:11:12.000123")
12000123
select extract(MICROSECOND FROM "1999-01-02 10:11:12.000123");
extract(MICROSECOND FROM "1999-01-02 10:11:12.000123")
123
select date_format("1997-12-31 23:59:59.000002", "%f");
date_format("1997-12-31 23:59:59.000002", "%f")
000002
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000 99:99:99.999999" DAY_MICROSECOND);
date_add("1997-12-31 23:59:59.000002",INTERVAL "10000 99:99:99.999999" DAY_MICROSECOND)
2025-05-23 04:40:39.000001
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99:99.999999" HOUR_MICROSECOND);
date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99:99.999999" HOUR_MICROSECOND)
1999-02-21 17:40:39.000001
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99.999999" MINUTE_MICROSECOND);
date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99.999999" MINUTE_MICROSECOND)
1998-01-07 22:41:39.000001
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000.999999" SECOND_MICROSECOND);
date_add("1997-12-31 23:59:59.000002",INTERVAL "10000.999999" SECOND_MICROSECOND)
1998-01-01 02:46:40.000001
select date_add("1997-12-31 23:59:59.000002",INTERVAL "999999" MICROSECOND);
date_add("1997-12-31 23:59:59.000002",INTERVAL "999999" MICROSECOND)
1998-01-01 00:00:00.000001
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1 1:1:1.000002" DAY_MICROSECOND);
date_sub("1998-01-01 00:00:00.000001",INTERVAL "1 1:1:1.000002" DAY_MICROSECOND)
1997-12-30 22:58:58.999999
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1:1.000002" HOUR_MICROSECOND);
date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1:1.000002" HOUR_MICROSECOND)
1997-12-31 22:58:58.999999
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1.000002" MINUTE_MICROSECOND);
date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1.000002" MINUTE_MICROSECOND)
1997-12-31 23:58:58.999999
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1.000002" SECOND_MICROSECOND);
date_sub("1998-01-01 00:00:00.000001",INTERVAL "1.000002" SECOND_MICROSECOND)
1997-12-31 23:59:58.999999
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "000002" MICROSECOND);
date_sub("1998-01-01 00:00:00.000001",INTERVAL "000002" MICROSECOND)
1997-12-31 23:59:59.999999
select adddate("1997-12-31 23:59:59.000001", 10);
adddate("1997-12-31 23:59:59.000001", 10)
1998-01-10 23:59:59.000001
select subdate("1997-12-31 23:59:59.000001", 10);
subdate("1997-12-31 23:59:59.000001", 10)
1997-12-21 23:59:59.000001
select datediff("1997-12-31 23:59:59.000001","1997-12-30");
datediff("1997-12-31 23:59:59.000001","1997-12-30")
1
select datediff("1997-11-31 23:59:59.000001","1997-12-31");
datediff("1997-11-31 23:59:59.000001","1997-12-31")
-30
select datediff("1997-11-31 23:59:59.000001",null);
datediff("1997-11-31 23:59:59.000001",null)
NULL
select weekofyear("1997-11-31 23:59:59.000001");
weekofyear("1997-11-31 23:59:59.000001")
49
select makedate(1997,1);
makedate(1997,1)
1997-01-01
select makedate(1997,0);
makedate(1997,0)
NULL
select addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002");
addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002")
1998-01-02 01:01:01.000001
select subtime("1997-12-31 23:59:59.000001", "1 1:1:1.000002");
subtime("1997-12-31 23:59:59.000001", "1 1:1:1.000002")
1997-12-30 22:58:57.999999
select addtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
addtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999")
NULL
select subtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
subtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999")
NULL
select subtime("01:00:00.999999", "02:00:00.999998");
subtime("01:00:00.999999", "02:00:00.999998")
-00:59:59.999999
select subtime("02:01:01.999999", "01:01:01.999999");
subtime("02:01:01.999999", "01:01:01.999999")
01:00:00.000000
select timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002");
timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002")
8807:59:59.999999
select timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002");
timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002")
46:58:57.999999
select timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002");
timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002")
-23:59:59.999999
select timediff("1997-12-31 23:59:59.000001","23:59:59.000001");
timediff("1997-12-31 23:59:59.000001","23:59:59.000001")
NULL
select timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.000001");
timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.000001")
-00:00:00.000001
select maketime(10,11,12);
maketime(10,11,12)
10:11:12
select maketime(25,11,12);
maketime(25,11,12)
25:11:12
select maketime(-25,11,12);
maketime(-25,11,12)
-25:11:12
select timestamp("2001-12-01", "01:01:01.999999");
timestamp("2001-12-01", "01:01:01.999999")
2001-12-01 01:01:01.999999
select timestamp("2001-13-01", "01:01:01.000001");
timestamp("2001-13-01", "01:01:01.000001")
NULL
select timestamp("2001-12-01", "25:01:01");
timestamp("2001-12-01", "25:01:01")
2001-12-02 01:01:01
select timestamp("2001-12-01 01:01:01.000100");
timestamp("2001-12-01 01:01:01.000100")
2001-12-01 01:01:01.000100
select timestamp("2001-12-01");
timestamp("2001-12-01")
2001-12-01 00:00:00
select day("1997-12-31 23:59:59.000001");
day("1997-12-31 23:59:59.000001")
31
select date("1997-12-31 23:59:59.000001");
date("1997-12-31 23:59:59.000001")
1997-12-31
select date("1997-13-31 23:59:59.000001");
date("1997-13-31 23:59:59.000001")
NULL
select time("1997-12-31 23:59:59.000001");
time("1997-12-31 23:59:59.000001")
23:59:59.000001
select time("1997-12-31 25:59:59.000001");
time("1997-12-31 25:59:59.000001")
NULL
select microsecond("1997-12-31 23:59:59.000001");
microsecond("1997-12-31 23:59:59.000001")
1
create table t1
select makedate(1997,1) as f1,
addtime(cast("1997-12-31 23:59:59.000001" as datetime), "1 1:1:1.000002") as f2,
addtime(cast("23:59:59.999999" as time) , "1 1:1:1.000002") as f3,
timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002") as f4,
timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002") as f5,
maketime(10,11,12) as f6,
timestamp(cast("2001-12-01" as date), "01:01:01") as f7,
date("1997-12-31 23:59:59.000001") as f8,
time("1997-12-31 23:59:59.000001") as f9;
describe t1;
Field Type Null Key Default Extra
f1 date 0000-00-00
f2 datetime 0000-00-00 00:00:00
f3 time 00:00:00
f4 time 00:00:00
f5 time 00:00:00
f6 time 00:00:00
f7 datetime 0000-00-00 00:00:00
f8 date 0000-00-00
f9 time 00:00:00
select * from t1;
f1 f2 f3 f4 f5 f6 f7 f8 f9
1997-01-01 1998-01-02 01:01:00 49:01:01 46:58:57 -23:59:59 10:11:12 2001-12-01 01:01:01 1997-12-31 23:59:59
create table test(t1 datetime, t2 time, t3 time, t4 datetime);
insert into test values
('2001-01-01 01:01:01', '01:01:01', null, '2001-02-01 01:01:01'),
('2001-01-01 01:01:01', '-01:01:01', '-23:59:59', "1997-12-31 23:59:59.000001"),
('1997-12-31 23:59:59.000001', '-23:59:59', '-01:01:01', '2001-01-01 01:01:01'),
('2001-01-01 01:01:01', '01:01:01', '-1 01:01:01', null),
('2001-01-01 01:01:01', null, '-1 01:01:01', null),
(null, null, null, null),
('2001-01-01 01:01:01', '01:01:01', '1 01:01:01', '2001-01-01 01:01:01');
SELECT ADDTIME(t1,t2) As ttt, ADDTIME(t2, t3) As qqq from test;
ttt qqq
2001-01-01 02:02:02 NULL
2001-01-01 00:00:00 -25:01:00
1997-12-31 00:00:00 -25:01:00
2001-01-01 02:02:02 -24:00:00
NULL NULL
NULL NULL
2001-01-01 02:02:02 26:02:02
SELECT TIMEDIFF(t1,t4) As ttt, TIMEDIFF(t2, t3) As qqq from test;
ttt qqq
-744:00:00 NULL
26305:01:02 22:58:58
-26305:01:02 -22:58:58
NULL 26:02:02
NULL NULL
NULL NULL
00:00:00 -24:00:00
drop table t1, test;
--disable_warnings
drop table if exists t1, test;
--enable_warnings
#
# time functions
#
select extract(DAY_MICROSECOND FROM "1999-01-02 10:11:12.000123");
select extract(HOUR_MICROSECOND FROM "1999-01-02 10:11:12.000123");
select extract(MINUTE_MICROSECOND FROM "1999-01-02 10:11:12.000123");
select extract(SECOND_MICROSECOND FROM "1999-01-02 10:11:12.000123");
select extract(MICROSECOND FROM "1999-01-02 10:11:12.000123");
select date_format("1997-12-31 23:59:59.000002", "%f");
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000 99:99:99.999999" DAY_MICROSECOND);
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99:99.999999" HOUR_MICROSECOND);
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000:99.999999" MINUTE_MICROSECOND);
select date_add("1997-12-31 23:59:59.000002",INTERVAL "10000.999999" SECOND_MICROSECOND);
select date_add("1997-12-31 23:59:59.000002",INTERVAL "999999" MICROSECOND);
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1 1:1:1.000002" DAY_MICROSECOND);
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1:1.000002" HOUR_MICROSECOND);
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1:1.000002" MINUTE_MICROSECOND);
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "1.000002" SECOND_MICROSECOND);
select date_sub("1998-01-01 00:00:00.000001",INTERVAL "000002" MICROSECOND);
#Date functions
select adddate("1997-12-31 23:59:59.000001", 10);
select subdate("1997-12-31 23:59:59.000001", 10);
select datediff("1997-12-31 23:59:59.000001","1997-12-30");
select datediff("1997-11-31 23:59:59.000001","1997-12-31");
select datediff("1997-11-31 23:59:59.000001",null);
select weekofyear("1997-11-31 23:59:59.000001");
select makedate(1997,1);
select makedate(1997,0);
#Time functions
select addtime("1997-12-31 23:59:59.999999", "1 1:1:1.000002");
select subtime("1997-12-31 23:59:59.000001", "1 1:1:1.000002");
select addtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
select subtime("1997-12-31 23:59:59.999999", "1998-01-01 01:01:01.999999");
select subtime("01:00:00.999999", "02:00:00.999998");
select subtime("02:01:01.999999", "01:01:01.999999");
select timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002");
select timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002");
select timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002");
select timediff("1997-12-31 23:59:59.000001","23:59:59.000001");
select timediff("2000:01:01 00:00:00", "2000:01:01 00:00:00.000001");
select maketime(10,11,12);
select maketime(25,11,12);
select maketime(-25,11,12);
#Extraction functions
select timestamp("2001-12-01", "01:01:01.999999");
select timestamp("2001-13-01", "01:01:01.000001");
select timestamp("2001-12-01", "25:01:01");
select timestamp("2001-12-01 01:01:01.000100");
select timestamp("2001-12-01");
select day("1997-12-31 23:59:59.000001");
select date("1997-12-31 23:59:59.000001");
select date("1997-13-31 23:59:59.000001");
select time("1997-12-31 23:59:59.000001");
select time("1997-12-31 25:59:59.000001");
select microsecond("1997-12-31 23:59:59.000001");
create table t1
select makedate(1997,1) as f1,
addtime(cast("1997-12-31 23:59:59.000001" as datetime), "1 1:1:1.000002") as f2,
addtime(cast("23:59:59.999999" as time) , "1 1:1:1.000002") as f3,
timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002") as f4,
timediff("1997-12-30 23:59:59.000001","1997-12-31 23:59:59.000002") as f5,
maketime(10,11,12) as f6,
timestamp(cast("2001-12-01" as date), "01:01:01") as f7,
date("1997-12-31 23:59:59.000001") as f8,
time("1997-12-31 23:59:59.000001") as f9;
describe t1;
select * from t1;
create table test(t1 datetime, t2 time, t3 time, t4 datetime);
insert into test values
('2001-01-01 01:01:01', '01:01:01', null, '2001-02-01 01:01:01'),
('2001-01-01 01:01:01', '-01:01:01', '-23:59:59', "1997-12-31 23:59:59.000001"),
('1997-12-31 23:59:59.000001', '-23:59:59', '-01:01:01', '2001-01-01 01:01:01'),
('2001-01-01 01:01:01', '01:01:01', '-1 01:01:01', null),
('2001-01-01 01:01:01', null, '-1 01:01:01', null),
(null, null, null, null),
('2001-01-01 01:01:01', '01:01:01', '1 01:01:01', '2001-01-01 01:01:01');
SELECT ADDTIME(t1,t2) As ttt, ADDTIME(t2, t3) As qqq from test;
SELECT TIMEDIFF(t1,t4) As ttt, TIMEDIFF(t2, t3) As qqq from test;
drop table t1, test;
...@@ -3152,11 +3152,13 @@ bool Field_time::get_time(TIME *ltime) ...@@ -3152,11 +3152,13 @@ bool Field_time::get_time(TIME *ltime)
ltime->neg= 1; ltime->neg= 1;
tmp=-tmp; tmp=-tmp;
} }
ltime->day= 0;
ltime->hour= (int) (tmp/10000); ltime->hour= (int) (tmp/10000);
tmp-=ltime->hour*10000; tmp-=ltime->hour*10000;
ltime->minute= (int) tmp/100; ltime->minute= (int) tmp/100;
ltime->second= (int) tmp % 100; ltime->second= (int) tmp % 100;
ltime->second_part=0; ltime->second_part=0;
ltime->time_type= TIMESTAMP_TIME;
return 0; return 0;
} }
......
...@@ -691,3 +691,38 @@ Item *create_func_uncompressed_length(Item* a) ...@@ -691,3 +691,38 @@ Item *create_func_uncompressed_length(Item* a)
#endif #endif
Item *create_func_datediff(Item *a, Item *b)
{
return new Item_func_minus(new Item_func_to_days(a),
new Item_func_to_days(b));
}
Item *create_func_weekofyear(Item *a)
{
return new Item_func_week(a, new Item_int((char*) "0", 3, 1));
}
Item *create_func_makedate(Item* a,Item* b)
{
return new Item_func_makedate(a, b);
}
Item *create_func_addtime(Item* a,Item* b)
{
return new Item_func_add_time(a, b, 0, 0);
}
Item *create_func_subtime(Item* a,Item* b)
{
return new Item_func_add_time(a, b, 0, 1);
}
Item *create_func_timediff(Item* a,Item* b)
{
return new Item_func_timediff(a, b);
}
Item *create_func_maketime(Item* a,Item* b,Item* c)
{
return new Item_func_maketime(a, b, c);
}
...@@ -146,3 +146,10 @@ Item *create_func_compress(Item *a); ...@@ -146,3 +146,10 @@ Item *create_func_compress(Item *a);
Item *create_func_uncompress(Item *a); Item *create_func_uncompress(Item *a);
Item *create_func_uncompressed_length(Item *a); Item *create_func_uncompressed_length(Item *a);
Item *create_func_datediff(Item *a, Item *b);
Item *create_func_weekofyear(Item *a);
Item *create_func_makedate(Item* a,Item* b);
Item *create_func_addtime(Item* a,Item* b);
Item *create_func_subtime(Item* a,Item* b);
Item *create_func_timediff(Item* a,Item* b);
Item *create_func_maketime(Item* a,Item* b,Item* c);
This diff is collapsed.
...@@ -478,9 +478,10 @@ class Item_func_sec_to_time :public Item_str_func ...@@ -478,9 +478,10 @@ class Item_func_sec_to_time :public Item_str_func
enum interval_type enum interval_type
{ {
INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE,
INTERVAL_SECOND, INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND ,INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR,
INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE,
INTERVAL_MINUTE_SECOND INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND,
INTERVAL_HOUR_MICROSECOND, INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND
}; };
...@@ -556,6 +557,8 @@ class Item_date_typecast :public Item_typecast ...@@ -556,6 +557,8 @@ class Item_date_typecast :public Item_typecast
{ {
public: public:
Item_date_typecast(Item *a) :Item_typecast(a) {} Item_date_typecast(Item *a) :Item_typecast(a) {}
String *val_str(String *str);
bool get_date(TIME *ltime, bool fuzzy_date);
const char *func_name() const { return "date"; } const char *func_name() const { return "date"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; } enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
Field *tmp_table_field() { return result_field; } Field *tmp_table_field() { return result_field; }
...@@ -570,6 +573,8 @@ class Item_time_typecast :public Item_typecast ...@@ -570,6 +573,8 @@ class Item_time_typecast :public Item_typecast
{ {
public: public:
Item_time_typecast(Item *a) :Item_typecast(a) {} Item_time_typecast(Item *a) :Item_typecast(a) {}
String *val_str(String *str);
bool get_time(TIME *ltime);
const char *func_name() const { return "time"; } const char *func_name() const { return "time"; }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; } enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
Field *tmp_table_field() { return result_field; } Field *tmp_table_field() { return result_field; }
...@@ -584,6 +589,7 @@ class Item_datetime_typecast :public Item_typecast ...@@ -584,6 +589,7 @@ class Item_datetime_typecast :public Item_typecast
{ {
public: public:
Item_datetime_typecast(Item *a) :Item_typecast(a) {} Item_datetime_typecast(Item *a) :Item_typecast(a) {}
String *val_str(String *str);
const char *func_name() const { return "datetime"; } const char *func_name() const { return "datetime"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }
Field *tmp_table_field() { return result_field; } Field *tmp_table_field() { return result_field; }
...@@ -592,3 +598,106 @@ class Item_datetime_typecast :public Item_typecast ...@@ -592,3 +598,106 @@ class Item_datetime_typecast :public Item_typecast
return (new Field_datetime(maybe_null, name, t_arg, default_charset())); return (new Field_datetime(maybe_null, name, t_arg, default_charset()));
} }
}; };
class Item_func_makedate :public Item_str_func
{
public:
Item_func_makedate(Item *a,Item *b) :Item_str_func(a,b) {}
String *val_str(String *str);
const char *func_name() const { return "makedate"; }
enum_field_types field_type() const { return MYSQL_TYPE_DATE; }
void fix_length_and_dec()
{
decimals=0;
max_length=8*MY_CHARSET_BIN_MB_MAXLEN;
}
Field *tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg)
{
return (new Field_date(maybe_null, name, t_arg, &my_charset_bin));
}
};
class Item_func_add_time :public Item_str_func
{
const bool is_date;
int sign;
enum_field_types cached_field_type;
public:
Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg)
:Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; }
String *val_str(String *str);
const char *func_name() const { return "addtime"; }
enum_field_types field_type() const { return cached_field_type; }
void fix_length_and_dec();
/*
TODO:
Change this when we support
microseconds in TIME/DATETIME
*/
Field *tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg)
{
if (cached_field_type == MYSQL_TYPE_TIME)
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
else if (cached_field_type == MYSQL_TYPE_DATETIME)
return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin));
return (new Field_string(max_length, maybe_null, name, t_arg, &my_charset_bin));
}
};
class Item_func_timediff :public Item_str_func
{
public:
Item_func_timediff(Item *a, Item *b)
:Item_str_func(a, b) {}
String *val_str(String *str);
const char *func_name() const { return "timediff"; }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
void fix_length_and_dec()
{
decimals=0;
max_length=17*MY_CHARSET_BIN_MB_MAXLEN;
}
Field *tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg)
{
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
}
};
class Item_func_maketime :public Item_str_func
{
public:
Item_func_maketime(Item *a, Item *b, Item *c)
:Item_str_func(a, b ,c) {}
String *val_str(String *str);
const char *func_name() const { return "maketime"; }
enum_field_types field_type() const { return MYSQL_TYPE_TIME; }
void fix_length_and_dec()
{
decimals=0;
max_length=8*MY_CHARSET_BIN_MB_MAXLEN;
}
Field *tmp_table_field() { return result_field; }
Field *tmp_table_field(TABLE *t_arg)
{
return (new Field_time(maybe_null, name, t_arg, &my_charset_bin));
}
};
class Item_func_microsecond :public Item_int_func
{
public:
Item_func_microsecond(Item *a) :Item_int_func(a) {}
longlong val_int();
const char *func_name() const { return "microsecond"; }
void fix_length_and_dec()
{
decimals=0;
maybe_null=1;
}
};
...@@ -116,6 +116,7 @@ static SYMBOL symbols[] = { ...@@ -116,6 +116,7 @@ static SYMBOL symbols[] = {
{ "DATETIME", SYM(DATETIME),0,0}, { "DATETIME", SYM(DATETIME),0,0},
{ "DAY", SYM(DAY_SYM),0,0}, { "DAY", SYM(DAY_SYM),0,0},
{ "DAY_HOUR", SYM(DAY_HOUR_SYM),0,0}, { "DAY_HOUR", SYM(DAY_HOUR_SYM),0,0},
{ "DAY_MICROSECOND", SYM(DAY_MICROSECOND_SYM),0,0},
{ "DAY_MINUTE", SYM(DAY_MINUTE_SYM),0,0}, { "DAY_MINUTE", SYM(DAY_MINUTE_SYM),0,0},
{ "DAY_SECOND", SYM(DAY_SECOND_SYM),0,0}, { "DAY_SECOND", SYM(DAY_SECOND_SYM),0,0},
{ "DEC", SYM(DECIMAL_SYM),0,0}, { "DEC", SYM(DECIMAL_SYM),0,0},
...@@ -186,6 +187,7 @@ static SYMBOL symbols[] = { ...@@ -186,6 +187,7 @@ static SYMBOL symbols[] = {
{ "HELP", SYM(HELP_SYM),0,0}, { "HELP", SYM(HELP_SYM),0,0},
{ "HIGH_PRIORITY", SYM(HIGH_PRIORITY),0,0}, { "HIGH_PRIORITY", SYM(HIGH_PRIORITY),0,0},
{ "HOUR", SYM(HOUR_SYM),0,0}, { "HOUR", SYM(HOUR_SYM),0,0},
{ "HOUR_MICROSECOND", SYM(HOUR_MICROSECOND_SYM),0,0},
{ "HOUR_MINUTE", SYM(HOUR_MINUTE_SYM),0,0}, { "HOUR_MINUTE", SYM(HOUR_MINUTE_SYM),0,0},
{ "HOUR_SECOND", SYM(HOUR_SECOND_SYM),0,0}, { "HOUR_SECOND", SYM(HOUR_SECOND_SYM),0,0},
{ "HOSTS", SYM(HOSTS_SYM),0,0}, { "HOSTS", SYM(HOSTS_SYM),0,0},
...@@ -259,9 +261,11 @@ static SYMBOL symbols[] = { ...@@ -259,9 +261,11 @@ static SYMBOL symbols[] = {
{ "MERGE", SYM(MERGE_SYM),0,0}, { "MERGE", SYM(MERGE_SYM),0,0},
{ "MEDIUM", SYM(MEDIUM_SYM),0,0}, { "MEDIUM", SYM(MEDIUM_SYM),0,0},
{ "MEMORY", SYM(MEMORY_SYM),0,0}, { "MEMORY", SYM(MEMORY_SYM),0,0},
{ "MICROSECOND", SYM(MICROSECOND_SYM),0,0},
{ "MIDDLEINT", SYM(MEDIUMINT),0,0}, /* For powerbuilder */ { "MIDDLEINT", SYM(MEDIUMINT),0,0}, /* For powerbuilder */
{ "MIN_ROWS", SYM(MIN_ROWS),0,0}, { "MIN_ROWS", SYM(MIN_ROWS),0,0},
{ "MINUTE", SYM(MINUTE_SYM),0,0}, { "MINUTE", SYM(MINUTE_SYM),0,0},
{ "MINUTE_MICROSECOND", SYM(MINUTE_MICROSECOND_SYM),0,0},
{ "MINUTE_SECOND", SYM(MINUTE_SECOND_SYM),0,0}, { "MINUTE_SECOND", SYM(MINUTE_SECOND_SYM),0,0},
{ "MOD", SYM(MOD_SYM),0,0}, { "MOD", SYM(MOD_SYM),0,0},
{ "MODE", SYM(MODE_SYM),0,0}, { "MODE", SYM(MODE_SYM),0,0},
...@@ -337,6 +341,7 @@ static SYMBOL symbols[] = { ...@@ -337,6 +341,7 @@ static SYMBOL symbols[] = {
{ "ROWS", SYM(ROWS_SYM),0,0}, { "ROWS", SYM(ROWS_SYM),0,0},
{ "RTREE", SYM(RTREE_SYM),0,0}, { "RTREE", SYM(RTREE_SYM),0,0},
{ "SECOND", SYM(SECOND_SYM),0,0}, { "SECOND", SYM(SECOND_SYM),0,0},
{ "SECOND_MICROSECOND", SYM(SECOND_MICROSECOND_SYM),0,0},
{ "SEPARATOR", SYM(SEPARATOR_SYM),0,0}, { "SEPARATOR", SYM(SEPARATOR_SYM),0,0},
{ "SELECT", SYM(SELECT_SYM),0,0}, { "SELECT", SYM(SELECT_SYM),0,0},
{ "SERIAL", SYM(SERIAL_SYM),0,0}, { "SERIAL", SYM(SERIAL_SYM),0,0},
...@@ -427,7 +432,8 @@ static SYMBOL symbols[] = { ...@@ -427,7 +432,8 @@ static SYMBOL symbols[] = {
static SYMBOL sql_functions[] = { static SYMBOL sql_functions[] = {
{ "ABS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_abs)}, { "ABS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_abs)},
{ "ACOS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_acos)}, { "ACOS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_acos)},
{ "ADDDATE", SYM(DATE_ADD_INTERVAL),0,0}, { "ADDDATE", SYM(ADDDATE_SYM),0,0},
{ "ADDTIME", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_addtime)},
{ "AES_ENCRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_encrypt)}, { "AES_ENCRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_encrypt)},
{ "AES_DECRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_decrypt)}, { "AES_DECRYPT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_aes_decrypt)},
{ "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)}, { "AREA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_area)},
...@@ -470,6 +476,7 @@ static SYMBOL sql_functions[] = { ...@@ -470,6 +476,7 @@ static SYMBOL sql_functions[] = {
{ "CURDATE", SYM(CURDATE),0,0}, { "CURDATE", SYM(CURDATE),0,0},
{ "CURTIME", SYM(CURTIME),0,0}, { "CURTIME", SYM(CURTIME),0,0},
{ "DATE_ADD", SYM(DATE_ADD_INTERVAL),0,0}, { "DATE_ADD", SYM(DATE_ADD_INTERVAL),0,0},
{ "DATEDIFF", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_datediff)},
{ "DATE_FORMAT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_date_format)}, { "DATE_FORMAT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_date_format)},
{ "DATE_SUB", SYM(DATE_SUB_INTERVAL),0,0}, { "DATE_SUB", SYM(DATE_SUB_INTERVAL),0,0},
{ "DAYNAME", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_dayname)}, { "DAYNAME", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_dayname)},
...@@ -545,6 +552,8 @@ static SYMBOL sql_functions[] = { ...@@ -545,6 +552,8 @@ static SYMBOL sql_functions[] = {
{ "LPAD", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_lpad)}, { "LPAD", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_lpad)},
{ "LTRIM", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ltrim)}, { "LTRIM", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_ltrim)},
{ "MAKE_SET", SYM(MAKE_SET_SYM),0,0}, { "MAKE_SET", SYM(MAKE_SET_SYM),0,0},
{ "MAKEDATE", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_makedate)},
{ "MAKETIME", SYM(FUNC_ARG3),0,CREATE_FUNC(create_func_maketime)},
{ "MASTER_POS_WAIT", SYM(MASTER_POS_WAIT),0,0}, { "MASTER_POS_WAIT", SYM(MASTER_POS_WAIT),0,0},
{ "MAX", SYM(MAX_SYM),0,0}, { "MAX", SYM(MAX_SYM),0,0},
{ "MBRCONTAINS", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_contains)}, { "MBRCONTAINS", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_contains)},
...@@ -605,7 +614,7 @@ static SYMBOL sql_functions[] = { ...@@ -605,7 +614,7 @@ static SYMBOL sql_functions[] = {
{ "RTRIM", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_rtrim)}, { "RTRIM", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_rtrim)},
{ "SEC_TO_TIME", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sec_to_time)}, { "SEC_TO_TIME", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sec_to_time)},
{ "SESSION_USER", SYM(USER),0,0}, { "SESSION_USER", SYM(USER),0,0},
{ "SUBDATE", SYM(DATE_SUB_INTERVAL),0,0}, { "SUBDATE", SYM(SUBDATE_SYM),0,0},
{ "SIGN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sign)}, { "SIGN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sign)},
{ "SIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sin)}, { "SIN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sin)},
{ "SHA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)}, { "SHA", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)},
...@@ -620,12 +629,14 @@ static SYMBOL sql_functions[] = { ...@@ -620,12 +629,14 @@ static SYMBOL sql_functions[] = {
{ "STRCMP", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_strcmp)}, { "STRCMP", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_strcmp)},
{ "SUBSTRING", SYM(SUBSTRING),0,0}, { "SUBSTRING", SYM(SUBSTRING),0,0},
{ "SUBSTRING_INDEX", SYM(SUBSTRING_INDEX),0,0}, { "SUBSTRING_INDEX", SYM(SUBSTRING_INDEX),0,0},
{ "SUBTIME", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_subtime)},
{ "SUM", SYM(SUM_SYM),0,0}, { "SUM", SYM(SUM_SYM),0,0},
{ "SYSDATE", SYM(NOW_SYM),0,0}, { "SYSDATE", SYM(NOW_SYM),0,0},
{ "SYSTEM_USER", SYM(USER),0,0}, { "SYSTEM_USER", SYM(USER),0,0},
{ "TAN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_tan)}, { "TAN", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_tan)},
{ "TIME_FORMAT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_time_format)}, { "TIME_FORMAT", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_time_format)},
{ "TIME_TO_SEC", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_time_to_sec)}, { "TIME_TO_SEC", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_time_to_sec)},
{ "TIMEDIFF", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_timediff)},
{ "TO_DAYS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_to_days)}, { "TO_DAYS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_to_days)},
{ "TOUCHES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_touches)}, { "TOUCHES", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_touches)},
{ "TRIM", SYM(TRIM),0,0}, { "TRIM", SYM(TRIM),0,0},
...@@ -639,6 +650,7 @@ static SYMBOL sql_functions[] = { ...@@ -639,6 +650,7 @@ static SYMBOL sql_functions[] = {
{ "VERSION", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_version)}, { "VERSION", SYM(FUNC_ARG0),0,CREATE_FUNC(create_func_version)},
{ "WEEK", SYM(WEEK_SYM),0,0}, { "WEEK", SYM(WEEK_SYM),0,0},
{ "WEEKDAY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_weekday)}, { "WEEKDAY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_weekday)},
{ "WEEKOFYEAR", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_weekofyear)},
{ "WITHIN", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_within)}, { "WITHIN", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_within)},
{ "X", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_x)}, { "X", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_x)},
{ "Y", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_y)}, { "Y", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_y)},
......
...@@ -224,6 +224,8 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset; ...@@ -224,6 +224,8 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
#define RAID_BLOCK_SIZE 1024 #define RAID_BLOCK_SIZE 1024
#define MY_CHARSET_BIN_MB_MAXLEN 1
#ifdef EXTRA_DEBUG #ifdef EXTRA_DEBUG
/* /*
Sync points allow us to force the server to reach a certain line of code Sync points allow us to force the server to reach a certain line of code
...@@ -557,6 +559,7 @@ void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used); ...@@ -557,6 +559,7 @@ void free_prep_stmt(PREP_STMT *stmt, TREE_FREE mode, void *not_used);
bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length); bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length);
void mysql_stmt_execute(THD *thd, char *packet); void mysql_stmt_execute(THD *thd, char *packet);
void mysql_stmt_free(THD *thd, char *packet); void mysql_stmt_free(THD *thd, char *packet);
void mysql_stmt_reset(THD *thd, char *packet);
void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length); void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
int check_insert_fields(THD *thd,TABLE *table,List<Item> &fields, int check_insert_fields(THD *thd,TABLE *table,List<Item> &fields,
List<Item> &values, ulong counter); List<Item> &values, ulong counter);
...@@ -851,6 +854,7 @@ longlong str_to_datetime(const char *str,uint length,bool fuzzy_date); ...@@ -851,6 +854,7 @@ longlong str_to_datetime(const char *str,uint length,bool fuzzy_date);
timestamp_type str_to_TIME(const char *str, uint length, TIME *l_time, timestamp_type str_to_TIME(const char *str, uint length, TIME *l_time,
bool fuzzy_date); bool fuzzy_date);
void localtime_to_TIME(TIME *to, struct tm *from); void localtime_to_TIME(TIME *to, struct tm *from);
void calc_time_from_sec(TIME *to, long seconds, long microseconds);
int test_if_number(char *str,int *res,bool allow_wildcards); int test_if_number(char *str,int *res,bool allow_wildcards);
void change_byte(byte *,uint,char,char); void change_byte(byte *,uint,char,char);
......
...@@ -823,6 +823,13 @@ bool Protocol_simple::store(Field *field) ...@@ -823,6 +823,13 @@ bool Protocol_simple::store(Field *field)
} }
/*
TODO:
Second_part format ("%06") needs to change when
we support 0-6 decimals for time.
*/
bool Protocol_simple::store(TIME *tm) bool Protocol_simple::store(TIME *tm)
{ {
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
...@@ -840,6 +847,8 @@ bool Protocol_simple::store(TIME *tm) ...@@ -840,6 +847,8 @@ bool Protocol_simple::store(TIME *tm)
(int) tm->hour, (int) tm->hour,
(int) tm->minute, (int) tm->minute,
(int) tm->second)); (int) tm->second));
if (tm->second_part)
length+= my_sprintf(buff+length,(buff+length, ".%06d", (int)tm->second_part));
return net_store_data((char*) buff, length); return net_store_data((char*) buff, length);
} }
...@@ -861,6 +870,12 @@ bool Protocol_simple::store_date(TIME *tm) ...@@ -861,6 +870,12 @@ bool Protocol_simple::store_date(TIME *tm)
} }
/*
TODO:
Second_part format ("%06") needs to change when
we support 0-6 decimals for time.
*/
bool Protocol_simple::store_time(TIME *tm) bool Protocol_simple::store_time(TIME *tm)
{ {
#ifndef DEBUG_OFF #ifndef DEBUG_OFF
...@@ -876,6 +891,8 @@ bool Protocol_simple::store_time(TIME *tm) ...@@ -876,6 +891,8 @@ bool Protocol_simple::store_time(TIME *tm)
(long) day*24L+(long) tm->hour, (long) day*24L+(long) tm->hour,
(int) tm->minute, (int) tm->minute,
(int) tm->second)); (int) tm->second));
if (tm->second_part)
length+= my_sprintf(buff+length,(buff+length, ".%06d", (int)tm->second_part));
return net_store_data((char*) buff, length); return net_store_data((char*) buff, length);
} }
......
...@@ -1290,6 +1290,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1290,6 +1290,11 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
mysql_stmt_free(thd, packet); mysql_stmt_free(thd, packet);
break; break;
} }
case COM_RESET_STMT:
{
mysql_stmt_reset(thd, packet);
break;
}
case COM_QUERY: case COM_QUERY:
{ {
if (alloc_query(thd, packet, packet_length)) if (alloc_query(thd, packet, packet_length))
......
...@@ -965,7 +965,7 @@ void mysql_stmt_reset(THD *thd, char *packet) ...@@ -965,7 +965,7 @@ void mysql_stmt_reset(THD *thd, char *packet)
PREP_STMT *stmt; PREP_STMT *stmt;
DBUG_ENTER("mysql_stmt_reset"); DBUG_ENTER("mysql_stmt_reset");
if (!(stmt=find_prepared_statement(thd, stmt_id, "close"))) if (!(stmt= find_prepared_statement(thd, stmt_id, "reset")))
{ {
send_error(thd); send_error(thd);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
...@@ -390,6 +390,23 @@ bool String::append(IO_CACHE* file, uint32 arg_length) ...@@ -390,6 +390,23 @@ bool String::append(IO_CACHE* file, uint32 arg_length)
return FALSE; return FALSE;
} }
bool String::append_with_prefill(const char *s,uint32 arg_length,
uint32 full_length, char fill_char)
{
int t_length= arg_length > full_length ? arg_length : full_length;
if (realloc(str_length + t_length))
return TRUE;
t_length= full_length - arg_length;
if (t_length > 0)
{
bfill(Ptr+str_length, t_length, fill_char);
str_length=str_length + t_length;
}
append(s, arg_length);
return FALSE;
}
uint32 String::numchars() uint32 String::numchars()
{ {
return str_charset->cset->numchars(str_charset, Ptr, Ptr+str_length); return str_charset->cset->numchars(str_charset, Ptr, Ptr+str_length);
......
...@@ -189,6 +189,8 @@ class String ...@@ -189,6 +189,8 @@ class String
bool append(const char *s,uint32 arg_length=0); bool append(const char *s,uint32 arg_length=0);
bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs); bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs);
bool append(IO_CACHE* file, uint32 arg_length); bool append(IO_CACHE* file, uint32 arg_length);
bool append_with_prefill(const char *s, uint32 arg_length,
uint32 full_length, char fill_char);
int strstr(const String &search,uint32 offset=0); // Returns offset to substring or -1 int strstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
int strstr_case(const String &s,uint32 offset=0); int strstr_case(const String &s,uint32 offset=0);
int strrstr(const String &search,uint32 offset=0); // Returns offset to substring or -1 int strrstr(const String &search,uint32 offset=0); // Returns offset to substring or -1
......
...@@ -163,6 +163,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -163,6 +163,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token VARIANCE_SYM %token VARIANCE_SYM
%token STOP_SYM %token STOP_SYM
%token SUM_SYM %token SUM_SYM
%token ADDDATE_SYM
%token SUPER_SYM %token SUPER_SYM
%token TRUNCATE_SYM %token TRUNCATE_SYM
%token UNLOCK_SYM %token UNLOCK_SYM
...@@ -431,6 +432,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -431,6 +432,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token VARYING %token VARYING
%token ZEROFILL %token ZEROFILL
%token ADDDATE_SYM
%token AGAINST %token AGAINST
%token ATAN %token ATAN
%token BETWEEN_SYM %token BETWEEN_SYM
...@@ -445,6 +447,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -445,6 +447,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token DATE_ADD_INTERVAL %token DATE_ADD_INTERVAL
%token DATE_SUB_INTERVAL %token DATE_SUB_INTERVAL
%token DAY_HOUR_SYM %token DAY_HOUR_SYM
%token DAY_MICROSECOND_SYM
%token DAY_MINUTE_SYM %token DAY_MINUTE_SYM
%token DAY_SECOND_SYM %token DAY_SECOND_SYM
%token DAY_SYM %token DAY_SYM
...@@ -467,6 +470,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -467,6 +470,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token GEOMETRYCOLLECTION %token GEOMETRYCOLLECTION
%token GROUP_CONCAT_SYM %token GROUP_CONCAT_SYM
%token GROUP_UNIQUE_USERS %token GROUP_UNIQUE_USERS
%token HOUR_MICROSECOND_SYM
%token HOUR_MINUTE_SYM %token HOUR_MINUTE_SYM
%token HOUR_SECOND_SYM %token HOUR_SECOND_SYM
%token HOUR_SYM %token HOUR_SYM
...@@ -481,6 +485,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -481,6 +485,8 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token LOCATE %token LOCATE
%token MAKE_SET_SYM %token MAKE_SET_SYM
%token MASTER_POS_WAIT %token MASTER_POS_WAIT
%token MICROSECOND_SYM
%token MINUTE_MICROSECOND_SYM
%token MINUTE_SECOND_SYM %token MINUTE_SECOND_SYM
%token MINUTE_SYM %token MINUTE_SYM
%token MODE_SYM %token MODE_SYM
...@@ -505,7 +511,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); ...@@ -505,7 +511,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token RIGHT %token RIGHT
%token ROUND %token ROUND
%token SECOND_SYM %token SECOND_SYM
%token SECOND_MICROSECOND_SYM
%token SHARE_SYM %token SHARE_SYM
%token SUBDATE_SYM
%token SUBSTRING %token SUBSTRING
%token SUBSTRING_INDEX %token SUBSTRING_INDEX
%token TRIM %token TRIM
...@@ -2334,6 +2342,10 @@ simple_expr: ...@@ -2334,6 +2342,10 @@ simple_expr:
{ $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);} { $$= ((Item*(*)(Item*,Item*))($1.symbol->create_func))($3,$5);}
| FUNC_ARG3 '(' expr ',' expr ',' expr ')' | FUNC_ARG3 '(' expr ',' expr ',' expr ')'
{ $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);} { $$= ((Item*(*)(Item*,Item*,Item*))($1.symbol->create_func))($3,$5,$7);}
| ADDDATE_SYM '(' expr ',' expr ')'
{ $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 0);}
| ADDDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
{ $$= new Item_date_add_interval($3, $6, $7, 0); }
| ATAN '(' expr ')' | ATAN '(' expr ')'
{ $$= new Item_func_atan($3); } { $$= new Item_func_atan($3); }
| ATAN '(' expr ',' expr ')' | ATAN '(' expr ',' expr ')'
...@@ -2368,6 +2380,10 @@ simple_expr: ...@@ -2368,6 +2380,10 @@ simple_expr:
$$= new Item_func_database(); $$= new Item_func_database();
Lex->safe_to_cache_query=0; Lex->safe_to_cache_query=0;
} }
| DATE_SYM '(' expr ')'
{ $$= new Item_date_typecast($3); }
| DAY_SYM '(' expr ')'
{ $$= new Item_func_dayofmonth($3); }
| ELT_FUNC '(' expr ',' expr_list ')' | ELT_FUNC '(' expr ',' expr_list ')'
{ $$= new Item_func_elt($3, *$5); } { $$= new Item_func_elt($3, *$5); }
| MAKE_SET_SYM '(' expr ',' expr_list ')' | MAKE_SET_SYM '(' expr ',' expr_list ')'
...@@ -2484,6 +2500,8 @@ simple_expr: ...@@ -2484,6 +2500,8 @@ simple_expr:
$$= new Item_master_pos_wait($3, $5, $7); $$= new Item_master_pos_wait($3, $5, $7);
Lex->safe_to_cache_query=0; Lex->safe_to_cache_query=0;
} }
| MICROSECOND_SYM '(' expr ')'
{ $$= new Item_func_microsecond($3); }
| MINUTE_SYM '(' expr ')' | MINUTE_SYM '(' expr ')'
{ $$= new Item_func_minute($3); } { $$= new Item_func_minute($3); }
| MOD_SYM '(' expr ',' expr ')' | MOD_SYM '(' expr ',' expr ')'
...@@ -2545,6 +2563,10 @@ simple_expr: ...@@ -2545,6 +2563,10 @@ simple_expr:
| ROUND '(' expr ')' | ROUND '(' expr ')'
{ $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); } { $$= new Item_func_round($3, new Item_int((char*)"0",0,1),0); }
| ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); } | ROUND '(' expr ',' expr ')' { $$= new Item_func_round($3,$5,0); }
| SUBDATE_SYM '(' expr ',' expr ')'
{ $$= new Item_date_add_interval($3, $5, INTERVAL_DAY, 1);}
| SUBDATE_SYM '(' expr ',' INTERVAL_SYM expr interval ')'
{ $$= new Item_date_add_interval($3, $6, $7, 1); }
| SECOND_SYM '(' expr ')' | SECOND_SYM '(' expr ')'
{ $$= new Item_func_second($3); } { $$= new Item_func_second($3); }
| SUBSTRING '(' expr ',' expr ',' expr ')' | SUBSTRING '(' expr ',' expr ',' expr ')'
...@@ -2557,6 +2579,12 @@ simple_expr: ...@@ -2557,6 +2579,12 @@ simple_expr:
{ $$= new Item_func_substr($3,$5); } { $$= new Item_func_substr($3,$5); }
| SUBSTRING_INDEX '(' expr ',' expr ',' expr ')' | SUBSTRING_INDEX '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_substr_index($3,$5,$7); } { $$= new Item_func_substr_index($3,$5,$7); }
| TIME_SYM '(' expr ')'
{ $$= new Item_time_typecast($3); }
| TIMESTAMP '(' expr ')'
{ $$= new Item_datetime_typecast($3); }
| TIMESTAMP '(' expr ',' expr ')'
{ $$= new Item_func_add_time($3, $5, 1, 0); }
| TRIM '(' expr ')' | TRIM '(' expr ')'
{ $$= new Item_func_trim($3); } { $$= new Item_func_trim($3); }
| TRIM '(' LEADING expr FROM expr ')' | TRIM '(' LEADING expr FROM expr ')'
...@@ -2973,15 +3001,20 @@ using_list: ...@@ -2973,15 +3001,20 @@ using_list:
interval: interval:
DAY_HOUR_SYM { $$=INTERVAL_DAY_HOUR; } DAY_HOUR_SYM { $$=INTERVAL_DAY_HOUR; }
| DAY_MICROSECOND_SYM { $$=INTERVAL_DAY_MICROSECOND; }
| DAY_MINUTE_SYM { $$=INTERVAL_DAY_MINUTE; } | DAY_MINUTE_SYM { $$=INTERVAL_DAY_MINUTE; }
| DAY_SECOND_SYM { $$=INTERVAL_DAY_SECOND; } | DAY_SECOND_SYM { $$=INTERVAL_DAY_SECOND; }
| DAY_SYM { $$=INTERVAL_DAY; } | DAY_SYM { $$=INTERVAL_DAY; }
| HOUR_MICROSECOND_SYM { $$=INTERVAL_HOUR_MICROSECOND; }
| HOUR_MINUTE_SYM { $$=INTERVAL_HOUR_MINUTE; } | HOUR_MINUTE_SYM { $$=INTERVAL_HOUR_MINUTE; }
| HOUR_SECOND_SYM { $$=INTERVAL_HOUR_SECOND; } | HOUR_SECOND_SYM { $$=INTERVAL_HOUR_SECOND; }
| HOUR_SYM { $$=INTERVAL_HOUR; } | HOUR_SYM { $$=INTERVAL_HOUR; }
| MICROSECOND_SYM { $$=INTERVAL_MICROSECOND; }
| MINUTE_MICROSECOND_SYM { $$=INTERVAL_MINUTE_MICROSECOND; }
| MINUTE_SECOND_SYM { $$=INTERVAL_MINUTE_SECOND; } | MINUTE_SECOND_SYM { $$=INTERVAL_MINUTE_SECOND; }
| MINUTE_SYM { $$=INTERVAL_MINUTE; } | MINUTE_SYM { $$=INTERVAL_MINUTE; }
| MONTH_SYM { $$=INTERVAL_MONTH; } | MONTH_SYM { $$=INTERVAL_MONTH; }
| SECOND_MICROSECOND_SYM { $$=INTERVAL_SECOND_MICROSECOND; }
| SECOND_SYM { $$=INTERVAL_SECOND; } | SECOND_SYM { $$=INTERVAL_SECOND; }
| YEAR_MONTH_SYM { $$=INTERVAL_YEAR_MONTH; } | YEAR_MONTH_SYM { $$=INTERVAL_YEAR_MONTH; }
| YEAR_SYM { $$=INTERVAL_YEAR; }; | YEAR_SYM { $$=INTERVAL_YEAR; };
...@@ -4300,6 +4333,7 @@ user: ...@@ -4300,6 +4333,7 @@ user:
keyword: keyword:
ACTION {} ACTION {}
| ADDDATE_SYM {}
| AFTER_SYM {} | AFTER_SYM {}
| AGAINST {} | AGAINST {}
| AGGREGATE_SYM {} | AGGREGATE_SYM {}
...@@ -4395,6 +4429,7 @@ keyword: ...@@ -4395,6 +4429,7 @@ keyword:
| MEDIUM_SYM {} | MEDIUM_SYM {}
| MERGE_SYM {} | MERGE_SYM {}
| MEMORY_SYM {} | MEMORY_SYM {}
| MICROSECOND_SYM {}
| MINUTE_SYM {} | MINUTE_SYM {}
| MIN_ROWS {} | MIN_ROWS {}
| MODIFY_SYM {} | MODIFY_SYM {}
...@@ -4460,6 +4495,7 @@ keyword: ...@@ -4460,6 +4495,7 @@ keyword:
| STATUS_SYM {} | STATUS_SYM {}
| STOP_SYM {} | STOP_SYM {}
| STRING_SYM {} | STRING_SYM {}
| SUBDATE_SYM {}
| SUBJECT_SYM {} | SUBJECT_SYM {}
| SUPER_SYM {} | SUPER_SYM {}
| TEMPORARY {} | TEMPORARY {}
......
...@@ -432,6 +432,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date) ...@@ -432,6 +432,7 @@ str_to_TIME(const char *str, uint length, TIME *l_time,bool fuzzy_date)
l_time->minute=date[4]; l_time->minute=date[4];
l_time->second=date[5]; l_time->second=date[5];
l_time->second_part=date[6]; l_time->second_part=date[6];
l_time->neg= 0;
DBUG_RETURN(l_time->time_type= DBUG_RETURN(l_time->time_type=
(number_of_fields <= 3 ? TIMESTAMP_DATE : TIMESTAMP_FULL)); (number_of_fields <= 3 ? TIMESTAMP_DATE : TIMESTAMP_FULL));
} }
...@@ -581,7 +582,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time) ...@@ -581,7 +582,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
/* Get fractional second part */ /* Get fractional second part */
if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_latin1,str[1])) if ((end-str) >= 2 && *str == '.' && my_isdigit(&my_charset_latin1,str[1]))
{ {
uint field_length=3; uint field_length=5;
str++; value=(uint) (uchar) (*str - '0'); str++; value=(uint) (uchar) (*str - '0');
while (++str != end && while (++str != end &&
my_isdigit(&my_charset_latin1,str[0]) && my_isdigit(&my_charset_latin1,str[0]) &&
...@@ -604,6 +605,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time) ...@@ -604,6 +605,7 @@ bool str_to_time(const char *str,uint length,TIME *l_time)
l_time->minute=date[2]; l_time->minute=date[2];
l_time->second=date[3]; l_time->second=date[3];
l_time->second_part=date[4]; l_time->second_part=date[4];
l_time->time_type= TIMESTAMP_TIME;
/* Check if there is garbage at end of the TIME specification */ /* Check if there is garbage at end of the TIME specification */
if (str != end && current_thd->count_cuted_fields) if (str != end && current_thd->count_cuted_fields)
...@@ -636,3 +638,13 @@ void localtime_to_TIME(TIME *to, struct tm *from) ...@@ -636,3 +638,13 @@ void localtime_to_TIME(TIME *to, struct tm *from)
to->minute= (int) from->tm_min; to->minute= (int) from->tm_min;
to->second= (int) from->tm_sec; to->second= (int) from->tm_sec;
} }
void calc_time_from_sec(TIME *to, long seconds, long microseconds)
{
long t_seconds;
to->hour= seconds/3600L;
t_seconds= seconds%3600L;
to->minute= t_seconds/60L;
to->second= t_seconds%60L;
to->second_part= microseconds;
}
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