mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:52:45 +00:00 
			
		
		
		
	 e923cb3739
			
		
	
	
		e923cb3739
		
	
	
	
	
		
			
			The database the sql client connected to was 'hardcoded' to the login name of the calling user. - Extended the IPC API to be more expressive when connecting, by returning the name of the database the client connected to in the 'connected' callback. - Gave the sql client a command line argument (-d/--database) allowing an alternative database name to be specified A subsequent commit will have a dot command allowing the user to connect to different databases from the same sql session.
		
			
				
	
	
		
			44 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <LibIPC/ServerConnection.h>
 | |
| #include <SQLServer/SQLClientEndpoint.h>
 | |
| #include <SQLServer/SQLServerEndpoint.h>
 | |
| 
 | |
| namespace SQL {
 | |
| 
 | |
| class SQLClient
 | |
|     : public IPC::ServerConnection<SQLClientEndpoint, SQLServerEndpoint>
 | |
|     , public SQLClientEndpoint {
 | |
|     C_OBJECT(SQLClient);
 | |
|     virtual ~SQLClient();
 | |
| 
 | |
|     Function<void(int, String const&)> on_connected;
 | |
|     Function<void(int)> on_disconnected;
 | |
|     Function<void(int, int, String const&)> on_connection_error;
 | |
|     Function<void(int, int, String const&)> on_execution_error;
 | |
|     Function<void(int, bool, int, int, int)> on_execution_success;
 | |
|     Function<void(int, Vector<String> const&)> on_next_result;
 | |
|     Function<void(int, int)> on_results_exhausted;
 | |
| 
 | |
| private:
 | |
|     SQLClient()
 | |
|         : IPC::ServerConnection<SQLClientEndpoint, SQLServerEndpoint>(*this, "/tmp/portal/sql")
 | |
|     {
 | |
|     }
 | |
| 
 | |
|     virtual void connected(int connection_id, String const& connected_to_database) override;
 | |
|     virtual void connection_error(int connection_id, int code, String const& message) override;
 | |
|     virtual void execution_success(int statement_id, bool has_results, int created, int updated, int deleted) override;
 | |
|     virtual void next_result(int statement_id, Vector<String> const&) override;
 | |
|     virtual void results_exhausted(int statement_id, int total_rows) override;
 | |
|     virtual void execution_error(int statement_id, int code, String const& message) override;
 | |
|     virtual void disconnected(int connection_id) override;
 | |
| };
 | |
| 
 | |
| }
 |