DB transaction setup, and feeling stupid

Hi, all. I'm a relative Ruby newb, and I'm trying to set up paramaterized MySQL queries. And am getting completely stumped. I do a similar query slightly before this one, and it works great. This one? Not so much. It fails with the same error in my .rb file, but I figured I'd give the pry for the gory details (and fewer lines):

[1] pry(main)> require 'mysql'
=> true
[2] pry(main)> @db_conn = Mysql.new 'localhost', 'root', 'passwordhere', 'jabberlogs'
=> #<Mysql:0x0000000183f760>
[3] pry(main)> line = '/home/ken/.purple/logs/jabber/kdambr200@cable/aabreh200@vss-xmpp.sys.comcast.net/2013-04-10.100100-0400EDT.html'
=> "/home/ken/.purple/logs/jabber/kdambr200@cable/aabreh200@vss-xmpp.sys.comcast.net/2013-04-10.100100-0400EDT.html"
[4] pry(main)> @dbio = @db_conn.prepare "SELECT file_id FROM loglines WHERE line=\"?\""
=> #<Mysql::Stmt:0x00000001599a60>
[5] pry(main)> @dbio.execute(line)
Mysql::Error: execute: param_count(0) != number of argument(1)
from (pry):5:in `execute'

I've tried all the permutations I can think for syntax surrounding the question mark... but I'm kinda stumped. Any pointers?

Thanks kindly,

-Ken

Hi, all. I'm a relative Ruby newb, and I'm trying to set up paramaterized MySQL queries. And am getting completely stumped. I do a similar query slightly before this one, and it works great. This one? Not so much. It fails with the same error in my .rb file, but I figured I'd give the pry for the gory details (and fewer lines):

[1] pry(main)> require 'mysql'
=> true
[2] pry(main)> @db_conn = Mysql.new 'localhost', 'root', 'passwordhere', 'jabberlogs'
=> #<Mysql:0x0000000183f760>
[3] pry(main)> line = '/home/ken/.purple/logs/jabber/kdambr200@cable/aabreh200@vss-xmpp.sys.comcast.net/2013-04-10.100100-0400EDT.html'
=> "/home/ken/.purple/logs/jabber/kdambr200@cable/aabreh200@vss-xmpp.sys.comcast.net/2013-04-10.100100-0400EDT.html"
[4] pry(main)> @dbio = @db_conn.prepare "SELECT file_id FROM loglines WHERE line=\"?\""

Have you tried

@dbio = @db_conn.prepare "SELECT file_id FROM loglines WHERE line=?"

So that the place holder is not "hidden" in a string?

=> #<Mysql::Stmt:0x00000001599a60>
[5] pry(main)> @dbio.execute(line)
Mysql::Error: execute: param_count(0) != number of argument(1)
from (pry):5:in `execute'

I've tried all the permutations I can think for syntax surrounding the question mark... but I'm kinda stumped. Any pointers?

Thanks kindly,

-Ken

Hope this helps,

Mike

···

On 2013-06-21, at 7:20 PM, "Ken D'Ambrosio" <ken@jots.org> wrote:

--

Mike Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.

Hi, all. I'm a relative Ruby newb, and I'm trying to set up paramaterized
MySQL queries. And am getting completely stumped. I do a similar query
slightly before this one, and it works great. This one? Not so much. It
fails with the same error in my .rb file, but I figured I'd give the pry
for the gory details (and fewer lines):

[1] pry(main)> require 'mysql'
=> true
[2] pry(main)> @db_conn = Mysql.new 'localhost', 'root', 'passwordhere',
'jabberlogs'
=> #<Mysql:0x0000000183f760>
[3] pry(main)> line = '/home/ken/.purple/logs/jabber/kdambr200@cable
/aabreh200@vss-xmpp.sys.comcast.net/2013-04-10.100100-0400EDT.html'
=> "/home/ken/.purple/logs/jabber/kdambr200@cable/
aabreh200@vss-xmpp.sys.comcast.net/2013-04-10.100100-0400EDT.html"
[4] pry(main)> @dbio = @db_conn.prepare "SELECT file_id FROM loglines
WHERE line=\"?\""

Have you tried

@dbio = @db_conn.prepare "SELECT file_id FROM loglines WHERE line=?"

So that the place holder is not "hidden" in a string?

It's not hidden - it's not a placeholder any more. :slight_smile: I agree: I am
almost 100% sure that this is the issue. When looking at the error message
it mentions 0 parameters but found 1 argument (see below).

=> #<Mysql::Stmt:0x00000001599a60>
[5] pry(main)> @dbio.execute(line)
Mysql::Error: execute: param_count(0) != number of argument(1)
from (pry):5:in `execute'

Kind regards

robert

···

On Sat, Jun 22, 2013 at 1:26 AM, Mike Stok <mike@stok.ca> wrote:

On 2013-06-21, at 7:20 PM, "Ken D'Ambrosio" <ken@jots.org> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/