Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
unintuitive language feature (exclamation functions)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="brabuhr, post: 4616354"] Internal to the CGI object, it appears that "a" in the @params hash is an array of strings not a string: irb(main):007:0> cgi = CGI.new('html4') (offline mode: enter name=value pairs on standard input) a=foohibyebar #!/usr/bin/env ruby require 'rubygems' require 'sqlite3' db = SQLite3::Database.new('test.sqlite') db.execute ('drop table if exists example') # clean up incase of multiple runs db.execute('create table example (aval)') require 'cgi' cgi = CGI.new('html4') a = cgi['a'][0] a.sub!(/hi/, 'bye') # to see expected behavior, replace the above with: a = a.sub(/hi/, 'bye') puts "Inserting value a=#{a} into the database.\n" sql = "insert into example (aval) values (?)" db.execute(sql, a) sql = "select aval from example" val = db.get_first_value(sql) puts "What was actually inserted into the database: #{val}\n" z.rb:7: warning: don't put space before argument parentheses (offline mode: enter name=value pairs on standard input) a=foohibyebar z.rb:13:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key'] Inserting value a=foobyebyebar into the database. What was actually inserted into the database: foobyebyebar [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
unintuitive language feature (exclamation functions)
Top