nbadw-util 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -263,19 +263,18 @@ module NBADW
263
263
  end
264
264
 
265
265
  STRING_TO_INT_FIXES = [
266
- { :table => "auxuserdbselectedsites", :column => "aquaticsiteuseid" },
267
- { :table => "auxuserdbselectedsiteuse", :column => "aquaticsiteuseid" },
268
- { :table => "cdtranslation - dfo stock mating", :column => "mating code" },
269
- { :table => "del-missing age class in tblfishmeasurement", :column => "fishsampleid" },
270
- { :table => "del-missing age class in tblfishmeasurement-robin", :column => "fishsampleid" },
271
- { :table => "selections", :column => "selectionid" },
272
- { :table => "tblelectrofishingmethoddetail", :column => "aquaticactivitydetailid" },
273
- { :table => "tbloldhabitatsurvey", :column => "habitatsurveyid" }
266
+ { :table => "auxUserDBSelectedSites", :column => "AquaticSiteUseID" },
267
+ { :table => "auxUserDBSelectedSiteUse", :column => "AquaticSiteUseID" },
268
+ { :table => "cdTranslation - DFO Stock Mating", :column => "Mating Code" },
269
+ { :table => "DEL-Missing Age Class in tblFishMeasurement", :column => "FishSampleID" },
270
+ { :table => "DEL-Missing Age Class in tblFishMeasurement-robin", :column => "FishSampleID" },
271
+ { :table => "Selections", :column => "SelectionID" },
272
+ { :table => "tblElectrofishingMethodDetail", :column => "AquaticActivityDetailID" },
273
+ { :table => "tblOldHabitatSurvey", :column => "HabitatSurveyID" }
274
274
  ]
275
275
  # not sure what's up here...
276
276
  before :create_table, :adapter => :postgres, :for => :destination do |src, dst, args|
277
- table = args[:table].to_s.downcase
278
- if fix = STRING_TO_INT_FIXES.detect { |fix| fix[:table] == table }
277
+ if fix = STRING_TO_INT_FIXES.detect { |fix| fix[:table] == args[:table].to_s }
279
278
  schema = args[:schema]
280
279
  schema = schema.split("\n").collect do |line|
