lib/spiderfw/model/storage/db/adapters/mysql.rb in spiderfw-0.6.27 vs lib/spiderfw/model/storage/db/adapters/mysql.rb in spiderfw-0.6.28

- old
+ new

@@ -71,11 +71,11 @@ :unique => 65536 } class << self; attr_reader :reserved_kewords, :type_synonyms, :safe_conversions, :field_types, :field_flags end - def self.new_connection(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) + def self.new_connection(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=0) conn = ::Mysql.new(host, user, passwd, db, port.to_i, sock, flag) conn.autocommit(true) conn.query("SET NAMES 'utf8'") return conn end @@ -340,21 +340,27 @@ def sql_create_primary_key(table_name, fields) nil # done in add field or alter field end - def function(func) - return super unless func.func_name == :concat - fields = func.elements.map{ |func_el| - if (func_el.is_a?(Spider::QueryFuncs::Function)) - function(func_el) - else - func.mapper_fields[func_el] - end - } - return "CONCAT(#{fields.map{ |f| "COALESCE(#{f}, '')" }.join(', ')})" - end + def function(func) + case func.func_name + when :rownum + "if(@rn, @rn:=@rn+1, @rn:=1)-1" + when :concat + fields = func.elements.map{ |func_el| + if (func_el.is_a?(Spider::QueryFuncs::Function)) + function(func_el) + else + func.mapper_fields[func_el.to_s] + end + } + "CONCAT(#{fields.map{ |f| "COALESCE(#{f}, '')" }.join(', ')})" + else + super + end + end ############################################################## # Methods to get information from the db # ############################################################## @@ -519,17 +525,9 @@ end db_attributes[:autoincrement] = false if attributes[:autoincrement] && !attributes[:primary_key] return db_attributes end - def function(func) - case func.func_name - when :rownum - "if(@rn, @rn:=@rn+1, @rn:=1)-1" - else - super - end - end def schema_field_int_equal?(current, field) # FIXME return true end