Hi,
I have this error when i try to insert some values into the database via perl script.
there is my code -
sub addWords {
-
my $self = shift;
-
my $wordsRef = shift;
-
my @words = \$wordsRef;
-
my $language = Language->new();
-
my $classId = undef;
-
my $wordId = undef;
-
if (!@words || !$language){
-
die "addWords invalid arguments.";
-
}
-
my $languageId = $language->id();
-
my $db = DBI->connect("dbi:SQLite:$dbFile","","",{RaiseError =>1, AutoCommit => 1, sqlite_unicode => 1}) or die "Unable to connect: $DBI::errstr\n";
-
foreach my $word (@words){
-
$db->do("INSERT INTO words(wordId, languageId, word, classId) VALUES ($wordId, $languageId, \"$word\", $classId);");
-
}
-
$db->disconnect or warn "Disconnection failed: $DBI::errstr\n";;
-
}
-
Please help
3 6285 RonB 589
Expert Mod 512MB
Start by changing:
To:
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. - my $sth = $db->prepare( "INSERT INTO words(wordId, languageId, word, classId) VALUES ($wordId, $languageId, ?, $classId)" );
-
-
foreach my $word (@words) {
-
$sth->execute($word);
-
}
It's been a while but I'm pretty sure SQLite uses single quotes and not double quotes to demarcate strings.
Sign in to post your reply or Sign up for a free account.
Similar topics
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'
|
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...
|
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...
|
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 =...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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();
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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
|
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...
| | |