Class: FrontbaseAdapter::Connection
- Inherits:
-
Object
- Object
- FrontbaseAdapter::Connection
- Defined in:
- lib/dm-frontbase-adapter/connection.rb
Overview
Connection wrapper
Instance Method Summary collapse
- #close ⇒ Object
- #connection ⇒ Object
- #describe(table) ⇒ Object
- #encoding_map ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #query(str) ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dm-frontbase-adapter/connection.rb', line 7 def initialize() default = { :host => 'localhost', :port => -1, :user => '', :password => '', :dbpassword => '', :database => '', } @options = default.merge() connection end |
Instance Method Details
#close ⇒ Object
67 68 69 70 |
# File 'lib/dm-frontbase-adapter/connection.rb', line 67 def close connection.close @connection = nil end |
#connection ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dm-frontbase-adapter/connection.rb', line 21 def connection unless @connection @connection = FBSQL_Connect.new( @options[:host], @options[:port], @options[:database], @options[:user], @options[:password], @options[:dbpassword] ) @connection.input_charset = encoding_map['UTF-8'] @connection.output_charset = encoding_map['ISO-8859-1'] end @connection end |
#describe(table) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dm-frontbase-adapter/connection.rb', line 49 def describe(table) sql = %[SELECT T3."COLUMN_NAME" AS NAME, T4."DATA_TYPE" FROM INFORMATION_SCHEMA.CATALOGS T0, INFORMATION_SCHEMA.SCHEMATA T1, INFORMATION_SCHEMA.TABLES T2, INFORMATION_SCHEMA.COLUMNS T3, INFORMATION_SCHEMA.DATA_TYPE_DESCRIPTOR T4 WHERE T0."CATALOG_PK" = T1."CATALOG_PK" AND T1."SCHEMA_PK" = T2."SCHEMA_PK" AND T2."TABLE_PK" = T3."TABLE_PK" AND T3."COLUMN_PK" = T4."COLUMN_NAME_PK" AND T1."SCHEMA_NAME" LIKE CURRENT_SCHEMA AND T2."TABLE_NAME" LIKE '#{table}';] connection.query(sql) end |
#encoding_map ⇒ Object
42 43 44 45 46 47 |
# File 'lib/dm-frontbase-adapter/connection.rb', line 42 def encoding_map { 'ISO-8859-1' => FBSQL_Connect::FBC_ISO8859_1, 'UTF-8' => FBSQL_Connect::FBC_UTF_8 } end |
#query(str) ⇒ Object
38 39 40 |
# File 'lib/dm-frontbase-adapter/connection.rb', line 38 def query str connection.query str end |