Skip to content

Commit

Permalink
Move standard SQL type defs to DBIish:Common
Browse files Browse the repository at this point in the history
  • Loading branch information
salortiz committed Apr 6, 2016
1 parent 2de753f commit f76f0b6
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 73 deletions.
15 changes: 8 additions & 7 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"perl" : "6",
"perl" : "6",
"name" : "DBIish",
"version" : "0.5.3",
"version" : "0.5.4",
"description" : "Database connectivity for Perl 6",
"test-depends" : [ ],
"depends" : [ "NativeHelpers::Blob" ],
"provides" : {
"DBIish" : "lib/DBIish.pm6",
"DBIish::CommonTesting" : "lib/DBIish/CommonTesting.pm6",
"DBIish::Common" : "lib/DBIish/Common.pm6",
"DBIish::CommonTesting" : "lib/DBIish/CommonTesting.pm6",
"DBDish" : "lib/DBDish.pm6",
"DBDish::Connection" : "lib/DBDish/Connection.pm6",
"DBDish::ErrorHandling" : "lib/DBDish/ErrorHandling.pm6",
"DBDish::StatementHandle" : "lib/DBDish/StatementHandle.pm6",
"DBDish::TestMock" : "lib/DBDish/TestMock.pm6",
"DBDish::TestMock" : "lib/DBDish/TestMock.pm6",
"DBDish::TestMock::StatementHandle" : "lib/DBDish/TestMock/StatementHandle.pm6",
"DBDish::TestMock::Connection" : "lib/DBDish/TestMock/Connection.pm6",
"DBDish::mysql" : "lib/DBDish/mysql.pm6",
"DBDish::mysql" : "lib/DBDish/mysql.pm6",
"DBDish::mysql::Connection" : "lib/DBDish/mysql/Connection.pm6",
"DBDish::mysql::Native" : "lib/DBDish/mysql/Native.pm6",
"DBDish::mysql::StatementHandle" : "lib/DBDish/mysql/StatementHandle.pm6",
"DBDish::Oracle" : "lib/DBDish/Oracle.pm6",
"DBDish::Oracle::Connection" : "lib/DBDish/Oracle/Connection.pm6",
"DBDish::Oracle" : "lib/DBDish/Oracle.pm6",
"DBDish::Oracle::Connection" : "lib/DBDish/Oracle/Connection.pm6",
"DBDish::Oracle::Native" : "lib/DBDish/Oracle/Native.pm6",
"DBDish::Oracle::StatementHandle" : "lib/DBDish/Oracle/StatementHandle.pm6",
"DBDish::Pg" : "lib/DBDish/Pg.pm6",
Expand Down
1 change: 1 addition & 0 deletions lib/DBDish.pm6
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use v6;

unit module DBDish;
need DBIish::Common;
need DBDish::ErrorHandling;
need DBDish::Connection;
need DBDish::StatementHandle;
Expand Down
65 changes: 1 addition & 64 deletions lib/DBIish.pm6
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use v6;
# DBIish.pm6

unit class DBIish:auth<mberends>:ver<0.5.3>;
unit class DBIish:auth<mberends>:ver<0.5.4>;
use DBDish;

package GLOBAL::X::DBIish {
Expand Down Expand Up @@ -83,69 +83,6 @@ unit class DBIish:auth<mberends>:ver<0.5.3>;
}


# 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::$_"}; }'
our sub SQL_GUID { -11 }
our sub SQL_WLONGVARCHAR { -10 }
our sub SQL_WVARCHAR { -9 }
our sub SQL_WCHAR { -8 }
our sub SQL_BIGINT { -5 }
our sub SQL_BIT { -7 }
our sub SQL_TINYINT { -6 }
our sub SQL_LONGVARBINARY { -4 }
our sub SQL_VARBINARY { -3 }
our sub SQL_BINARY { -2 }
our sub SQL_LONGVARCHAR { -1 }
our sub SQL_UNKNOWN_TYPE { 0 }
our sub SQL_ALL_TYPES { 0 }
our sub SQL_CHAR { 1 }
our sub SQL_NUMERIC { 2 }
our sub SQL_DECIMAL { 3 }
our sub SQL_INTEGER { 4 }
our sub SQL_SMALLINT { 5 }
our sub SQL_FLOAT { 6 }
our sub SQL_REAL { 7 }
our sub SQL_DOUBLE { 8 }
our sub SQL_DATETIME { 9 }
our sub SQL_DATE { 9 }
our sub SQL_INTERVAL { 10 }
our sub SQL_TIME { 10 }
our sub SQL_TIMESTAMP { 11 }
our sub SQL_VARCHAR { 12 }
our sub SQL_BOOLEAN { 16 }
our sub SQL_UDT { 17 }
our sub SQL_UDT_LOCATOR { 18 }
our sub SQL_ROW { 19 }
our sub SQL_REF { 20 }
our sub SQL_BLOB { 30 }
our sub SQL_BLOB_LOCATOR { 31 }
our sub SQL_CLOB { 40 }
our sub SQL_CLOB_LOCATOR { 41 }
our sub SQL_ARRAY { 50 }
our sub SQL_ARRAY_LOCATOR { 51 }
our sub SQL_MULTISET { 55 }
our sub SQL_MULTISET_LOCATOR { 56 }
our sub SQL_TYPE_DATE { 91 }
our sub SQL_TYPE_TIME { 92 }
our sub SQL_TYPE_TIMESTAMP { 93 }
our sub SQL_TYPE_TIME_WITH_TIMEZONE { 94 }
our sub SQL_TYPE_TIMESTAMP_WITH_TIMEZONE { 95 }
our sub SQL_INTERVAL_YEAR { 101 }
our sub SQL_INTERVAL_MONTH { 102 }
our sub SQL_INTERVAL_DAY { 103 }
our sub SQL_INTERVAL_HOUR { 104 }
our sub SQL_INTERVAL_MINUTE { 105 }
our sub SQL_INTERVAL_SECOND { 106 }
our sub SQL_INTERVAL_YEAR_TO_MONTH { 107 }
our sub SQL_INTERVAL_DAY_TO_HOUR { 108 }
our sub SQL_INTERVAL_DAY_TO_MINUTE { 109 }
our sub SQL_INTERVAL_DAY_TO_SECOND { 110 }
our sub SQL_INTERVAL_HOUR_TO_MINUTE { 111 }
our sub SQL_INTERVAL_HOUR_TO_SECOND { 112 }
our sub SQL_INTERVAL_MINUTE_TO_SECOND { 113 }

=begin pod
=head1 SYNOPSIS
Expand Down
138 changes: 138 additions & 0 deletions lib/DBIish/Common.pm6
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;
4 changes: 2 additions & 2 deletions t/01-Basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plan drvs.elems * 4 + 14;
use-ok 'DBIish', 'DBIish can be use-d';

my \DBIish = ::('DBIish');
ok DBIish.HOW, "Class is available";
ok DBIish !~~ Failure, "Class is available";

for <connect install-driver> {
ok DBIish.^method_table{$_}:exists, "Method $_";
Expand All @@ -24,7 +24,7 @@ given DBIish.^ver {
for < DBDish DBDish::Driver DBDish::Connection
DBDish::StatementHandle DBDish::ErrorHandling >
{
ok ::("$_").HOW, "Loaded $_";
ok ::("$_") !~~ Failure, "Loaded $_";
}

for drvs {
Expand Down

0 comments on commit f76f0b6

Please sign in to comment.