SQL API: fix prepared statements with FLOAT/DOUBLE type arguments
SQL API failed to prepare correctly SQL statements containing floating point arguments.
This commit is contained in:
@ -332,13 +332,11 @@ function sql_param.set(self, value)
|
||||
if btype == sql_type.TINYINT or
|
||||
btype == sql_type.SMALLINT or
|
||||
btype == sql_type.INT or
|
||||
btype == sql_type.BIGINT
|
||||
then
|
||||
self.buffer[0] = value
|
||||
elseif btype == sql_type.FLOAT or
|
||||
btype == sql_type.BIGINT or
|
||||
btype == sql_type.FLOAT or
|
||||
btype == sql_type.DOUBLE
|
||||
then
|
||||
self.buffer[1] = value
|
||||
self.buffer[0] = value
|
||||
elseif btype == sql_type.CHAR or
|
||||
btype == sql_type.VARCHAR
|
||||
then
|
||||
|
||||
@ -59,25 +59,27 @@ function event()
|
||||
print(string.format("%s %s", con:query_row("SELECT b, a FROM t2 ORDER BY b")))
|
||||
print('--')
|
||||
con:query("DROP TABLE t2")
|
||||
con:query("ALTER TABLE t ADD COLUMN b CHAR(10)")
|
||||
con:query("ALTER TABLE t ADD COLUMN b CHAR(10), ADD COLUMN c FLOAT")
|
||||
|
||||
e, m = pcall(con.prepare, con, "SELECT * FROM nonexisting")
|
||||
print(m)
|
||||
print('--')
|
||||
|
||||
local stmt = con:prepare("UPDATE t SET a = a + ?, b = ?")
|
||||
local stmt = con:prepare("UPDATE t SET a = a + ?, b = ?, c = ?")
|
||||
local a = stmt:bind_create(sysbench.sql.type.INT)
|
||||
local b = stmt:bind_create(sysbench.sql.type.CHAR, 10)
|
||||
local c = stmt:bind_create(sysbench.sql.type.FLOAT)
|
||||
|
||||
print(a)
|
||||
print(b)
|
||||
print(c)
|
||||
|
||||
e, m = pcall(stmt.bind_create, stmt, sysbench.sql.type.DATE)
|
||||
print(m)
|
||||
|
||||
print(stmt:bind_param())
|
||||
|
||||
stmt:bind_param(a, b)
|
||||
stmt:bind_param(a, b, c)
|
||||
a:set(100)
|
||||
rs1 = stmt:execute()
|
||||
print(rs1)
|
||||
@ -85,6 +87,14 @@ function event()
|
||||
b:set("01234567890")
|
||||
rs2 = stmt:execute()
|
||||
print(rs2)
|
||||
a:set(300)
|
||||
b:set("09876543210")
|
||||
c:set(0.9)
|
||||
rs3 = stmt:execute()
|
||||
print(rs3)
|
||||
|
||||
e, m = pcall(rs3.free, rs)
|
||||
print(m)
|
||||
|
||||
e, m = pcall(rs2.free, rs)
|
||||
print(m)
|
||||
@ -92,6 +102,9 @@ function event()
|
||||
e, m = pcall(rs1.free, rs)
|
||||
print(m)
|
||||
|
||||
rs = con:query("SELECT a, b, c FROM t")
|
||||
print(unpack(rs:fetch_row(), 1, rs.nfields))
|
||||
|
||||
stmt:close()
|
||||
|
||||
print('--')
|
||||
|
||||
@ -47,21 +47,25 @@ SQL Lua API + MySQL tests
|
||||
--
|
||||
<sql_param>
|
||||
<sql_param>
|
||||
<sql_param>
|
||||
Unsupported argument type: 8
|
||||
nil
|
||||
<sql_result>
|
||||
<sql_result>
|
||||
<sql_result>
|
||||
ALERT: attempt to free an invalid result set
|
||||
db_free_results() failed
|
||||
db_free_results() failed
|
||||
db_free_results() failed
|
||||
601\t0987654321\t0.9 (esc)
|
||||
--
|
||||
(last message repeated 1 times)
|
||||
(last message repeated 2 times)
|
||||
ALERT: attempt to use an already closed connection
|
||||
*/api_sql.lua:*: SQL API error (glob)
|
||||
ALERT: attempt to close an already closed connection
|
||||
--
|
||||
4
|
||||
301 400 0123456789 0123456789
|
||||
601 700 0987654321 0987654321
|
||||
--
|
||||
1
|
||||
2
|
||||
|
||||
@ -49,21 +49,25 @@ SQL Lua API + PostgreSQL tests
|
||||
--
|
||||
<sql_param>
|
||||
<sql_param>
|
||||
<sql_param>
|
||||
Unsupported argument type: 8
|
||||
nil
|
||||
<sql_result>
|
||||
<sql_result>
|
||||
<sql_result>
|
||||
ALERT: attempt to free an invalid result set
|
||||
db_free_results() failed
|
||||
db_free_results() failed
|
||||
db_free_results() failed
|
||||
601\t0987654321\t0.9 (esc)
|
||||
--
|
||||
(last message repeated 1 times)
|
||||
(last message repeated 2 times)
|
||||
ALERT: attempt to use an already closed connection
|
||||
*/api_sql.lua:*: SQL API error (glob)
|
||||
ALERT: attempt to close an already closed connection
|
||||
--
|
||||
4
|
||||
301 400 0123456789 0123456789
|
||||
601 700 0987654321 0987654321
|
||||
--
|
||||
1
|
||||
2
|
||||
@ -73,17 +77,17 @@ SQL Lua API + PostgreSQL tests
|
||||
|
||||
connection creation failed
|
||||
--
|
||||
FATAL: PQexec() failed: 7 null value in column "a" violates not-null constraint
|
||||
FATAL: PQexec() failed: 7 null value in column "a" *violates not-null constraint (glob)
|
||||
FATAL: failed query was: INSERT INTO t VALUES (NULL)
|
||||
Got an error descriptor:
|
||||
{
|
||||
connection = <sql_connection>,
|
||||
query = "INSERT INTO t VALUES (NULL)",
|
||||
sql_errmsg = 'null value in column "a" violates not-null constraint',
|
||||
sql_errmsg = 'null value in column "a" *violates not-null constraint', (glob)
|
||||
sql_errno = 0,
|
||||
sql_state = "23502"
|
||||
}
|
||||
*/api_sql.lua:*: SQL error, errno = 0, state = '23502': null value in column "a" violates not-null constraint (glob)
|
||||
*/api_sql.lua:*: SQL error, errno = 0, state = '23502': null value in column "a" *violates not-null constraint (glob)
|
||||
FATAL: PQexec() failed: 7 value too long for type character(1)
|
||||
FATAL: failed query was: INSERT INTO t VALUES ('test')
|
||||
Got an error descriptor:
|
||||
|
||||
Reference in New Issue
Block a user