281
280
  line = " Integer :\"#{fix[:column]}\"" if line.match(/#{fix[:column]}/)
@@ -7,10 +7,11 @@ src = 'jdbc:access:////home/colin/master.mdb'
7
7
  dst = 'jdbc:mysql://localhost/test?user=developer&password=developer'
8
8
 
9
9
  NBADW::Util::CopyDatabaseTask.start(src, dst, :verify_data => true, :except => ['EF Data before mm/100'])
10
- #
10
+
11
11
  #db = Sequel.connect(src)
12
12
  #
13
- #db.tables.each do |t|
13
+ #tables = db.tables
14
+ #tables.each do |t|
14
15
  # puts t
15
16
  #end
16
17
  #
@@ -19,3 +20,7 @@ NBADW::Util::CopyDatabaseTask.start(src, dst, :verify_data => true, :except => [
19
20
  #db.schema(:cdAgency).each do |col_info|
20
21
  # puts "#{col_info[0]}: #{col_info[1].inspect}"
21
22
  #end
23
+ #
24
+ #db[:cdAgency].each do |row|
25
+ # puts row.inspect
26
+ #end
@@ -1,12 +1,7 @@
1
1
  require 'sequel/adapters/shared/access'
2
2
 
3
3
  module Sequel
4
- module JDBC
5
- class Database
6
- # Alias the generic JDBC version so it can be called directly later
7
- alias jdbc_schema_parse_table schema_parse_table
8
- end
9
-
4
+ module JDBC
10
5
  # Database and Dataset instance methods for MSSQL specific
11
6
  # support via JDBC.
12
7
  module Access
@@ -22,10 +17,24 @@ module Sequel
22
17
  end
23
18
 
24
19
  private
25
- # Call the generic JDBC version instead of MSSQL version,
26
- # since the JDBC version handles primary keys.
27
20
  def schema_parse_table(table, opts={})
28
- jdbc_schema_parse_table(table, opts)
21
+ m = output_identifier_meth
22
+ im = input_identifier_meth
23
+ ds = dataset
24
+ schema, table = schema_and_table(table)
25
+ schema ||= opts[:schema]
26
+ schema = im.call(schema) if schema
27
+ table = im.call(table)
28
+ pks, ts = [], []
29
+ metadata(:getPrimaryKeys, nil, schema, table) do |h|
30
+ h = downcase_hash_keys(h)
31
+ pks << h[:column_name]
32
+ end
33
+ metadata(:getColumns, nil, schema, table, nil) do |h|
34
+ h = downcase_hash_keys(h)
35
+ ts << [m.call(h[:column_name]), {:type=>schema_column_type(h[:type_name]), :db_type=>h[:type_name], :default=>(h[:column_def] == '' ? nil : h[:column_def]), :allow_null=>(h[:nullable] != 0), :primary_key=>pks.include?(h[:column_name]), :column_size=>h[:column_size]}]
36
+ end
37
+ ts
29
38
  end
30
39
 
31
40
  # Primary key indexes appear to start with pk__ on MSSQL
@@ -22,34 +22,40 @@ module Sequel
22
22
  true
23
23
  end
24
24
 
25
+ def tables
26
+ ts = []
27
+ m = output_identifier_meth
28
+ metadata(:getTables, nil, nil, nil, ['TABLE'].to_java(:string)) do |h|
29
+ h = downcase_hash_keys(h)
30
+ ts << m.call(h[:table_name])
31
+ end
32
+ ts
33
+ end
34
+
35
+ def identifier_input_method_default
36
+ :to_s
37
+ end
38
+
39
+ # The method to apply to identifiers coming the database by default.
40
+ # Should be overridden in subclasses for databases that fold unquoted
41
+ # identifiers to lower case instead of uppercase, such as
42
+ # MySQL, PostgreSQL, and SQLite.
43
+ def identifier_output_method_default
44
+ :to_s
45
+ end
46
+
25
47
  private
48
+ def downcase_hash_keys(h)
49
+ lh = {}
50
+ h.each { |k,v| lh[k.to_s.downcase.to_sym] = v }
51
+ lh
52
+ end
26
53
 
27
- # MSSQL uses the IDENTITY(1,1) column for autoincrementing columns.
54
+ # MSSQL uses the COUNTER(1,1) column for autoincrementing columns.
28
55
  def auto_increment_sql
29
56
  AUTO_INCREMENT
30
57
  end
31
58
 
32
- # MSSQL specific syntax for altering tables.
33
- def alter_table_sql(table, op)
34
- case op[:op]
35
- when :add_column
36
- "ALTER TABLE #{quote_schema_table(table)} ADD #{column_definition_sql(op)}"
37
- when :rename_column
38
- "SP_RENAME #{literal("#{quote_schema_table(table)}.#{quote_identifier(op[:name])}")}, #{literal(op[:new_name].to_s)}, 'COLUMN'"
39
- when :set_column_type
40
- "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} #{type_literal(op)}"
41
- when :set_column_null
42
- sch = schema(table).find{|k,v| k.to_s == op[:name].to_s}.last
43
- type = {:type=>sch[:db_type]}
44
- type[:size] = sch[:max_chars] if sch[:max_chars]
45
- "ALTER TABLE #{quote_schema_table(table)} ALTER COLUMN #{quote_identifier(op[:name])} #{type_literal(type)} #{'NOT ' unless op[:null]}NULL"
46
- when :set_column_default
47
- "ALTER TABLE #{quote_schema_table(table)} ADD CONSTRAINT #{quote_identifier("sequel_#{table}_#{op[:name]}_def")} DEFAULT #{literal(op[:default])} FOR #{quote_identifier(op[:name])}"
48
- else
49
- super(table, op)
50
- end
51
- end
52
-
53
59
  # SQL to start a new savepoint
54
60
  def begin_savepoint_sql(depth)
55
61
  SQL_SAVEPOINT % depth
@@ -93,27 +99,6 @@ module Sequel
93
99
  SQL_ROLLBACK
94
100
  end
95
101
 
96
- # MSSQL uses the INFORMATION_SCHEMA to hold column information. This method does
97
- # not support the parsing of primary key information.
98
- def schema_parse_table(table_name, opts)
99
- m = output_identifier_meth
100
- m2 = input_identifier_meth
101
- ds = metadata_dataset.from(:information_schema__tables___t).
102
- join(:information_schema__columns___c, :table_catalog=>:table_catalog,
103
- :table_schema => :table_schema, :table_name => :table_name).
104
- select(:column_name___column, :data_type___db_type, :character_maximum_length___max_chars, :column_default___default, :is_nullable___allow_null).
105
- filter(:c__table_name=>m2.call(table_name.to_s))
106
- if schema = opts[:schema] || default_schema
107
- ds.filter!(:table_schema=>schema)
108
- end
109
- ds.map do |row|
110
- row[:allow_null] = row[:allow_null] == 'YES' ? true : false
111
- row[:default] = nil if blank_object?(row[:default])
112
- row[:type] = schema_column_type(row[:db_type])
113
- [m.call(row.delete(:column)), row]
114
- end
115
- end
116
-
117
102
  # SQL fragment for marking a table as temporary
118
103
  def temporary_table_sql
119
104
  TEMPORARY
@@ -164,12 +149,13 @@ module Sequel
164
149
  meta = result.getMetaData
165
150
  cols = []
166
151
  i = 0
167
- meta.getColumnCount.times{cols << [output_identifier(meta.getColumnLabel(i+=1)).to_s.downcase.to_sym, i]}
152
+ meta.getColumnCount.times { cols << [output_identifier(meta.getColumnLabel(i+=1)), i] }
168
153
  @columns = cols.map{|c| c.at(0)}
169
154
  row = {}
170
155
  blk = if @convert_types
171
156
  lambda{ |n, i|
172
157
  begin
158
+ # puts "#{n}=#{(o = result.getObject(i)).nil? ? 'nil' : o}"
173
159
  row[n] = convert_type(result.getObject(i))
174
160
  rescue
175
161
  # XXX: this is because HXTT driver throws an error here
@@ -276,11 +262,6 @@ module Sequel
276
262
  s.select_sql
277
263
  end
278
264
 
279
- # The version of the database server.
280
- def server_version
281
- db.server_version(@opts[:server])
282
- end
283
-
284
265
  # Microsoft SQL Server does not support INTERSECT or EXCEPT
285
266
  def supports_intersect_except?
286
267
  false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nbadw-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Casey