1616
1717class SqliteCloudClient :
1818 """
19- Client to connect to SqliteCloud
19+ Client to interact with Sqlite Cloud
2020 """
2121
2222 SQLITE_DEFAULT_PORT = 8860
@@ -27,14 +27,11 @@ def __init__(
2727 connection_str : Optional [str ] = None ,
2828 # pub_subs: SQCloudPubSubCallback = [],
2929 ) -> None :
30- """Initializes a new instance of the class.
30+ """Initializes a new instance of the class with connection information .
3131
3232 Args:
3333 connection_str (str): The connection string for the database.
3434
35- Raises:
36- ValueError: If the connection string is invalid.
37-
3835 """
3936 self .driver = Driver ()
4037
@@ -47,7 +44,7 @@ def __init__(
4744 elif cloud_account :
4845 self .config .account = cloud_account
4946 else :
50- raise Exception ("Missing connection parameters" )
47+ raise SQCloudException ("Missing connection parameters" )
5148
5249 def open_connection (self ) -> SQCloudConnect :
5350 """Opens a connection to the SQCloud server.
@@ -72,48 +69,40 @@ def open_connection(self) -> SQCloudConnect:
7269 def disconnect (self , conn : SQCloudConnect ) -> None :
7370 """Closes the connection to the database.
7471
75- This method is used to close the connection to the database. It does not take any arguments and does not return any value.
76-
77- Returns:
78- None: This method does not return any value.
72+ This method is used to close the connection to the database.
7973 """
8074 self .driver .disconnect (conn )
8175
8276 def exec_query (
8377 self , query : str , conn : SQCloudConnect = None
8478 ) -> SqliteCloudResultSet :
85- """Executes a SQL query on the SQLite database.
79+ """Executes a SQL query on the SQLite Cloud database.
8680
8781 Args:
8882 query (str): The SQL query to be executed.
8983
9084 Returns:
9185 SqliteCloudResultSet: The result set of the executed query.
9286 """
93- if not conn :
87+ provided_connection = conn is not None
88+ if not provided_connection :
9489 conn = self .open_connection ()
9590
9691 result = self .driver .execute (query , conn )
92+
93+ if not provided_connection :
94+ self .disconnect (conn )
95+
9796 return SqliteCloudResultSet (result )
9897
99- # def exec_statement(
100- # self, query: str, values: List[Any], conn: SQCloudConnect = None
101- # ) -> SqliteCloudResultSet:
102- # local_conn = conn if conn else self.open_connection()
103- # result: SQCloudResult = SQCloudExecArray(
104- # local_conn,
105- # self._encode_str_to_c(query),
106- # [SqlParameter(self._encode_str_to_c(str(v)), v) for v in values],
107- # )
108- # if SQCloudResultIsError(result):
109- # raise Exception(
110- # "Query error: " + str(SQCloudResultDump(local_conn, result))
111- # )
112- # return SqliteCloudResultSet(result)
113- # pass
114-
115- def sendblob (self ):
116- pass
98+ def sendblob (self , blob : bytes , conn : SQCloudConnect ) -> SqliteCloudResultSet :
99+ """Sends a blob to the SQLite database.
100+
101+ Args:
102+ blob (bytes): The blob to be sent to the database.
103+ conn (SQCloudConnect): The connection to the database.
104+ """
105+ return self .driver .sendblob (blob , conn )
117106
118107 def _parse_connection_string (self , connection_string ) -> SQCloudConfig :
119108 # URL STRING FORMAT
0 commit comments