l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2004 Dec 23 21:17

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] sqlite + perl - wierd unrecognized token error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



On Thu 23 Dec 04,  1:09 PM, Henry House <hajhouse@houseag.com> said:
> På torsdag, 23 december 2004, skrev Peter Jay Salzman:
> > On Thu 23 Dec 04, 11:15 AM, Shwaine <shwaine@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.
 

Yeah.  Actually, I used sprintf which seems tailor made for exactly this
purpose:

   $_ = sprintf("%s (%s, %s, %s, %s, %s)",
            "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} )
        );

> 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!

Strange -- it seems to work for me:


   p@satan$ ./driver.pl


   Grade Utility
   +-=-=-=-=-=-=-=-=-=-+
   1. Create a new class
   2. Add a student
   3. Modify a record
   4. Print_Record()
   5. Dump A Course Table
   q. Quit
   +-=-=-=-=-=-=-=-=-=-+

   Choice: 5
   Enter database name: 20051.Phy101.1234.dat
   semester:    20051
   course:      Phy101
   course_desc: College Physics I
   college:     MCCC
   reference:   1234


Damn.  I think I'm really starting to understand multi-file perl programs,
and how to write packages and modules.  Scary -- I never thought I'd grok
that stuff.

Now I just need to conquer grokking Perl's object oriented stuff.   It takes
so much darn *effort* just to write a stupid class.  I hope Perl6 simplifies
the process.  Seems like people have been talking about Perl6 for well over
2 years now.  I can't wait to write...

   if ( condition )
      do_something;

without the stupid Freedom-braces!!!    ;-)

Pete

-- 
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's "Fearful Symmetry"

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.