Class: DBI::DBD::SQLAnywhere::Driver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- DBI::DBD::SQLAnywhere::Driver
- Includes:
- Utility
- Defined in:
- lib/dbd/sqlanywhere/driver.rb
Constant Summary
Constants included from Utility
Utility::INPUT_ONLY, Utility::INPUT_OUTPUT, Utility::NO_DIRECTION, Utility::OUTPUT_ONLY
Instance Method Summary collapse
-
#connect(dbname, user, auth, attr) ⇒ Object
The DBNAME string can be specified in the following forms:.
- #default_user ⇒ Object
- #disconnect_all ⇒ Object
-
#initialize ⇒ Driver
constructor
A new instance of Driver.
Methods included from Utility
Constructor Details
#initialize ⇒ Driver
Returns a new instance of Driver.
29 30 31 |
# File 'lib/dbd/sqlanywhere/driver.rb', line 29 def initialize super("0.4.0") end |
Instance Method Details
#connect(dbname, user, auth, attr) ⇒ Object
The DBNAME string can be specified in the following forms:
“DBI:SQLAnywhere:” “DBI:SQLAnywhere:ENG” “DBI:SQLAnywhere:ENG:DBN” “DBI:SQLAnywhere:CONNECTION_STRING” # where CONNECTION_STRING ~= “key1=val1;key2=val2;…”
For the first form, nothing will be added to the connection string. With the second and third forms the driver will add ENG and DBN to the connection string accordingly. The fourth form will pass the supplied connection string through unmolested.
The user and auth can be passed into the function and they will be automatically appended to the connection string. Since Ruby DBI will automatically fill in the username and password with defaults if they are ommited, you should NEVER include a “UID=” or “PWD=” in your connection string or an exception will be thrown.
Examples:
Function Call ==> Generated Connection String
==============================================================================================
DBI.connect("DBI:SQLAnywhere:") ==> "uid=dba;pwd=sql"
DBI.connect("DBI:SQLAnywhere:Demo") ==> "eng=Demo;uid=dba;pwd=sql"
DBI.connect("DBI:SQLAnywhere:Demo:Test") ==> "eng=Demo;dbn=Test;uid=dba;pwd=sql"
DBI.connect("DBI:SQLAnywhere:Demo:Test", 'john', 'doe') ==> "eng=Demo;dbn=Test;uid=john;pwd=doe"
DBI.connect("DBI:SQLAnywhere:eng=Demo;dbn=Test") ==> "eng=Demo;dbn=Test;uid=dba;pwd=sql"
DBI.connect("DBI:SQLAnywhere:eng=Demo;dbn=Test;uid=john") ==> EXCEPTION! UID cannot be specified in the connection string
DBI.connect("DBI:SQLAnywhere:CommLinks=tcpip(port=2638)") ==> "CommLinks=tcpip(port=2638);uid=dba;pwd=sql"
The attr parameter is ignored.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dbd/sqlanywhere/driver.rb', line 62 def connect( dbname, user, auth, attr ) conn = SA.instance.api.sqlany_new_connection() conn_str = '' unless dbname.nil? if dbname =~ /^[^=:;]+$/ conn_str = "eng=#{dbname};" elsif dbname =~ /^[^=:;]+:[^=:;]+$/ eng_name, db_name = dbname.split(":") conn_str = "eng=#{eng_name};dbn=#{db_name};" else conn_str = dbname; conn_str << ';' unless conn_str.length == 0 or conn_str[conn_str.length - 1, 1] == ';' end end unless user.nil? raise DBI::ProgrammingError.new("UID is specified twice. Once in the connection string AND once as a connect() parameter. It can only be specified once.") if conn_str =~ /uid=/i conn_str << "uid=#{user};" end unless auth.nil? raise DBI::ProgrammingError.new("PWD is specified twice. Once in the connection string AND once as a connect() parameter. It can only be specifed once.") if conn_str =~ /pwd=/i conn_str << "pwd=#{auth};" end res = SA.instance.api.sqlany_connect(conn, conn_str) if res == 0 then code, msg = SA.instance.api.sqlany_error(conn) state = SA.instance.api.sqlany_sqlstate(conn) raise DBI::DatabaseError.new(msg, code, state) end return Database.new(conn, attr) end |
#default_user ⇒ Object
99 100 101 |
# File 'lib/dbd/sqlanywhere/driver.rb', line 99 def default_user return ['dba', 'sql'] end |