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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wiinie
    New Member
    • Feb 2011
    • 47

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

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

    there is my code
    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
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Start by changing:
    Code:
    my @words = \$wordsRef;
    To:
    Code:
    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.
    Code:
        my $sth = $db->prepare( "INSERT INTO words(wordId, languageId, word, classId) VALUES ($wordId, $languageId, ?, $classId)" );
        
        foreach my $word (@words) { 
            $sth->execute($word);
        }

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      It's been a while but I'm pretty sure SQLite uses single quotes and not double quotes to demarcate strings.

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Winnie,

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



        - Miller

        Comment

        Working...