posted by 빠담아빠다 2016. 3. 6. 01:37

#!/usr/bin/perl

use strict;
use DBI;

my $dbh = DBI->connect(          
    "dbi:SQLite:dbname=test.db", 
    "",
    "",
    { RaiseError => 1}
) or die $DBI::errstr;

$dbh->do("DROP TABLE IF EXISTS Cars");
$dbh->do("CREATE TABLE Cars(Id INT PRIMARY KEY, Name TEXT, Price INT)");
$dbh->do("INSERT INTO Cars VALUES(1,'Audi',52642)");
$dbh->do("INSERT INTO Cars VALUES(2,'Mercedes',57127)");
$dbh->do("INSERT INTO Cars VALUES(3,'Skoda',9000)");
$dbh->do("INSERT INTO Cars VALUES(4,'Volvo',29000)");
$dbh->do("INSERT INTO Cars VALUES(5,'Bentley',350000)");
$dbh->do("INSERT INTO Cars VALUES(6,'Citroen',21000)");
$dbh->do("INSERT INTO Cars VALUES(7,'Hummer',41400)");
$dbh->do("INSERT INTO Cars VALUES(8,'Volkswagen',21600)");

$dbh->disconnect();



The above script creates a Cars table and inserts 8 rows into the table.

$dbh->do("CREATE TABLE Cars(Id INT PRIMARY KEY, Name TEXT, Price INT)");

The do() method executes the SQL statements. It combines two method calls, prepare() andexecute() into one single call. The do() method is used for non-select statements.

$dbh->do("INSERT INTO Cars VALUES(1,'Audi',52642)");
$dbh->do("INSERT INTO Cars VALUES(2,'Mercedes',57127)");




출처 : http://zetcode.com/db/sqliteperltutorial/connect/


'DB > sqlite' 카테고리의 다른 글

[sqlite] DBI DBD on linux  (0) 2016.03.06
[sqlite] rownum 기능 limit 기능으로 구한다.  (0) 2016.03.06
[sqlite] perl select 쿼리  (0) 2016.03.06
[sqlite] 테이블 구조 보기  (0) 2016.03.06