|
@@ -24,12 +24,23 @@ RefPtr<SQLStatement> SQLStatement::statement_for(int statement_id)
|
|
|
|
|
|
static int s_next_statement_id = 0;
|
|
static int s_next_statement_id = 0;
|
|
|
|
|
|
-SQLStatement::SQLStatement(DatabaseConnection& connection, DeprecatedString sql)
|
|
|
|
|
|
+SQL::ResultOr<NonnullRefPtr<SQLStatement>> SQLStatement::create(DatabaseConnection& connection, StringView sql)
|
|
|
|
+{
|
|
|
|
+ auto parser = SQL::AST::Parser(SQL::AST::Lexer(sql));
|
|
|
|
+ auto statement = parser.next_statement();
|
|
|
|
+
|
|
|
|
+ if (parser.has_errors())
|
|
|
|
+ return SQL::Result { SQL::SQLCommand::Unknown, SQL::SQLErrorCode::SyntaxError, parser.errors()[0].to_deprecated_string() };
|
|
|
|
+
|
|
|
|
+ return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SQLStatement(connection, move(statement))));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+SQLStatement::SQLStatement(DatabaseConnection& connection, NonnullRefPtr<SQL::AST::Statement> statement)
|
|
: Core::Object(&connection)
|
|
: Core::Object(&connection)
|
|
, m_statement_id(s_next_statement_id++)
|
|
, m_statement_id(s_next_statement_id++)
|
|
- , m_sql(move(sql))
|
|
|
|
|
|
+ , m_statement(move(statement))
|
|
{
|
|
{
|
|
- dbgln_if(SQLSERVER_DEBUG, "SQLStatement({}, {})", connection.connection_id(), sql);
|
|
|
|
|
|
+ dbgln_if(SQLSERVER_DEBUG, "SQLStatement({})", connection.connection_id());
|
|
s_statements.set(m_statement_id, *this);
|
|
s_statements.set(m_statement_id, *this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -47,7 +58,6 @@ void SQLStatement::report_error(SQL::Result result)
|
|
else
|
|
else
|
|
warnln("Cannot return execution error. Client disconnected");
|
|
warnln("Cannot return execution error. Client disconnected");
|
|
|
|
|
|
- m_statement = nullptr;
|
|
|
|
m_result = {};
|
|
m_result = {};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -61,12 +71,6 @@ void SQLStatement::execute()
|
|
}
|
|
}
|
|
|
|
|
|
deferred_invoke([this] {
|
|
deferred_invoke([this] {
|
|
- auto parse_result = parse();
|
|
|
|
- if (parse_result.is_error()) {
|
|
|
|
- report_error(parse_result.release_error());
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
VERIFY(!connection()->database().is_null());
|
|
VERIFY(!connection()->database().is_null());
|
|
|
|
|
|
auto execution_result = m_statement->execute(connection()->database().release_nonnull());
|
|
auto execution_result = m_statement->execute(connection()->database().release_nonnull());
|
|
@@ -93,16 +97,6 @@ void SQLStatement::execute()
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-SQL::ResultOr<void> SQLStatement::parse()
|
|
|
|
-{
|
|
|
|
- auto parser = SQL::AST::Parser(SQL::AST::Lexer(m_sql));
|
|
|
|
- m_statement = parser.next_statement();
|
|
|
|
-
|
|
|
|
- if (parser.has_errors())
|
|
|
|
- return SQL::Result { SQL::SQLCommand::Unknown, SQL::SQLErrorCode::SyntaxError, parser.errors()[0].to_deprecated_string() };
|
|
|
|
- return {};
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
bool SQLStatement::should_send_result_rows() const
|
|
bool SQLStatement::should_send_result_rows() const
|
|
{
|
|
{
|
|
VERIFY(m_result.has_value());
|
|
VERIFY(m_result.has_value());
|