I'm trying to port a nested_set library I have used in another language to 
work with DataMapper.

   sql  = 'LOCK TABLE ' + cattable + ' WRITE;'
    sql += 'SELECT @myRight := rgt FROM ' + cattable + ' WHERE id = ' + 
id.to_s + ';'
    sql += 'UPDATE ' + cattable + ' SET rgt = rgt + 2 WHERE rgt > @myRight;'
    sql += 'UPDATE ' + cattable + ' SET lft = lft + 2 WHERE lft > @myRight;'
    sql += 'INSERT INTO ' + cattable + '(title, lft, rgt' + @xtra_fields + 
',unique_seed) VALUES("' + txt + '", @myRight + 1, @myRight + 2' + 
@xtra_values + ',"' + self.unique_id + '");'
    sql += 'UNLOCK TABLES;'
    puts sql
    adapter = DataMapper.repository(:default).adapter
    adapter.execute(@sql)

When I output the value of the SQL being concatenated and run it in the 
terminal it executes perfectly, but running it from the adapter causes a 
syntax error:

.rvm/gems/ruby-1.9.3-p0/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:63:in
 
`execute_non_query': You have an error in your SQL syntax; check the manual 
that corresponds to your MySQL server version for the right syntax to use 
near 'SELECT @myRight := rgt FROM documints WHERE id = 12;UPDATE documints 
SET rgt = r' at line 1 (DataObjects::SQLError)

I think that perhaps datmapper is choking on the assignment operator when I 
attempt to set the variable @myRight in the second line.

What's the best way to resolve this?

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/datamapper/-/_onm1lFFquoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to