473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Error of DBD::SQLite::db do failed: near ",": syntax error at C:\

47
Hi,
I have this error when i try to insert some values into the database via perl script.

there is my code
Expand|Select|Wrap|Line Numbers
  1. sub addWords {
  2.     my $self = shift;
  3.     my $wordsRef = shift;
  4.     my @words = \$wordsRef;
  5.     my $language = Language->new();
  6.     my $classId = undef;
  7.     my $wordId = undef;
  8.     if (!@words || !$language){
  9.         die "addWords invalid arguments.";
  10.     }
  11.     my $languageId = $language->id();
  12.     my $db = DBI->connect("dbi:SQLite:$dbFile","","",{RaiseError =>1, AutoCommit => 1, sqlite_unicode => 1}) or die "Unable to connect: $DBI::errstr\n"; 
  13.     foreach my $word (@words){ 
  14.         $db->do("INSERT INTO words(wordId, languageId, word, classId) VALUES ($wordId, $languageId, \"$word\", $classId);");         
  15.     }
  16.     $db->disconnect or warn "Disconnection failed: $DBI::errstr\n";;
  17. }
  18.  
Please help
Apr 21 '11 #1
3 6285
RonB
589 Expert Mod 512MB
Start by changing:
Expand|Select|Wrap|Line Numbers
  1. my @words = \$wordsRef;
To:
Expand|Select|Wrap|Line Numbers
  1. my @words = @$wordsRef;
Next, instead of the doing the 'do' statement, it would be better to do a prepare statement prior to the foreach loop and use a placeholder, then do an execute statement in the loop.
Expand|Select|Wrap|Line Numbers
  1.     my $sth = $db->prepare( "INSERT INTO words(wordId, languageId, word, classId) VALUES ($wordId, $languageId, ?, $classId)" );
  2.  
  3.     foreach my $word (@words) { 
  4.         $sth->execute($word);
  5.     }
Apr 21 '11 #2
Rabbit
12,516 Expert Mod 8TB
It's been a while but I'm pretty sure SQLite uses single quotes and not double quotes to demarcate strings.
Apr 21 '11 #3
miller
1,089 Expert 1GB
Winnie,

Address your first question please before asking a related one, or at least continue in the same thread:

http://bytes.com/topic/perl/answers/...trict-refs-use

- Miller
Apr 22 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Julien ARNOUX | last post by:
Hi, I'd like to use regular expressions in sqlite query, I using apsw module but it doesn't work...Can you help me ? My script: import apsw import re path = 'db/db.db3'
0
by: tsivaraman | last post by:
I am trying to build php-5.2.1 in RedHat Linux 9. I have installed libxml2-2.6.11,mysql-5.0.33,httpd-2.2.4(apache) successfully.When i do 'make' from the php directory,i get the following...
0
bartonc
by: bartonc | last post by:
This is a work in progress (current and active). There are some issues to resolve in supporting multiple connection types and I plan to add PySQLite to the mix. The this update is due to my...
10
by: Luigi | last post by:
Hello all! I'm a newbie in PHP. I have written a short script that tries to update a SQLite database with the user data. It is pretty simple, something like this: <?php $sqlite =...
0
by: kurtf | last post by:
Hope somebody could help me with the creation of a table in sqlite3 from python. I am developing an application that allows a user to import a data file and insert the data into a sqlite3...
2
by: Hexade | last post by:
Hello I would like to use the safe "?" placeholder in my SQLite requests but I got the following error: Traceback (most recent call last): (...) cursor.execute("SELECT ? FROM ? WHERE name =...
4
vikysaran
by: vikysaran | last post by:
Hello, I have my new application on Godaddy.com server. Previously it was giving error on Permission. i asked support about it and they told me to set trust level MEDIUM so I search over the...
4
by: peterv6 | last post by:
I'm running OS X Snow Leopard on a MacBook Pro. I've installed Mysql using Macports. MySQL works fine, but I need to install the DBI module. I've tried several ways, but I always get the following...
11
by: Wiinie | last post by:
Can you give me a hint that how to print out the 2d array package DataLayer; sub nextWords { my $lang_size = languages(); for my $id(1 .. $lang_size ){ my ($id, $offset) = @_; my @array...
3
by: Wiinie | last post by:
sub languages{ my $self = shift; if (!$self->{LANGUAGE}) { my @language = (); my $statement = $db1->prepare("select Id, Name, syllableData from language"); $statement->execute(); ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.