mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:02:44 +00:00 
			
		
		
		
	 b159bdd4fd
			
		
	
	
		b159bdd4fd
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			40 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibSQL/AST/AST.h>
 | |
| #include <LibSQL/Database.h>
 | |
| #include <LibSQL/Meta.h>
 | |
| #include <LibSQL/Row.h>
 | |
| 
 | |
| namespace SQL::AST {
 | |
| 
 | |
| ResultOr<ResultSet> Delete::execute(ExecutionContext& context) const
 | |
| {
 | |
|     auto const& schema_name = m_qualified_table_name->schema_name();
 | |
|     auto const& table_name = m_qualified_table_name->table_name();
 | |
|     auto table_def = TRY(context.database->get_table(schema_name, table_name));
 | |
| 
 | |
|     ResultSet result { SQLCommand::Delete };
 | |
| 
 | |
|     for (auto& table_row : TRY(context.database->select_all(*table_def))) {
 | |
|         context.current_row = &table_row;
 | |
| 
 | |
|         if (auto const& where_clause = this->where_clause()) {
 | |
|             auto where_result = TRY(where_clause->evaluate(context)).to_bool();
 | |
|             if (!where_result.has_value() || !where_result.value())
 | |
|                 continue;
 | |
|         }
 | |
| 
 | |
|         TRY(context.database->remove(table_row));
 | |
| 
 | |
|         // FIXME: Implement the RETURNING clause.
 | |
|         result.insert_row(table_row, {});
 | |
|     }
 | |
| 
 | |
|     return result;
 | |
| }
 | |
| 
 | |
| }
 |