DB2 casts strings using RTRIM and CHAR instead of VARCHAR.
# File lib/sequel/adapters/shared/db2.rb, line 245 def cast_sql_append(sql, expr, type) if(type == String) sql << CAST_STRING_OPEN literal_append(sql, expr) sql << CAST_STRING_CLOSE else super end end
# File lib/sequel/adapters/shared/db2.rb, line 255 def complex_expression_sql_append(sql, op, args) case op when :&, :|, :^ # works with db2 v9.5 and after op = BITWISE_METHOD_MAP[op] sql << complex_expression_arg_pairs(args){|a, b| literal(SQL::Function.new(op, a, b))} when :<< sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * POWER(2, #{literal(b)}))"} when :>> sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / POWER(2, #{literal(b)}))"} when :% sql << complex_expression_arg_pairs(args){|a, b| "MOD(#{literal(a)}, #{literal(b)})"} when :'B~' literal_append(sql, SQL::Function.new(:BITNOT, *args)) when :extract sql << args.at(0).to_s sql << PAREN_OPEN literal_append(sql, args.at(1)) sql << PAREN_CLOSE else super end end
DB2 supports GROUP BY CUBE
# File lib/sequel/adapters/shared/db2.rb, line 280 def supports_group_cube? true end
DB2 supports GROUP BY ROLLUP
# File lib/sequel/adapters/shared/db2.rb, line 285 def supports_group_rollup? true end
DB2 does not support IS TRUE.
# File lib/sequel/adapters/shared/db2.rb, line 290 def supports_is_true? false end
DB2 does not support multiple columns in IN.
# File lib/sequel/adapters/shared/db2.rb, line 295 def supports_multiple_column_in? false end
DB2 only allows * in SELECT if it is the only thing being selected.
# File lib/sequel/adapters/shared/db2.rb, line 300 def supports_select_all_and_column? false end
DB2 does not support fractional seconds in timestamps.
# File lib/sequel/adapters/shared/db2.rb, line 305 def supports_timestamp_usecs? false end
DB2 does not support WHERE 1.
# File lib/sequel/adapters/shared/db2.rb, line 315 def supports_where_true? false end
DB2 supports window functions
# File lib/sequel/adapters/shared/db2.rb, line 310 def supports_window_functions? true end
# File lib/sequel/adapters/shared/db2.rb, line 373 def _truncate_sql(table) # "TRUNCATE #{table} IMMEDIATE" is only for newer version of db2, so we # use the following one "ALTER TABLE #{quote_schema_table(table)} ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE" end
DB2 needs the standard workaround to insert all default values into a table with more than one column.
# File lib/sequel/adapters/shared/db2.rb, line 323 def insert_supports_empty_values? false end
DB2 uses a literal hexidecimal number for blob strings
# File lib/sequel/adapters/shared/db2.rb, line 338 def literal_blob_append(sql, v) if ::Sequel::DB2.use_clob_as_blob super else sql << BLOB_OPEN << v.unpack(HSTAR).first << BLOB_CLOSE end end
Use 0 for false on DB2
# File lib/sequel/adapters/shared/db2.rb, line 328 def literal_false BOOL_FALSE end
Use 1 for true on DB2
# File lib/sequel/adapters/shared/db2.rb, line 333 def literal_true BOOL_TRUE end
Add a fallback table for empty from situation
# File lib/sequel/adapters/shared/db2.rb, line 347 def select_from_sql(sql) @opts[:from] ? super : (sql << EMPTY_FROM_TABLE) end
Modify the sql to limit the number of rows returned Note:
After db2 v9.7, MySQL flavored "LIMIT X OFFSET Y" can be enabled using db2set DB2_COMPATIBILITY_VECTOR=MYSQL db2stop db2start Support for this feature is not used in this adapter however.
# File lib/sequel/adapters/shared/db2.rb, line 361 def select_limit_sql(sql) if l = @opts[:limit] if l == 1 sql << FETCH_FIRST_ROW_ONLY else sql << FETCH_FIRST literal_append(sql, l) sql << ROWS_ONLY end end end