mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:22:45 +00:00 
			
		
		
		
	SQLServer: Parse SQL a single time to actually "prepare" the statement
One of the benefits of prepared statements is that the SQL string is parsed just once and re-used. This updates SQLStatement to do just that and store the parsed result.
This commit is contained in:
		
							parent
							
								
									83bb25611e
								
							
						
					
					
						commit
						b13527b8b2
					
				
					 5 changed files with 40 additions and 39 deletions
				
			
		|  | @ -67,19 +67,20 @@ void DatabaseConnection::disconnect() | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| int DatabaseConnection::prepare_statement(DeprecatedString const& sql) | ||||
| SQL::ResultOr<int> DatabaseConnection::prepare_statement(StringView sql) | ||||
| { | ||||
|     dbgln_if(SQLSERVER_DEBUG, "DatabaseConnection::prepare_statement(connection_id {}, database '{}', sql '{}'", connection_id(), m_database_name, sql); | ||||
| 
 | ||||
|     if (!m_accept_statements) | ||||
|         return SQL::Result { SQL::SQLCommand::Unknown, SQL::SQLErrorCode::DatabaseUnavailable }; | ||||
| 
 | ||||
|     auto client_connection = ConnectionFromClient::client_connection_for(client_id()); | ||||
|     if (!client_connection) { | ||||
|         warnln("Cannot notify client of database disconnection. Client disconnected"); | ||||
|         return -1; | ||||
|         return SQL::Result { SQL::SQLCommand::Unknown, SQL::SQLErrorCode::InternalError, "Client disconnected"sv }; | ||||
|     } | ||||
|     if (!m_accept_statements) { | ||||
|         client_connection->async_execution_error(-1, (int)SQL::SQLErrorCode::DatabaseUnavailable, m_database_name); | ||||
|         return -1; | ||||
|     } | ||||
|     auto statement = SQLStatement::construct(*this, sql); | ||||
| 
 | ||||
|     auto statement = TRY(SQLStatement::create(*this, sql)); | ||||
|     return statement->statement_id(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy Flynn
						Timothy Flynn