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:
so I can't help you with your problem, as the SQL itself looks fine:[1046]tom@margo scripts $ perl -we '$harga = 0, $harga2 = kan.$harga;' Unquoted string "kan" may clash with future reserved word at -e line 1 +.
[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
write$sqlstatement2 =qq~ SELECT rowid, NamaBarang FROM barangan WHERE CompanyID = '$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:$sqlstatement2 =qq~ SELECT rowid, NamaBarang FROM barangan WHERE CompanyID = ? 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.my $quotedCID = $dbh->quote($companyid); $sqlstatement2 =qq~ SELECT rowid, NamaBarang FROM barangan WHERE CompanyID = '$quotedCID' ORDER by rowid ASC ~;
regards,
tomte
An intellectual is someone whose mind watches itself.
-- Albert Camus
|
|---|