forked from localytics/odbc_adapter
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from localytics/dbms-consolidation
Consolidate logic onto DatabaseMetadata
- Loading branch information
Showing
7 changed files
with
60 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module ODBCAdapter | ||
# Caches SQLGetInfo output | ||
class DatabaseMetadata | ||
FIELDS = %i[ | ||
SQL_DBMS_NAME | ||
SQL_DBMS_VER | ||
SQL_IDENTIFIER_CASE | ||
SQL_QUOTED_IDENTIFIER_CASE | ||
SQL_IDENTIFIER_QUOTE_CHAR | ||
SQL_MAX_IDENTIFIER_LEN | ||
SQL_MAX_TABLE_NAME_LEN | ||
SQL_USER_NAME | ||
SQL_DATABASE_NAME | ||
] | ||
|
||
attr_reader :values | ||
|
||
def initialize(connection) | ||
@values = Hash[FIELDS.map { |field| [field, connection.get_info(ODBC.const_get(field))] }] | ||
end | ||
|
||
def adapter_class | ||
ODBCAdapter.adapter_for(dbms_name) | ||
end | ||
|
||
def upcase_identifiers? | ||
@upcase_identifiers ||= (identifier_case == ODBC::SQL_IC_UPPER) | ||
end | ||
|
||
# A little bit of metaprogramming magic here to create accessors for each of | ||
# the fields reported on by the DBMS. | ||
FIELDS.each do |field| | ||
define_method(field.to_s.downcase.gsub('sql_', '')) do | ||
value_for(field) | ||
end | ||
end | ||
|
||
private | ||
|
||
def value_for(field) | ||
values[field] | ||
end | ||
end | ||
end |
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 was deleted.
Oops, something went wrong.
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