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 6754911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:20:14+00:00 2026-05-26T13:20:14+00:00

I have a ruby script repeatedly executing the following the INSERT statement using the

  • 0

I have a ruby script repeatedly executing the following the INSERT statement using the dbi gem:

sql = "INSERT INTO traffic_by_pages (publication_id, subdomain, region_id, region_name, page_url, site_section, yr, mnth, dy, TrafficDate, DailyVisitors, DailyVisits, DailyPageViews, NewVisitors, ReturningVisitors, object_id, object_type) VALUES (#{publication_id}, '#{subdomain}', #{region_id}, '#{region_name}', '#{page_url}', '#{site_section}', #{yr}, #{mnth}, #{dy}, '#{trafficdate}', #{dailyvisitors}, #{dailyvisits}, #{dailypageviews}, #{newvisitors}, #{returningvisitors}, #{obj_id}, '#{objectType}');"

This script was working perfectly well until a few days ago with the following error:

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 ‘ ”)’.

The error seems to have started with the addition of an index on object_id and object_type on the table it is inserting into. I have made this conclusion because if I do not insert a value for object_id, the statement magically works. Also, I took the index off our dev version of the table, and oila! It worked again. I need to keep this index.

Has anyone ever dealt with this issue? I am about to re-write the script using active record. The whole script pulls data from MS SQL Server database and INSERTS into a MySQL database.

I should also add when it comes to programming in Ruby I really don’t know what I am doing, and I am not sure how this script ended up being written in Ruby. Any help would be much appreciated. Thanks!

  • 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-05-26T13:20:15+00:00Added an answer on May 26, 2026 at 1:20 pm

    This sounds like it could be a quoting problem. Look closely at the error message:

     ' '')'
    

    You’re getting a space followed by an empty string literal followed by a closing parenthesis in your SQL. You added the object_id and object_type columns and everything broke so the problem is probably in the object_type values.

    You shouldn’t be using string interpolation to build SQL statements, you should be using placeholders. One of these approaches might help:

    sql = 'INSERT INTO traffic_by_pages (publication_id, subdomain, region_id, region_name, page_url, site_section, yr, mnth, dy, TrafficDate, DailyVisitors, DailyVisits, DailyPageViews, NewVisitors, ReturningVisitors, object_id, object_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
    # For each row...
    dbh.do(sql, 
        publication_id,
        subdomain,
        region_id,
        region_name,
        page_url,
        site_section,
        yr,
        mnth,
        dy,
        trafficdate,
        dailyvisitors,
        dailyvisits,
        dailypageviews,
        newvisitors,
        returningvisitors,
        obj_id,
        objectType
    )
    
    # or
    sth = dbh.prepare(sql)
    # for each row...
    sth.execute(publication_id, subdomain, region_id, ...)
    

    That it starts and stops working is strange but that could just be a side effect of your debugging efforts.

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

Sidebar

Related Questions

I have the following Ruby script that creates a Debian package, which works fine:
I have a Ruby script that produces a Latex document using an erb template.
I have a ruby script that creates a message using AMQP in RabbitMQ. #
I have the following Ruby script, in which class Foo includes module Baz, module
I have a ruby script which I run using the JRuby Interpreter. The script
I have a Ruby script I've written using Gruff to produce graphs. These are
I have written a ruby script to screen scrape something using the 'open-uri' and
I have implemented Ruby C extension(i.e. Invoking C function from ruby script) Following is
so i have ruby script that simply writes to a test.txt file with hello
I have a Ruby script that generates a UTF8 CSV file remotely in a

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.