Преглед изворни кода

LibSQL+SQLServer+sql: Send and parse the correct number of changed rows

The sql REPL had the created/updated rows swapped by mistake. Also make
sure SQLServer fills in the correct value depending on the executed
command, and that the DELETE command indicates the rows it deleted.
Timothy Flynn пре 2 година
родитељ
комит
b159bdd4fd

+ 1 - 0
Userland/Libraries/LibSQL/AST/Delete.cpp

@@ -31,6 +31,7 @@ ResultOr<ResultSet> Delete::execute(ExecutionContext& context) const
         TRY(context.database->remove(table_row));
         TRY(context.database->remove(table_row));
 
 
         // FIXME: Implement the RETURNING clause.
         // FIXME: Implement the RETURNING clause.
+        result.insert_row(table_row, {});
     }
     }
 
 
     return result;
     return result;

+ 8 - 1
Userland/Services/SQLServer/SQLStatement.cpp

@@ -94,7 +94,14 @@ Optional<u64> SQLStatement::execute(Vector<SQL::Value> placeholder_values)
             auto result_size = result.size();
             auto result_size = result.size();
             next(execution_id, move(result), result_size);
             next(execution_id, move(result), result_size);
         } else {
         } else {
-            client_connection->async_execution_success(statement_id(), execution_id, false, 0, result.size(), 0);
+            if (result.command() == SQL::SQLCommand::Insert)
+                client_connection->async_execution_success(statement_id(), execution_id, false, result.size(), 0, 0);
+            else if (result.command() == SQL::SQLCommand::Update)
+                client_connection->async_execution_success(statement_id(), execution_id, false, 0, result.size(), 0);
+            else if (result.command() == SQL::SQLCommand::Delete)
+                client_connection->async_execution_success(statement_id(), execution_id, false, 0, 0, result.size());
+            else
+                client_connection->async_execution_success(statement_id(), execution_id, false, 0, 0, 0);
         }
         }
     });
     });
 
 

+ 2 - 2
Userland/Utilities/sql.cpp

@@ -76,9 +76,9 @@ public:
 
 
         m_sql_client = SQL::SQLClient::try_create().release_value_but_fixme_should_propagate_errors();
         m_sql_client = SQL::SQLClient::try_create().release_value_but_fixme_should_propagate_errors();
 
 
-        m_sql_client->on_execution_success = [this](auto, auto, auto has_results, auto updated, auto created, auto deleted) {
+        m_sql_client->on_execution_success = [this](auto, auto, auto has_results, auto created, auto updated, auto deleted) {
             if (updated != 0 || created != 0 || deleted != 0) {
             if (updated != 0 || created != 0 || deleted != 0) {
-                outln("{} row(s) updated, {} created, {} deleted", updated, created, deleted);
+                outln("{} row(s) created, {} updated, {} deleted", created, updated, deleted);
             }
             }
             if (!has_results) {
             if (!has_results) {
                 read_sql();
                 read_sql();