lib/og/store/mysql.rb in og-0.18.1 vs lib/og/store/mysql.rb in og-0.19.0
- old
+ new
@@ -113,19 +113,19 @@
klass.property :oid, Fixnum, :sql => 'integer AUTO_INCREMENT PRIMARY KEY'
super
end
def query(sql)
-# Logger.debug sql if $DBG
+ Logger.debug sql if $DBG
@conn.query_with_result = true
return @conn.query(sql)
rescue => ex
handle_sql_exception(ex, sql)
end
def exec(sql)
-# Logger.debug sql if $DBG
+ Logger.debug sql if $DBG
@conn.query_with_result = false
@conn.query(sql)
rescue => ex
handle_sql_exception(ex, sql)
end
@@ -147,10 +147,15 @@
def rollback
# nop, not supported?
# FIXME: InnoDB supports transactions.
end
+ def sql_update(sql)
+ exec(sql)
+ @conn.affected_rows
+ end
+
private
def create_table(klass)
fields = fields_for_class(klass)
@@ -159,13 +164,17 @@
# Create table constrains.
if klass.__meta and constrains = klass.__meta[:sql_constrain]
sql << ", #{constrains.join(', ')}"
end
+
+ if table_type = @options[:table_type]
+ sql << ") TYPE = #{table_type};"
+ else
+ sql << ");"
+ end
- sql << ");"
-
# Create indices.
if klass.__meta and indices = klass.__meta[:index]
for data in indices
idx, options = *data
@@ -260,11 +269,16 @@
return "YAML.load(res[#{col} + offset])"
end
end
def eval_og_insert(klass)
- props = klass.properties
+ props = klass.properties.dup
values = props.collect { |p| write_prop(p) }.join(',')
+
+ if klass.metadata.superclass or klass.metadata.subclasses
+ props << Property.new(:ogtype, String)
+ values << ", '#{klass}'"
+ end
sql = "INSERT INTO #{klass::OGTABLE} (#{props.collect {|p| p.symbol.to_s}.join(',')}) VALUES (#{values})"
klass.class_eval %{
def og_insert(store)