Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:01:59+00:00 2026-06-14T14:01:59+00:00

I have an example string Canon PowerShot 12.1-Megapixel and when I run the following

  • 0

I have an example string “Canon PowerShot 12.1-Megapixel” and when I run the following code, it seems to fail:

db.execute "CREATE TABLE IF NOT EXISTS Products( id INTEGER PRIMARY KEY, stockID INTEGER, Name TEXT )" 

id = 12345
name = "Canon PowerShot 12.1-Megapixel"       

db.execute( "INSERT INTO Products ( stockID, Name ) VALUES ( #{id}, #{name} )" )

The error code is:

C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/lib/sqlite3/d
atabase.rb:91:in `initialize': near "PowerShot": syntax error
(SQLite3::SQLExcep tion)
        from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/
lib/sqlite3/database.rb:91:in `new'
        from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/
lib/sqlite3/database.rb:91:in `prepare'
        from C:/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.6-x86-mingw32/
lib/sqlite3/database.rb:134:in `execute'
        from E:/Documents/Cowboom/scraping/DBDOTDList.rb:48:in `<main>'

Any idea why this dies after “PowerShot”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:02:01+00:00Added an answer on June 14, 2026 at 2:02 pm

    There are no quotes around the string that you are creating. So the string is actually coming out as:

    "INSERT INTO Products ( stockID, Name ) VALUES ( 12345, Canon PowerShot 12.1-Megapixel )"
    

    As you can see, that is invalid SQL; it will try to interpret Canon PowerSho 12.1-Megapixel as part of the SQL statement, not as a string.

    You could try to fix this by putting quotes around the variable interpolations:

    db.execute( "INSERT INTO Products ( stockID, Name ) VALUES ( #{id}, '#{name}' )" )
    

    However, this is a bad idea in general. If the string winds up containing a ', then that will end the string within the SQL statement, causing an error (or worse, if an attacker does it, an SQL injection exploit; see this comic for an amusing example). You should generally avoid trying to build an SQL query by interpolating or appending strings; you may think that you could filter out or quote the wrong characters, but that is actually quite difficult to do.

    Instead, you should use bound parameters for any variable data that you are passing into your SQL statement:

    db.execute( "INSERT INTO Products ( stockID, Name ) VALUES ( ?, ? )", [id, name])
    

    See the sqlite3-ruby documentation for more information and examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following example string that needs to be filtered 0173556677 (Alice), 017545454 (Bob)
For example I have a string that looks like the following: var example_string =
If I have for example the following string: 123;3344;4334;12 and I want these numbers
I have for example string s = abc edef; I create istringstream with this
I have this example code: string query = select * from xy where id
I have an input string that's generated as in following example: string.Format(Document {0}, was
I have an example string parsed from a log file in the following format:
I have by example following XML: string xml = @<plist version='1.0'> <dict> <key>DataType</key> <string>Employee</string>
I have following example string: $0$aaaaa$1$bbbbb$2$cccccc where between dollar markers there are some numbers.
I have the following example string and I would like to remove only one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.