Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Converting from MySQL to SQLite

by Tomte (Priest)
on Jul 29, 2004 at 08:58 UTC ( [id://378325]=note: print w/replies, xml ) Need Help??


in reply to Converting from MySQL to SQLite

The code and error/problem-information you provided are insufficient to help you. to me at least $harga = 0, $harga2 = kan.$harga; doesn't make any sense, and perl doesn't like it that much either:

[1046]tom@margo scripts $ perl -we '$harga = 0, $harga2 = kan.$harga;' Unquoted string "kan" may clash with future reserved word at -e line 1 +.
so I can't help you with your problem, as the SQL itself looks fine:
[1052]tom@margo scripts $ sqlite /home/tom/sqlitetest.sldb SQLite version 2.8.14 Enter ".help" for instructions sqlite> create table barangan (NamaBarang text NOT NULL, CompanyID int +(9)); sqlite> insert into barangan (NamaBarang, CompanyID) VALUES ('hello', +1); sqlite> insert into barangan (NamaBarang, CompanyID) VALUES ('hello2', + 2); sqlite> SELECT rowid, NamaBarang ...> FROM barangan ...> WHERE CompanyID = '2' ...> ORDER by rowid ASC ; 2|hello2

2 more notes to make your job easier in the future:

1. Always check for the return-value of anything that can produce errors and indicates errors via the return-value, including $dbh->prepare(), as ysth already said.

2. Don't interpolate data into SQL when not technically necessary (e.g. dynamically inserting the tablename):
instead of

$sqlstatement2 =qq~ SELECT rowid, NamaBarang FROM barangan WHERE CompanyID = '$companyid' ORDER by rowid ASC ~;
write
$sqlstatement2 =qq~ SELECT rowid, NamaBarang FROM barangan WHERE CompanyID = ? ORDER by rowid ASC ~;
and give $companyid as a parameter to $sth2->excute() (as in $sth2->excute($companyid)), or use $dbh->quote() before you interpolate:
my $quotedCID = $dbh->quote($companyid); $sqlstatement2 =qq~ SELECT rowid, NamaBarang FROM barangan WHERE CompanyID = '$quotedCID' ORDER by rowid ASC ~;
To adopt the practice of using placeholders if you use SQL in any language you programm in, greatly increases the quality and security of your code.

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://378325]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-23 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found