Skip to content

Commit

Permalink
add auto incremnted
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-j-m committed Nov 18, 2024
1 parent 18c0363 commit a649c0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def disconnect!
# Build a new column object from the given options. Effectively the same
# as super except that it also passes in the native type.
# rubocop:disable Metrics/ParameterLists
def new_column(name, default, sql_type_metadata, null, table_name, default_function = nil, collation = nil, native_type = nil)
::ODBCAdapter::Column.new(name, default, sql_type_metadata, null, table_name, default_function, collation, native_type)
def new_column(name, default, sql_type_metadata, null, native_type = nil, auto_incremented = false)
::ODBCAdapter::Column.new(name, default, sql_type_metadata, null, native_type, auto_incremented)
end

protected
Expand Down Expand Up @@ -166,6 +166,11 @@ def initialize_type_map(map)
alias_type map, ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP
end

# odbc_adapter does not support returning, so there are no return values from an insert
def return_value_after_insert?(column) # :nodoc:
column.auto_incremented
end

# Translate an exception from the native DBMS to something usable by
# ActiveRecord.
def translate_exception(exception, message:, sql:, binds:)
Expand Down
7 changes: 4 additions & 3 deletions lib/odbc_adapter/column.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
module ODBCAdapter
class Column < ActiveRecord::ConnectionAdapters::Column
attr_reader :native_type
attr_reader :native_type, :auto_incremented

# Add the native_type accessor to allow the native DBMS to report back what
# it uses to represent the column internally.
# rubocop:disable Metrics/ParameterLists
def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, native_type = nil, default_function = nil, collation = nil)
super(name, default, sql_type_metadata, null, table_name, default_function, collation)
def initialize(name, default, sql_type_metadata = nil, null = true, native_type = nil, auto_incremented, **kwargs)
super(name, default, sql_type_metadata, null, **kwargs)
@native_type = native_type
@auto_incremented = auto_incremented
end
end
end
3 changes: 2 additions & 1 deletion lib/odbc_adapter/schema_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def columns(table_name, _name = nil)

# SQLColumns: IS_NULLABLE, SQLColumns: NULLABLE
col_nullable = nullability(col_name, col[17], col[10])
auto_incremented = col[:auto_incremented]

args = { sql_type: col_sql_type, type: col_sql_type, limit: col_limit }
args[:sql_type] = 'boolean' if col_native_type == self.class::BOOLEAN_TYPE
Expand All @@ -83,7 +84,7 @@ def columns(table_name, _name = nil)
end
sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(**args)

cols << new_column(format_case(col_name), col_default, sql_type_metadata, col_nullable, table_name, col_native_type)
cols << new_column(format_case(col_name), col_default, sql_type_metadata, col_nullable, col_native_type, auto_incremented)
end
end

Expand Down

0 comments on commit a649c0d

Please sign in to comment.