-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customizing logic for setting values in statements.
- Loading branch information
Showing
9 changed files
with
126 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Statement_Setter.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from Standard.Base import all | ||
import Standard.Base.Errors.Illegal_State.Illegal_State | ||
|
||
polyglot java import java.sql.PreparedStatement | ||
|
||
type Statement_Setter | ||
## PRIVATE | ||
Encapsulates the logic for filling a hole in a prepared statement. | ||
Value (fill_hole : PreparedStatement -> Integer -> Any -> Nothing) | ||
|
||
## PRIVATE | ||
A helper that gets a list of values and fills their corresponding holes | ||
in the prepared statement. | ||
|
||
It assumes that the provided vector contains all values expected in this | ||
prepared statement. It should not be called multiple times on the same | ||
statement. | ||
fill_values : PreparedStatement -> Vector Any -> Nothing | ||
fill_values self stmt values = | ||
values.each_with_index ix-> value-> | ||
self.fill_hole stmt (ix + 1) value | ||
|
||
## PRIVATE | ||
The default setter that is handling simple commonly supported types. | ||
default : Statement_Setter | ||
default = Statement_Setter.Value fill_hole_default | ||
|
||
## PRIVATE | ||
Used internally to mark statements that do not expect to have any values | ||
to set. | ||
|
||
It will panic if called. | ||
null : Statement_Setter | ||
null = | ||
fill_hole_unexpected _ _ _ = | ||
Panic.throw (Illegal_State.Error "The associated statement does not expect any values to be set. This is a bug in the Database library.") | ||
Statement_Setter.Value fill_hole_unexpected | ||
|
||
## PRIVATE | ||
fill_hole_default stmt i value = case value of | ||
Nothing -> stmt.setNull i Java_Types.NULL | ||
_ : Boolean -> stmt.setBoolean i value | ||
_ : Integer -> stmt.setLong i value | ||
_ : Decimal -> stmt.setDouble i value | ||
_ : Text -> stmt.setString i value | ||
_ -> stmt.setObject i value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters