-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move standard SQL type defs to DBIish:Common
- Loading branch information
Showing
5 changed files
with
150 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
use v6; | ||
# DBIish::Common.pm6 | ||
# Common code used by both DBIish and DBDish | ||
unit package DBIish; | ||
|
||
BEGIN { | ||
Rakudo::Internals.REGISTER-DYNAMIC: '$*DBI-DEFS', { | ||
PROCESS::<$DBI-DEFS> = Hash.new; | ||
}; | ||
} | ||
|
||
# The following list of SQL constants was produced by the following | ||
# adaptation of the EXPORT_TAGS suggestion in 'perldoc DBI': | ||
# perl -MDBI -e'for (@{ $DBI::EXPORT_TAGS{sql_types} }) | ||
# { printf "our sub %s { %d }\n", $_, &{"DBI::$_"}; }' | ||
enum SQLType is export ( | ||
:SQL_GUID( -11), | ||
:SQL_WLONGVARCHAR( -10), | ||
:SQL_WVARCHAR( -9), | ||
:SQL_WCHAR( -8), | ||
:SQL_BIT( -7), | ||
:SQL_TINYINT( -6), | ||
:SQL_BIGINT( -5), | ||
:SQL_LONGVARBINARY( -4), | ||
:SQL_VARBINARY( -3), | ||
:SQL_BINARY( -2), | ||
:SQL_LONGVARCHAR( -1), | ||
:SQL_UNKNOWN_TYPE( 0), | ||
:SQL_ALL_TYPES( 0), | ||
:SQL_CHAR( 1), | ||
:SQL_NUMERIC( 2), | ||
:SQL_DECIMAL( 3), | ||
:SQL_INTEGER( 4), | ||
:SQL_SMALLINT( 5), | ||
:SQL_FLOAT( 6), | ||
:SQL_REAL( 7), | ||
:SQL_DOUBLE( 8), | ||
:SQL_DATETIME( 9), | ||
:SQL_DATE( 9), | ||
:SQL_INTERVAL( 10), | ||
:SQL_TIME( 10), | ||
:SQL_TIMESTAMP( 11), | ||
:SQL_VARCHAR( 12), | ||
:SQL_BOOLEAN( 16), | ||
:SQL_UDT( 17), | ||
:SQL_UDT_LOCATOR( 18), | ||
:SQL_ROW( 19), | ||
:SQL_REF( 20), | ||
:SQL_BLOB( 30), | ||
:SQL_BLOB_LOCATOR( 31), | ||
:SQL_CLOB( 40), | ||
:SQL_CLOB_LOCATOR( 41), | ||
:SQL_ARRAY( 50), | ||
:SQL_ARRAY_LOCATOR( 51), | ||
:SQL_MULTISET( 55), | ||
:SQL_MULTISET_LOCATOR( 56), | ||
:SQL_TYPE_DATE( 91), | ||
:SQL_TYPE_TIME( 92), | ||
:SQL_TYPE_TIMESTAMP( 93), | ||
:SQL_TYPE_TIME_WITH_TIMEZONE( 94), | ||
:SQL_TYPE_TIMESTAMP_WITH_TIMEZONE( 95), | ||
:SQL_INTERVAL_YEAR( 101), | ||
:SQL_INTERVAL_MONTH( 102), | ||
:SQL_INTERVAL_DAY( 103), | ||
:SQL_INTERVAL_HOUR( 104), | ||
:SQL_INTERVAL_MINUTE( 105), | ||
:SQL_INTERVAL_SECOND( 106), | ||
:SQL_INTERVAL_YEAR_TO_MONTH( 107), | ||
:SQL_INTERVAL_DAY_TO_HOUR( 108), | ||
:SQL_INTERVAL_DAY_TO_MINUTE( 109), | ||
:SQL_INTERVAL_DAY_TO_SECOND( 110), | ||
:SQL_INTERVAL_HOUR_TO_MINUTE( 111), | ||
:SQL_INTERVAL_HOUR_TO_SECOND( 112), | ||
:SQL_INTERVAL_MINUTE_TO_SECOND( 113) | ||
); | ||
|
||
constant %SQLType-Conv is export = map({ | ||
+SQLType::{.key} => .value; | ||
},( | ||
:SQL_GUID( (:cast(Str))), | ||
:SQL_WLONGVARCHAR( (:cast(Str))), | ||
:SQL_WVARCHAR( (:cast(Str))), | ||
:SQL_WCHAR( (:cast(Str))), | ||
:SQL_BIGINT( (:cast(Str))), | ||
:SQL_BIT( (:cast(Bool))), | ||
:SQL_TINYINT( (:cast(Int))), | ||
:SQL_LONGVARBINARY( (:cast(Buf))), | ||
:SQL_VARBINARY( (:cast(Buf))), | ||
:SQL_BINARY( (:cast(Buf))), | ||
:SQL_LONGVARCHAR( (:cast(Str))), | ||
:SQL_UNKNOWN_TYPE( (:cast(Any))), | ||
#:SQL_ALL_TYPES( (:cast(Any))), | ||
:SQL_CHAR( (:cast(Str))), | ||
:SQL_NUMERIC( (:cast(Rat))), | ||
:SQL_DECIMAL( (:cast(Rat))), | ||
:SQL_INTEGER( (:cast(Int))), | ||
:SQL_SMALLINT( (:cast(Int))), | ||
:SQL_FLOAT( (:cast(Num))), | ||
:SQL_REAL( (:cast(Num))), | ||
:SQL_DOUBLE( (:cast(Num))), | ||
:SQL_DATETIME( (:cast(Str))), | ||
:SQL_DATE( (:cast(Str))), | ||
:SQL_INTERVAL( (:cast(Str))), | ||
:SQL_TIME( (:cast(Str))), | ||
:SQL_TIMESTAMP( (:cast(Str))), | ||
:SQL_VARCHAR( (:cast(Str))), | ||
:SQL_BOOLEAN( (:cast(Bool))), | ||
:SQL_UDT( (:cast(Str))), | ||
:SQL_UDT_LOCATOR( (:cast(Str))), | ||
:SQL_ROW( (:cast(Str))), | ||
:SQL_REF( (:cast(Str))), | ||
:SQL_BLOB( (:cast(Buf))), | ||
:SQL_BLOB_LOCATOR( (:cast(Str))), | ||
:SQL_CLOB( (:cast(Str))), | ||
:SQL_CLOB_LOCATOR( (:cast(Str))), | ||
:SQL_ARRAY( (:cast(Str))), | ||
:SQL_ARRAY_LOCATOR( (:cast(Str))), | ||
:SQL_MULTISET( (:cast(Str))), | ||
:SQL_MULTISET_LOCATOR( (:cast(Str))), | ||
:SQL_TYPE_DATE( (:cast(Str))), | ||
:SQL_TYPE_TIME( (:cast(Str))), | ||
:SQL_TYPE_TIMESTAMP( (:cast(Str))), | ||
:SQL_TYPE_TIME_WITH_TIMEZONE( (:cast(Str))), | ||
:SQL_TYPE_TIMESTAMP_WITH_TIMEZONE((:cast(Str))), | ||
:SQL_INTERVAL_YEAR( (:cast(Str))), | ||
:SQL_INTERVAL_MONTH( (:cast(Str))), | ||
:SQL_INTERVAL_DAY( (:cast(Str))), | ||
:SQL_INTERVAL_HOUR( (:cast(Str))), | ||
:SQL_INTERVAL_MINUTE( (:cast(Str))), | ||
:SQL_INTERVAL_SECOND( (:cast(Str))), | ||
:SQL_INTERVAL_YEAR_TO_MONTH( (:cast(Str))), | ||
:SQL_INTERVAL_DAY_TO_HOUR( (:cast(Str))), | ||
:SQL_INTERVAL_DAY_TO_MINUTE( (:cast(Str))), | ||
:SQL_INTERVAL_DAY_TO_SECOND( (:cast(Str))), | ||
:SQL_INTERVAL_HOUR_TO_MINUTE( (:cast(Str))), | ||
:SQL_INTERVAL_HOUR_TO_SECOND( (:cast(Str))), | ||
:SQL_INTERVAL_MINUTE_TO_SECOND( (:cast(Str))) | ||
)).hash; |
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