[vox-tech] sqlite + perl - wierd unrecognized token error

Henry House hajhouse at houseag.com
Thu Dec 23 13:09:37 PST 2004


På torsdag, 23 december 2004, skrev Peter Jay Salzman:
> On Thu 23 Dec 04, 11:15 AM, Shwaine <shwaine at shwaine.com> said:
> > On Thu, 23 Dec 2004, Peter Jay Salzman wrote:
> > <snip>
> > >  DBD::SQLite::db do failed: unrecognized token: ":" at Create_Tables.pm 
> > >  line
> > >  52, <> line 6.
> > >
> > <snip>
> > >Excerpt from Create_Tables.pm:
> > >
> > <snip>
> > >     my $dbh = DBI->connect("dbi:SQLite:$table_name");
> > >
> > <snip>
> > >Statement handle DBI::st=HASH(0x840773c) DESTROY ignored - never set up
> > >       ERROR: 1 'unrecognized token: ":"' (err#0)

This error seems to be coming from failure of the string cotaining the SQL
to be interpolated as expected. Changing the code to this:


	use DBI;

   sub Create_Course()
   {
      my %course;

      print "Enter semester: ";
      $course{semester} = <>;

      print "Enter course: ";
      $course{course} = <>;

      print "Enter Course Desc: ";
      $course{course_desc} = <>;

      print "Enter college: ";
      $course{college} = <>;

      print "Enter reference: ";
      $course{reference} = <>;

      foreach (keys %course) { chomp $course{$_}; }

      Create_Database(\%course);
   }

   sub Create_Database(%)
   {
      my ($course) = @_;

      my $table_name =
         "$course->{semester}.$course->{course}.$course->{reference}.dat";

      die "Database file already exists" if -e $table_name;

      my $dbh = DBI->connect("dbi:SQLite:$table_name");

      # Create the course table
      #
      $dbh->do("
         CREATE TABLE course (
            semester    VARCHAR(10),
            course      VARCHAR(10),
            course_desc VARCHAR(10),
            college     VARCHAR(20),
            reference   INT
         )
      ");


      # Populate the course table.  FIXME.  Clunky.
      #
		my $sql = "INSERT INTO course VALUES ( "
            . $dbh->quote ( $course->{semester} ) 
            . ', ' . $dbh->quote ( $course->{course} )
            . ', ' . $dbh->quote ( $course->{course_desc} )
            . ', ' . $dbh->quote ( $course->{college} )
            . ', ' . $dbh->quote ( $course->{reference} )
         	. " )";
		printf("%s\n", $sql);
		$dbh.do($sql);
   }

	Create_Course();

gets rid of this error:

# I'm getting an error message that I don't know how to fix:
[...]
#    DBD::SQLite::db do failed: unrecognized token: ":" at Create_Tables.pm line
#    52, <> line 6.

Unfortunately, it still does not work; the table is created but the insert
fails silently. I don't have time to figure it our right now, but I suggest
using the sqlite program to view the database file for debugging purposes
and to try the SQL there to make sure it works because if it subsequently
fails in perl you will know that you have a perl problem rather than an SQL
problem. I hope this helps!

-- 
Henry House
+1 530 753 3361 ext. 13
Please don't send me HTML mail! My mail system usually rejects it.
The unintelligible text that may follow is a digital signature.
See <http://hajhouse.org/pgp> to find out how to use it.
My OpenPGP key: <http://hajhouse.org/hajhouse.asc>.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://ns1.livepenguin.com/pipermail/vox-tech/attachments/20041223/f9ef4d91/attachment.bin


More information about the vox-tech mailing list