Closed mirromutth closed 8 months ago
@jchrys
Currently, it is simplify to add RETURNING
following original SQL statement without checking.
Perhaps the statement parser needs to be rewritten to support checking whether the statement supports RETURNING
(INSERT
/REPLACE
/DELETE
) or already includes RETURNING
, like r2dbc-mariadb
does?
@jchrys
Currently, it is simplify to add
RETURNING
following original SQL statement without checking.Perhaps the statement parser needs to be rewritten to support checking whether the statement supports
RETURNING
(INSERT
/REPLACE
/DELETE
) or already includesRETURNING
, liker2dbc-mariadb
does?
I think the current change is suitable for merging, as MariaDB will naturally return a syntax error in case of incorrect RETURNING
usage. I agree that enhancing the parser, akin to what's done in r2dbc-mariadb
, better be next step.
Columns should not be quoted, it can be an expression. e.g. INSERT INTO ... RETURNING CURRENT_TIMESTAMP
.
If we quoted it, like in the example above it would be INSERT INTO ... RETURNING `CURRENT_TIMESTAMP`
, which would be confusing. User wants the result of the CURRENT_TIMESTAMP
expression, not a column named CURRENT_TIMESTAMP
.
Keep columns raw and let ORM/QueryBuilder handle it.
@jchrys It is foreseeable that this PR will change the behavior of returnGenerateValues
when connecting to MariaDB 10.5.1+, maybe we should merge it with the next minor version?
For example, if a user is using returnGenerateValues
without arguments, we will return a Result
with one and only one row, which contains a LAST_INSERT_ID
column. This modification will change the number of result rows (maybe more, maybe 0 by INSERT ... SELECT ... RETURNING ...
), and the row metadata will contain all data columns in the table.
@jchrys It is foreseeable that this PR will change the behavior of
returnGenerateValues
when connecting to MariaDB 10.5.1+, maybe we should merge it with the next minor version?For example, if a user is using
returnGenerateValues
without arguments, we will return aResult
with one and only one row, which contains aLAST_INSERT_ID
column. This modification will change the number of result rows (maybe more, maybe 0 byINSERT ... SELECT ... RETURNING ...
), and the row metadata will contain all data columns in the table.
I agree. 😄
Motivation:
Add
RETURNING
clause support for MariaDB 10.5.1+ .See also #177 .
Modification:
Add
RETURNING
clause inMySqlStatement#returnGeneratedValues
and query message packets.Result:
For MariaDB 10.5.1 and above,
MySqlStatement#returnGeneratedValues
will useRETURNING
clause instead ofLAST_INSERT_ID
.Notice:
For MariaDB 10.5.0 and below,
MySqlStatement#returnGeneratedValues
will still useLAST_INSERT_ID
due to these versions do not supportRETURNING
clause.