Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryTravis committed Jan 31, 2025
1 parent 2bdd405 commit fa7dfcc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ type Invalid_Array_Index
Error array index

## PRIVATE
Convert the Forbidden_Operation error to a human-readable format.
Convert the Invalid_Array_Index error to a human-readable format.
to_display_text : Text
to_display_text self = "Invalid array index: "+self.index.to_text+"."

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from Standard.Base import all

import Standard.Base.Errors.Common.Forbidden_Operation
import Standard.Base.Errors.Common.Missing_Argument
import Standard.Base.Runtime.Context

from Standard.Table import Table

import project.Internal.Column_Fetcher as Column_Fetcher_Module
Expand Down Expand Up @@ -39,7 +44,7 @@ type Generic_JDBC_Connection
Connect to an H2 database instance.

connection = Generic_JDBC_Connection.connect "jdbc:h2:~/my_database"
connect url:Text -> Generic_JDBC_Connection =
connect (url : Text = (Missing_Argument.throw "url")) -> Generic_JDBC_Connection =
jdbc_connection = JDBC_Connection.create url []
Generic_JDBC_Connection.Value jdbc_connection

Expand All @@ -61,7 +66,8 @@ type Generic_JDBC_Connection
GROUP Standard.Base.Output
ICON data_output

Execute a raw SQL query or statement.
Execute a raw SQL query or statement. `execute` does not execute the SQL
unless the output context is enabled.

Returns the row count for a SQL DML statement, or 0 for SQL statements
that return nothing.
Expand All @@ -74,9 +80,10 @@ type Generic_JDBC_Connection

connection = Generic_JDBC_Connection.connect "jdbc:h2:~/my_database"
connection.execute "create table foo (a int)"
execute self sql:Text -> Integer =
self.jdbc_connection.with_prepared_statement sql Statement_Setter.default stmt->
stmt.executeUpdate
execute self (sql : Text = (Missing_Argument.throw "sql")) -> Integer =
when_output_enabled <|
self.jdbc_connection.with_prepared_statement sql Statement_Setter.default stmt->
stmt.executeUpdate

## ALIAS import, load
GROUP Standard.Base.Input
Expand All @@ -100,7 +107,7 @@ type Generic_JDBC_Connection

connection = Generic_JDBC_Connection.connect "jdbc:h2:~/my_database"
table = connection.read (SQL_Query.Table_name "foo")
read self sql_query:SQL_Query -> Table =
read self (sql_query : SQL_Query = (Missing_Argument.throw "sql_query")) -> Table =
resolved_sql = case sql_query of
SQL_Query.Raw_SQL raw_sql -> raw_sql
SQL_Query.Table_Name table_name -> "select * from "+(self.quote_identifier table_name)
Expand Down Expand Up @@ -287,3 +294,9 @@ private rs_to_table_ rs =
make_fallback_fetcher _ =
Column_Fetcher_Module.fallback_fetcher
result_set_to_table rs make_fallback_fetcher

## PRIVATE
Run the action if Output is enabled, otherwise raise a dataflow error
when_output_enabled ~action =
if Context.Output.is_enabled then action else
Error.throw (Forbidden_Operation.Error ("As writing is disabled, this operation was not executed. Press the Write button ▶ to execute it."))

0 comments on commit fa7dfcc

Please sign in to comment.