mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibSQL: Parse INSERT statement without column names
This adds the ability to parse SQL INSERT statements in the following form: INSERT INTO schema.tablename VALUES (column1, column2, ...), (column1, column2, ...), ...
This commit is contained in:
parent
64e231bd38
commit
f390478127
2 changed files with 18 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
||||
* Copyright (c) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -37,9 +38,20 @@ RefPtr<SQLResult> Insert::execute(ExecutionContext& context) const
|
|||
auto row_value = row_expr.evaluate(context);
|
||||
VERIFY(row_value.type() == SQLType::Tuple);
|
||||
auto values = row_value.to_vector().value();
|
||||
for (auto ix = 0u; ix < values.size(); ix++) {
|
||||
auto& column_name = m_column_names[ix];
|
||||
row[column_name] = values[ix];
|
||||
|
||||
// FIXME: Check that the values[ix] match the data type of the column.
|
||||
if (m_column_names.size() > 0) {
|
||||
for (auto ix = 0u; ix < values.size(); ix++) {
|
||||
auto& column_name = m_column_names[ix];
|
||||
row[column_name] = values[ix];
|
||||
}
|
||||
} else {
|
||||
if (values.size() != row.size()) {
|
||||
return SQLResult::construct(SQLCommand::Insert, SQLErrorCode::InvalidNumberOfValues, "");
|
||||
}
|
||||
for (auto ix = 0u; ix < values.size(); ix++) {
|
||||
row[ix] = values[ix];
|
||||
}
|
||||
}
|
||||
context.database->insert(row);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue