=encoding euc-jp
=pod
=head1 NAME
=begin original
DBD::SQLite - Self-contained RDBMS in a DBI Driver
=end original
DBD::SQLite - DBI ¥É¥é¥¤¥Ð¤Ç¤Î¼«¸Ê´°·ë·¿(Self Contained)RDBMS
(ÌõÃí: (TBR)¤¬¤Ä¤¤¤Æ¤¤¤ëÃÊÍî¤Ï¡Ö¤ß¤ó¤Ê¤Î¼«Æ°ËÝÌõ¡÷TexTra¡×¤Ë¤è¤ë
µ¡³£ËÝÌõ¤Ç¤¹¡£)
=head1 SYNOPSIS
use DBI;
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","");
=head1 DESCRIPTION
=begin original
SQLite is a public domain file-based relational database engine that
you can find at L.
=end original
SQLite ¤Ï¡¢¥Ñ¥Ö¥ê¥Ã¥¯¥É¥á¥¤¥ó¤Î¥Õ¥¡¥¤¥ë¥Ù¡¼¥¹¤Î´Ø·¸¥Ç¡¼¥¿¥Ù¡¼¥¹¥¨¥ó¥¸¥ó¤Ç¡¢
¤³¤Î URL ¤Ç¸«¤Ä¤±¤ë¤³¤È¤¬½ÐÍè¤Þ¤¹: L
=begin original
B is a Perl DBI driver for SQLite, that includes
the entire thing in the distribution.
So in order to get a fast transaction capable RDBMS working for your
perl project you simply have to install this module, and B
else.
=end original
B ¤Ï¡¢Á´¤Æ¤Î¤â¤Î¤ò¥Ç¥£¥¹¥È¥ê¥Ó¥å¡¼¥·¥ç¥ó¤Ë´Þ¤ó¤Ç¤¤¤ë¡¢
SQLite ¤Î¤¿¤á¤Î Perl DBI ¥É¥é¥¤¥Ð¤Ç¤¹¡£
¤½¤Î¤¿¤á¤¢¤Ê¤¿¤Î perl ¥×¥í¥¸¥§¥¯¥È¤Î¤¿¤á¤Ë¡¢¹â®¤Î
¥È¥é¥ó¥¶¥¯¥·¥ç¥ó²Äǽ¤Ê RDBMS ¤òÆ°¤«¤¹¤¿¤á¤Ë¤Ï¡¢Ã±¤Ë¤³¤Î¥â¥¸¥å¡¼¥ë¤ò
¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¤³¤È¤À¤±¤¬É¬ÍפǤ¹¡£
¾¤Ë¤Ï B<²¿¤â¤¢¤ê¤Þ¤»¤ó>¡£
=begin original
SQLite supports the following features:
=end original
SQLite¤Ï°Ê²¼¤Îµ¡Ç½¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹:
=over 4
=item Implements a large subset of SQL92
(SQL92 ¤Î¥µ¥Ö¥»¥Ã¥È¤Î¿¤¯¤ò¼ÂÁõ)
=begin original
See L for details.
=end original
¾ÜºÙ¤Ï L ¤ò¤´Í÷¤¯¤À¤µ¤¤¡£
=item A complete DB in a single disk file
(ñ°ì¤Î¥Ç¥£¥¹¥¯¥Õ¥¡¥¤¥ë¤Ç¤Î´°Á´¤Ê DB)
=begin original
Everything for your database is stored in a single disk file, making it
easier to move things around than with L.
=end original
¤¢¤Ê¤¿¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¤¿¤á¤ÎÁ´¤Æ¤Ï°ì¤Ä¤Î¥Ç¥£¥¹¥¯¥Õ¥¡¥¤¥ë¤Ë³ÊǼ¤µ¤ì¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê L ¤è¤ê¤â´Êñ¤ËÆ°¤«¤¹¤³¤È¤¬½ÐÍè¤Þ¤¹¡£
=item Atomic commit and rollback
(¥¢¥È¥ß¥Ã¥¯¤Ê¥³¥ß¥Ã¥È¤È¥í¡¼¥ë¥Ð¥Ã¥¯)
=begin original
Yes, B is small and light, but it supports full transactions!
=end original
¤½¤¦¤Ç¤¹¡¢B ¤Ï¾®¤µ¤¯¡¢·ÚÎ̤Ǥ¹¤¬¡¢
´°Á´¤Ê¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò¥µ¥Ý¡¼¥È¤·¤Þ¤¹¡£
=item Extensible
=begin original
User-defined aggregate or regular functions can be registered with the
SQL parser.
=end original
¥æ¡¼¥¶¡¼ÄêµÁ¤Î½¸·×´Ø¿ô¤Þ¤¿¤Ïɸ½à´Ø¿ô¤Ï¡¢SQL¥Ñ¡¼¥µ¡¼¤ËÅÐÏ¿¤Ç¤¤Þ¤¹¡£
(TBR)
=back
=begin original
There's lots more to it, so please refer to the docs on the SQLite web
page, listed above, for SQL details. Also refer to L for details
on how to use DBI itself. The API works like every DBI module does.
However, currently many statement attributes are not implemented or
are limited by the typeless nature of the SQLite database.
=end original
¤³¤ì°Ê¾å¤Î¤â¤Î¤¬¤¢¤ê¤Þ¤¹¤¬¡¢
¤½¤Î¤¿¤á SQL ¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢¾å¤Ëµó¤²¤¿ SQLite web ¥Ú¡¼¥¸¤Ë¤¢¤ë
¥É¥¥å¥á¥ó¥È¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
¤Þ¤¿¡¢DBI ¼«¿È¤Î»È¤¤Êý¤Ë´Ø¤¹¤ë¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï
L ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
API ¤Ï¤Û¤Ü³Æ DBI ¥â¥¸¥å¡¼¥ë¤¬¤¹¤ë¤è¤¦¤Ëµ¡Ç½¤·¤Þ¤¹¡£
¤·¤«¤·¡¢¸½ºß¤Î½ê¿¤¯¤Îʸ°À¤Ï¡¢Ì¤¼ÂÁõ¤Ç¤¢¤Ã¤¿¤ê¡¢SQLite ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤Ï
·¿¤¬¤Ê¤¤¤È¤¤¤¦À¼Á¤«¤éÀ©¸Â¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
=head1 NOTABLE DIFFERENCES FROM OTHER DRIVERS
=head2 Database Name Is A File Name
=begin original
SQLite creates a file per a database. You should pass the C of
the database file (with or without a parent directory) in the DBI
connection string (as a database C):
=end original
SQLite¤Ç¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤´¤È¤Ë¥Õ¥¡¥¤¥ë¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£
¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë¤ÎC(¿Æ¥Ç¥£¥ì¥¯¥È¥ê¤ÎÍ̵¤Ë¤«¤«¤ï¤é¤º)¤òDBIÀܳʸ»úÎó¤Ë(¥Ç¡¼¥¿¥Ù¡¼¥¹C¤È¤·¤Æ)ÅϤ¹É¬Íפ¬¤¢¤ê¤Þ¤¹:
(TBR)
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","");
=begin original
The file is opened in read/write mode, and will be created if
it does not exist yet.
=end original
¥Õ¥¡¥¤¥ë¤ÏÆɤ߼è¤ê/½ñ¤¹þ¤ß¥â¡¼¥É¤Ç³«¤«¤ì¡¢¤Þ¤À¸ºß¤·¤Ê¤¤¾ì¹ç¤ÏºîÀ®¤µ¤ì¤Þ¤¹¡£
(TBR)
=begin original
Although the database is stored in a single file, the directory
containing the database file must be writable by SQLite because the
library will create several temporary files there.
=end original
¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ï1¤Ä¤Î¥Õ¥¡¥¤¥ë¤Ë³ÊǼ¤µ¤ì¤Þ¤¹¤¬¡¢¥é¥¤¥Ö¥é¥ê¤Ë¤è¤Ã¤ÆÊ£¿ô¤Î°ì»þ¥Õ¥¡¥¤¥ë¤¬ºîÀ®¤µ¤ì¤ë¤¿¤á¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë¤ò´Þ¤à¥Ç¥£¥ì¥¯¥È¥ê¤ÏSQLite¤Ë¤è¤Ã¤Æ½ñ¤¹þ¤ß²Äǽ¤Ç¤¢¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
(TBR)
=begin original
If the filename C<$dbfile> is ":memory:", then a private, temporary
in-memory database is created for the connection. This in-memory
database will vanish when the database connection is closed.
It is handy for your library tests.
=end original
¥Õ¥¡¥¤¥ë̾C<$dbfile>¤¬":memory:"¤Î¾ì¹ç¡¢ÀܳÍѤ˥ץ饤¥Ù¡¼¥È¤Ê°ì»þŪ¤Ê¥á¥â¥ê¡¼Æâ¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£
¤³¤Î¥á¥â¥ê¡¼Æâ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹Àܳ¤¬ÊĤ¸¤é¤ì¤ë¤È¾Ãµî¤µ¤ì¤Þ¤¹¡£
¤³¤ì¤Ï¥é¥¤¥Ö¥é¥ê¤Î¥Æ¥¹¥È¤ËÊØÍø¤Ç¤¹¡£
(TBR)
=begin original
Note that future versions of SQLite might make use of additional
special filenames that begin with the ":" character. It is recommended
that when a database filename actually does begin with a ":" character
you should prefix the filename with a pathname such as "./" to avoid
ambiguity.
=end original
SQLite¤Î¾Íè¤Î¥Ð¡¼¥¸¥ç¥ó¤Ç¤Ï¡¢¡Ö:¡×ʸ»ú¤Ç»Ï¤Þ¤ëÄɲäÎÆüì¤Ê¥Õ¥¡¥¤¥ë̾¤¬»ÈÍѤµ¤ì¤ë²ÄǽÀ¤¬¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë̾¤¬¼ÂºÝ¤Ë¡Ö:¡×ʸ»ú¤Ç»Ï¤Þ¤ë¾ì¹ç¤Ï¡¢¤¢¤¤¤Þ¤¤¤µ¤òÈò¤±¤ë¤¿¤á¤Ë¡¢¥Õ¥¡¥¤¥ë̾¤ÎÁ°¤Ë¡Ö./¡×¤Ê¤É¤Î¥Ñ¥¹Ì¾¤òÉÕ¤±¤ë¤³¤È¤ò¤ªÁ¦¤á¤·¤Þ¤¹¡£
(TBR)
=begin original
If the filename C<$dbfile> is an empty string, then a private,
temporary on-disk database will be created. This private database will
be automatically deleted as soon as the database connection is closed.
=end original
¥Õ¥¡¥¤¥ë̾C<$dbfile>¤¬¶õ¤Îʸ»úÎó¤Î¾ì¹ç¡¢¥×¥é¥¤¥Ù¡¼¥È¤Ê°ì»þŪ¤Ê¥ª¥ó¥Ç¥£¥¹¥¯¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬ºîÀ®¤µ¤ì¤Þ¤¹¡£
¤³¤Î¥×¥é¥¤¥Ù¡¼¥È¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹Àܳ¤¬ÊĤ¸¤é¤ì¤ë¤È¤¹¤°¤Ë¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¡£
(TBR)
=head2 Accessing A Database With Other Tools
=begin original
To access the database from the command line, try using C
which comes with the L module. Just type:
=end original
¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤é¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤Ë¤Ï¡¢L ¥â¥¸¥å¡¼¥ë¤Ë
Æþ¤Ã¤Æ¤¤¤ë C ¤ò»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
°Ê²¼¤Î¤è¤¦¤Ë¥¿¥¤¥×¤·¤Æ:
dbish dbi:SQLite:foo.db
=begin original
On the command line to access the file F.
=end original
¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ç¥Õ¥¡¥¤¥ë F ¤Ë¥¢¥¯¥»¥¹¤·¤Þ¤¹¡£
=begin original
Alternatively you can install SQLite from the link above without
conflicting with B and use the supplied C
command line tool.
=end original
Âå¤ï¤ê¤È¤·¤Æ¡¢¾åµ¤Î¥ê¥ó¥¯¤«¤é B ¤Ë¤Ö¤Ä¤«¤ë¤³¤È¤Ê¤¯ SQLite ¤ò
¥¤¥ó¥¹¥È¡¼¥ë¤·¡¢Ä󶡤µ¤ì¤ë C ¥³¥Þ¥ó¥É¥é¥¤¥ó¥Ä¡¼¥ë¤ò»È¤¦¤³¤È¤¬
½ÐÍè¤Þ¤¹¡£
=head2 Blobs
=begin original
As of version 1.11, blobs should "just work" in SQLite as text columns.
However this will cause the data to be treated as a string, so SQL
statements such as length(x) will return the length of the column as a NUL
terminated string, rather than the size of the blob in bytes. In order to
store natively as a BLOB use the following code:
=end original
¥Ð¡¼¥¸¥ç¥ó1.11¤Ç¤Ï¡¢blob¤ÏSQLite¤Ç¤Ï¥Æ¥¥¹¥ÈÎó¤È¤·¤Æ¡ÖÆ°ºî¤¹¤ë¡×¤Ï¤º¤Ç¤¹¡£
¤¿¤À¤·¡¢¤³¤ì¤Ë¤è¤ê¥Ç¡¼¥¿¤¬Ê¸»úÎó¤È¤·¤Æ°·¤ï¤ì¤ë¤¿¤á¡¢length(x)¤Ê¤É¤ÎSQLʸ¤Ï¡¢¥Ð¥¤¥Èñ°Ì¤Îblob¤Î¥µ¥¤¥º¤Ç¤Ï¤Ê¤¯¡¢NUL¤Ç½ªÎ»¤¹¤ëʸ»úÎó¤È¤·¤ÆÎó¤ÎŤµ¤òÊÖ¤·¤Þ¤¹¡£
BLOB¤È¤·¤Æ¥Í¥¤¥Æ¥£¥Ö¤Ë³ÊǼ¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î¥³¡¼¥É¤ò»ÈÍѤ·¤Þ¤¹:
(TBR)
use DBI qw(:sql_types);
my $dbh = DBI->connect("dbi:SQLite:dbfile","","");
my $blob = `cat foo.jpg`;
my $sth = $dbh->prepare("INSERT INTO mytable VALUES (1, ?)");
$sth->bind_param(1, $blob, SQL_BLOB);
$sth->execute();
=begin original
And then retrieval just works:
=end original
¤½¤·¤Æ¸¡º÷¤Ïµ¡Ç½¤·¤Þ¤¹
(TBR)
$sth = $dbh->prepare("SELECT * FROM mytable WHERE id = 1");
$sth->execute();
my $row = $sth->fetch;
my $blobo = $row->[1];
# now $blobo == $blob
=head2 Functions And Bind Parameters
=begin original
As of this writing, a SQL that compares a return value of a function
with a numeric bind value like this doesn't work as you might expect.
=end original
¤³¤Îµ»ö¤ò½ñ¤¤¤Æ¤¤¤ë»þÅÀ¤Ç¤Ï¡¢´Ø¿ô¤ÎÌá¤êÃͤò¿ôÃͥХ¤¥ó¥ÉÃͤÈÈæ³Ó¤¹¤ëSQL¤Ï¡¢´üÂÔ¤·¤¿¤è¤¦¤Ë¤ÏÆ°ºî¤·¤Þ¤»¤ó¡£
(TBR)
my $sth = $dbh->prepare(q{
SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?;
});
$sth->execute(5);
=begin original
This is because DBD::SQLite assumes that all the bind values are text
(and should be quoted) by default. Thus the above statement becomes
like this while executing:
=end original
¤³¤ì¤Ï¡¢DBD::SQLite¤Ç¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¤¹¤Ù¤Æ¤Î¥Ð¥¤¥ó¥ÉÃͤ¬¥Æ¥¥¹¥È¤Ç¤¢¤ë(°úÍÑÉä¤Ç°Ï¤àɬÍפ¬¤¢¤ë)¤ÈÁÛÄꤵ¤ì¤Æ¤¤¤ë¤¿¤á¤Ç¤¹¡£
¤½¤Î¤¿¤á¡¢¾åµ¤Î¥¹¥Æ¡¼¥È¥á¥ó¥È¤ò¼Â¹Ô¤¹¤ë¤È¡¢¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
(TBR)
SELECT bar FROM foo GROUP BY bar HAVING count(*) > "5";
=begin original
There are two workarounds for this.
=end original
¤³¤ì¤Ë¤Ï¡¢2¤Ä¤Î²óÈòºö¤¬¤¢¤ê¤Þ¤¹¡£
(TBR)
=over 4
=item Use bind_param() explicitly
=begin original
As shown above in the C section, you can always use
C to tell the type of a bind value.
=end original
¾åµ¤ÎC¥»¥¯¥·¥ç¥ó¤Ç¼¨¤·¤¿¤è¤¦¤Ë¡¢C¤ò»ÈÍѤ·¤Æ¥Ð¥¤¥ó¥ÉÃͤΥ¿¥¤¥×¤ò»ØÄê¤Ç¤¤Þ¤¹¡£
(TBR)
use DBI qw(:sql_types); # Don't forget this
my $sth = $dbh->prepare(q{
SELECT bar FROM foo GROUP BY bar HAVING count(*) > ?;
});
$sth->bind_param(1, 5, SQL_INTEGER);
$sth->execute();
=item Add zero to make it a number
=begin original
This is somewhat weird, but works anyway.
=end original
¤³¤ì¤Ï¾¯¤·´ñ̯¤Ç¤¹¤¬¡¢¤È¤Ë¤«¤¯µ¡Ç½¤·¤Þ¤¹¡£
(TBR)
my $sth = $dbh->prepare(q{
SELECT bar FROM foo GROUP BY bar HAVING count(*) > (? + 0);
});
$sth->execute(5);
=back
=head2 Foreign Keys
=begin original
B
=end original
B<³Ð¸ç¤·¤í!¥ª¥ª¥«¥ßÀܶá!>
(TBR)
=begin original
SQLite has started supporting foreign key constraints since 3.6.19
(released on Oct 14, 2009; bundled with DBD::SQLite 1.26_05).
To be exact, SQLite has long been able to parse a schema with foreign
keys, but the constraints has not been enforced. Now you can issue
a pragma actually to enable this feature and enforce the constraints.
=end original
SQLite¤Ï3.6.19(2009ǯ10·î14Æü¤Ë¥ê¥ê¡¼¥¹¤µ¤ì¡¢DBD::SQLite 1.26_05¤Ë¥Ð¥ó¥É¥ë¤µ¤ì¤Æ¤¤¤ë)¤«¤é³°Éô¥¡¼À©Ìó¤Î¥µ¥Ý¡¼¥È¤ò³«»Ï¤·¤¿¡£
Àµ³Î¤Ë¤Ï¡¢SQLite¤ÏŤ¤´Ö³°Éô¥¡¼¤ò»ÈÍѤ·¤Æ¥¹¥¡¼¥Þ¤ò²òÀϤ¹¤ë¤³¤È¤¬¤Ç¤¤¿¤¬¡¢À©Ìó¤Ï¶¯À©¤µ¤ì¤Æ¤¤¤Ê¤«¤Ã¤¿¡£
¤³¤ì¤Ç¡¢¥×¥é¥°¥Þ¤ò¼ÂºÝ¤Ëȯ¹Ô¤·¤Æ¤³¤Îµ¡Ç½¤ò͸ú¤Ë¤·¡¢À©Ìó¤ò¶¯À©¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
(TBR)
=begin original
To do this, issue the following pragma (see below), preferably as
soon as you connect to a database and you're not in a transaction:
=end original
¤³¤ì¤ò¹Ô¤¦¤Ë¤Ï¡¢¼¡¤Î¥×¥é¥°¥Þ(²¼µ»²¾È)¤òȯ¹Ô¤·¤Þ¤¹¡£
¥È¥é¥ó¥¶¥¯¥·¥ç¥óÃæ¤Ç¤Ï¤Ê¤¯¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤ËÀܳ¤·¤¿Ä¾¸å¤Ëȯ¹Ô¤¹¤ë¤³¤È¤ò¤ª´«¤á¤·¤Þ¤¹¡£
(TBR)
$dbh->do("PRAGMA foreign_keys = ON");
=begin original
And you can explicitly disable the feature whenever you like by
turning the pragma off:
=end original
¤Þ¤¿¡¢¥×¥é¥°¥Þ¤ò¥ª¥Õ¤Ë¤¹¤ë¤³¤È¤Ç¡¢¤¤¤Ä¤Ç¤â¤³¤Îµ¡Ç½¤òÌÀ¼¨Åª¤Ë̵¸ú¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
(TBR)
$dbh->do("PRAGMA foreign_keys = OFF");
=begin original
As of this writing, this feature is disabled by default by the
sqlite team, and by us, to secure backward compatibility, as
this feature may break your applications, and actually broke
some for us. If you have used a schema with foreign key constraints
but haven't cared them much and supposed they're always ignored for
SQLite, be prepared, and B. It is very likely that the sqlite
team will turn it default-on in the future, and we plan to do it
NO LATER THAN they do so.
=end original
¤³¤Îµ»ö¤ò½ñ¤¤¤Æ¤¤¤ë»þÅÀ¤Ç¤Ï¡¢SQLite¥Á¡¼¥à¤È»ä¤¿¤Á¤Ï¡¢¸åÊý¸ß´¹À¤ò³ÎÊݤ¹¤ë¤¿¤á¤Ë¡¢¤³¤Îµ¡Ç½¤ò¥Ç¥Õ¥©¥ë¥È¤Ç̵¸ú¤Ë¤·¤Æ¤¤¤Þ¤¹¡£
¤³¤ì¤Ï¡¢¤³¤Îµ¡Ç½¤¬¤¢¤Ê¤¿¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤òÇ˲õ¤¹¤ë²ÄǽÀ¤¬¤¢¤ê¡¢¼ÂºÝ¤Ë»ä¤¿¤Á¤Î¤¿¤á¤Ë¤¤¤¯¤Ä¤«Ç˲õ¤·¤¿¤«¤é¤Ç¤¹¡£
³°Éô¥¡¼¤ÎÀ©Ìó¤ò»ý¤Ä¥¹¥¡¼¥Þ¤ò»ÈÍѤ·¤¿¤³¤È¤¬¤¢¤Ã¤Æ¤â¡¢¤½¤ì¤ò¤¢¤Þ¤êµ¤¤Ë¤·¤Æ¤ª¤é¤º¡¢SQLite¤Ç¤Ï¾ï¤Ë̵»ë¤µ¤ì¤ë¤ÈÁÛÄꤷ¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢½àÈ÷¤·¤Æ¡¢B<³°Éô¥¡¼¤Î¥µ¥Ý¡¼¥È¤¬¥Ç¥Õ¥©¥ë¥È¤Ç͸ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ç¤â¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬Æ°ºî¤·Â³¤±¤ë¤³¤È¤òÊݾڤ¹¤ë¤¿¤á¤Ë¡¢¹ÈϤʥƥ¹¥È¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤>¡£
SQLite¥Á¡¼¥à¤¬¾ÍèŪ¤Ë¥Ç¥Õ¥©¥ë¥È¤Ç¥ª¥ó¤Ë¤¹¤ë²ÄǽÀ¤ÏÈó¾ï¤Ë¹â¤¯¡¢»ä¤¿¤Á¤ÏÈà¤é¤¬¤½¤¦¤¹¤ë¤Þ¤Ç¤Ë¤½¤ì¤ò¹Ô¤¦Í½Äê¤Ç¤¹¡£
(TBR)
=begin original
See L for details.
=end original
¾ÜºÙ¤ÏL¤ò¤´Í÷¤¯¤À¤µ¤¤¡£
(TBR)
=head2 Pragma
=begin original
SQLite has a set of "Pragma"s to modifiy its operation or to query
for its internal data. These are specific to SQLite and are not
likely to work with other DBD libraries, but you may find some of
these are quite useful. DBD::SQLite actually sets some (like
C) for you when you connect to a database.
See L for details.
=end original
SQLite¤Ë¤Ï¡¢Áàºî¤òÊѹ¹¤·¤¿¤ê¡¢ÆâÉô¥Ç¡¼¥¿¤ò¾È²ñ¤·¤¿¤ê¤¹¤ë¤¿¤á¤Î¡Ö¥×¥é¥°¥Þ¡×¤Î¥»¥Ã¥È¤¬¤¢¤ê¤Þ¤¹¡£
¤³¤ì¤é¤ÏSQLite¤Ë¸ÇͤΤâ¤Î¤Ç¡¢Â¾¤ÎDBD¥é¥¤¥Ö¥é¥ê¤Ç¤ÏÆ°ºî¤·¤Ê¤¤¤è¤¦¤Ç¤¹¤¬¡¢¤³¤ì¤é¤Î¤¤¤¯¤Ä¤«¤ÏÈó¾ï¤ËÊØÍø¤Ç¤¹¡£
DBD::SQLite¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤ËÀܳ¤¹¤ë¤È¤¤Ë¡¢¼ÂºÝ¤Ë¤¤¤¯¤Ä¤«(C¤Ê¤É)¤òÀßÄꤷ¤Þ¤¹¡£
¾ÜºÙ¤ÏL¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
(TBR)
=head2 Transactions
=begin original
DBI/DBD::SQLite's transactions may be a bit confusing. They behave
differently according to the status of the C flag:
=end original
DBI/DBD::SQLite¤Î¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤Ï¾¯¤·º®Í𤷤Ƥ¤¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£
¤³¤ì¤é¤Ï¡¢C¥Õ¥é¥°¤Î¥¹¥Æ¡¼¥¿¥¹¤Ë±þ¤¸¤ÆÆ°ºî¤¬°Û¤Ê¤ê¤Þ¤¹¡£
(TBR)
=over 4
=item When the AutoCommit flag is on
=begin original
You're supposed to always use the auto-commit mode, except you
explicitly begin a transaction, and when the transaction ended,
you're supposed to go back to the auto-commit mode. To begin a
transaction, call C method, or issue a C
statement. To end it, call C methods, or issue
the corresponding statements.
=end original
¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤òÌÀ¼¨Åª¤Ë³«»Ï¤·¡¢¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤¬½ªÎ»¤·¤¿¤È¤¤Ë¼«Æ°¥³¥ß¥Ã¥È¥â¡¼¥É¤ËÌá¤ë¾ì¹ç¤ò½ü¤¡¢¾ï¤Ë¼«Æ°¥³¥ß¥Ã¥È¥â¡¼¥É¤ò»ÈÍѤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò³«»Ï¤¹¤ë¤Ë¤Ï¡¢C¥á¥½¥Ã¥É¤ò¥³¡¼¥ë¤¹¤ë¤«¡¢Cʸ¤òȯ¹Ô¤·¤Þ¤¹¡£
¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò½ªÎ»¤¹¤ë¤Ë¤Ï¡¢C¥á¥½¥Ã¥É¤ò¥³¡¼¥ë¤¹¤ë¤«¡¢Âбþ¤¹¤ëʸ¤òȯ¹Ô¤·¤Þ¤¹¡£
(TBR)
$dbh->{AutoCommit} = 1;
$dbh->begin_work; # or $dbh->do('BEGIN TRANSACTION');
# $dbh->{AutoCommit} is turned off temporarily during a transaction;
$dbh->commit; # or $dbh->do('COMMIT');
# $dbh->{AutoCommit} is turned on again;
=item When the AutoCommit flag is off
=begin original
You're supposed to always use the transactinal mode, until you
explicitly turn on the AutoCommit flag. You can explicitly issue
a C statement (only when an actual transaction has not
begun yet) but you're not allowed to call C method
(if you don't issue a C, it will be issued internally).
You can commit or roll it back freely. Another transaction will
automatically begins if you execute another statement.
=end original
AutoCommit¥Õ¥é¥°¤òÌÀ¼¨Åª¤Ë¥ª¥ó¤Ë¤¹¤ë¤Þ¤Ç¤Ï¡¢¾ï¤Ëtransactinal¥â¡¼¥É¤ò»ÈÍѤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
Cʸ¤ÏÌÀ¼¨Åª¤Ëȯ¹Ô¤Ç¤¤Þ¤¹¤¬(¼ÂºÝ¤Î¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤¬¤Þ¤À³«»Ï¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Î¤ß)¡¢C¥á¥½¥Ã¥É¤ò¥³¡¼¥ë¤¹¤ë¤³¤È¤Ï¤Ç¤¤Þ¤»¤ó(C¤òȯ¹Ô¤·¤Ê¤¤¾ì¹ç¤Ï¡¢ÆâÉôŪ¤Ëȯ¹Ô¤µ¤ì¤Þ¤¹)¡£
¥³¥ß¥Ã¥È¤Þ¤¿¤Ï¥í¡¼¥ë¥Ð¥Ã¥¯¤Ï¼«Í³¤Ë¼Â¹Ô¤Ç¤¤Þ¤¹¡£
Ê̤Îʸ¤ò¼Â¹Ô¤¹¤ë¤È¡¢Ê̤Υȥé¥ó¥¶¥¯¥·¥ç¥ó¤¬¼«Æ°Åª¤Ë³«»Ï¤µ¤ì¤Þ¤¹¡£
(TBR)
$dbh->{AutoCommit} = 0;
# $dbh->do('BEGIN TRANSACTION') is not necessary, but possible
...
$dbh->commit; # or $dbh->do('COMMIT');
# $dbh->{AutoCommit} stays intact;
$dbh->{AutoCommit} = 1; # ends the transactional mode
=back
=begin original
This C mode is independent from the autocommit mode
of the internal SQLite library, which always begins by a C
statement, and ends by a C or a .
=end original
¤³¤ÎC¥â¡¼¥É¤Ï¡¢ÆâÉôSQLite¥é¥¤¥Ö¥é¥ê¤Î¥ª¡¼¥È¥³¥ß¥Ã¥È¥â¡¼¥É¤«¤éÆÈΩ¤·¤Æ¤¤¤Þ¤¹¡£
¥ª¡¼¥È¥³¥ß¥Ã¥È¥â¡¼¥É¤Ï¾ï¤ËCʸ¤Ç»Ï¤Þ¤ê¡¢C¤Þ¤¿¤Ï¤Ç½ª¤ï¤ê¤Þ¤¹¡£
(TBR)
=head2 Performance
(Àǽ)
=begin original
SQLite is fast, very fast. Matt processed my 72MB log file with it,
inserting the data (400,000+ rows) by using transactions and only
committing every 1000 rows (otherwise the insertion is quite slow),
and then performing queries on the data.
=end original
SQLite ¤Ï¹â®¤Ç¤¹¡¢Èó¾ï¤Ë¹â®¤Ç¤¹¡£
Matt ¤Ï¡¢»ä¤Î 72MB ¤Î¥í¥°¥Õ¥¡¥¤¥ë¤ò¤½¤ì¤Ç½èÍý¤·¤Þ¤·¤¿¡£
ñ½ã¤Ë 1000 ¹ÔËè¤Ë¥³¥ß¥Ã¥È¤·¤Ê¤¬¤é(¤½¤¦¤Ç¤Ê¤±¤ì¤ÐÁÞÆþ¤¬¤È¤Æ¤âÃÙ¤¯¤Ê¤ê¤Þ¤¹)¡¢
¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò»È¤Ã¤Æ¥Ç¡¼¥¿(400,000 °Ê¾å¤Î¹Ô)¤òÁÞÆþ¤·¡¢
¤½¤Î¥Ç¡¼¥¿¤ËÌ䤤¹ç¤ï¤»¤ò¼Â¹Ô¤·¤Þ¤·¤¿¡£
=begin original
Queries like count(*) and avg(bytes) took fractions of a second to
return, but what surprised him most of all was:
=end original
count(*) ¤È avg(bytes) ¤Î¤è¤¦¤ÊÌ䤤¹ç¤ï¤»¤Ï¡¢¤¿¤Á¤Þ¤ÁÊ֤äƤ¤Þ¤·¤¿¡£
¤·¤«¤·²¿¤è¤êÈब¶Ã¤¤¤¿¤³¤È¤Ï:
SELECT url, count(*) as count
FROM access_log
GROUP BY url
ORDER BY count desc
LIMIT 20
=begin original
To discover the top 20 hit URLs on the site (L),
and it returned within 2 seconds. He was seriously considering
switching his log analysis code to use this little speed demon!
=end original
¥µ¥¤¥È (L) ¤Ë¥Ò¥Ã¥È¤· ¤¿URL ¤Î¥È¥Ã¥× 20 ¤ò
¸«¤Ä¤±¤ë¤³¤È¤Ç¤·¤¿¡£
¤³¤ì¤ò 2 ÉðÊÆâ¤ÇÊÖ¤·¤Þ¤·¤¿¡£
Èà¤Ï¿¿·õ¤Ë»ä¤Î¥í¥°²òÀÏ¥³¡¼¥É¤ò¡¢¤³¤Î¾®¤µ¤Ê
¥¹¥Ô¡¼¥É¤ÎËâʪ¤ò»È¤¦¤è¤¦¤ËÊѹ¹¤¹¤ë¤³¤È¤ò¹Í¤¨¤Æ¤¤¤Þ¤¹¡£
=begin original
Oh yeah, and that was with no indexes on the table, on a 400MHz PIII.
=end original
¤½¤¦¤½¤¦¡¢¥Æ¡¼¥Ö¥ë¤Ë¤Ï¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò¤Ä¤±¤Æ¤¤¤Þ¤»¤ó¤·¡¢400MHz PIII ¤Î¾å¤Ç¤¹¡£
=begin original
For best performance be sure to tune your hdparm settings if you
are using linux. Also you might want to set:
=end original
¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤òºÇ¹â¤Ë¤¹¤ë¤¿¤á¤Ë¤Ï¡¢linux ¤ò»È¤Ã¤Æ¤¤¤ë¤Î¤Ç¤¢¤ì¤Ð¡¢
hdparam ¤Î¥»¥Ã¥Æ¥£¥ó¥°¤ò³Î¼Â¤Ë¥Á¥å¡¼¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£
¤Þ¤¿¤³¤Î¤è¤¦¤ËÀßÄꤷ¤¿¤¤¤«¤â¤·¤ì¤Þ¤»¤ó:
PRAGMA default_synchronous = OFF
=begin original
Which will prevent sqlite from doing fsync's when writing (which
slows down non-transactional writes significantly) at the expense
of some peace of mind. Also try playing with the cache_size pragma.
=end original
¤³¤ì¤Ï¡¢¤¤¤¯¤é¤«¤Î¿´ÇÛ¤òµ¾À·¤Ë¤¹¤ë¤³¤È¤Ç¡¢¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò»È¤ï¤Ê¤¤
½ñ¹þ¤ß¤òÈó¾ï¤ËÃÙ¤¯¤·¤Æ¤·¤Þ¤¦ fsync ¤¬¤¹¤ë¤³¤È¤«¤é¡¢sqlite ¤òÊݸ¤Þ¤¹¡£
cache_size pragma ¤Ç¤â³Ú¤·¤ó¤Ç¤ß¤ë¤è¤¦¤Ë¤·¤Æ¤¯¤À¤µ¤¤¡£
=begin original
The memory usage of SQLite can also be tuned using the cache_size
pragma.
=end original
SQLite¤Î¥á¥â¥ê»ÈÍÑÎ̤ϡ¢cache_size¥×¥é¥°¥Þ¤ò»ÈÍѤ·¤ÆÄ´À°¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
(TBR)
$dbh->do("PRAGMA cache_size = 800000");
=begin original
The above will allocate 800M for DB cache; the default is 2M.
Your sweet spot probably lies somewhere in between.
=end original
¾åµ¤ÏDB¥¥ã¥Ã¥·¥å¤Ë800M¤ò³ä¤êÅö¤Æ¤Þ¤¹¡£
¥Ç¥Õ¥©¥ë¥È¤Ï2M¤Ç¤¹¡£
¤¢¤Ê¤¿¤Î¥¹¥¤¡¼¥È¥¹¥Ý¥Ã¥È¤Ï¤ª¤½¤é¤¯¤½¤Î´Ö¤Î¤É¤³¤«¤Ë¤¢¤ê¤Þ¤¹¡£
(TBR)
=head1 DRIVER PRIVATE ATTRIBUTES
=head2 Database Handle Attributes
=over 4
=item sqlite_version
=begin original
Returns the version of the SQLite library which B is using,
e.g., "2.8.0". Can only be read.
=end original
B¤¬»ÈÍѤ·¤Æ¤¤¤ëSQLite¥é¥¤¥Ö¥é¥ê¤Î¥Ð¡¼¥¸¥ç¥ó("2.8.0"¤Ê¤É)¤òÊÖ¤·¤Þ¤¹¡£
Æɤ߼è¤êÀìÍѤǤ¹¡£
(TBR)
=item sqlite_unicode
=begin original
If set to a true value, B will turn the UTF-8 flag on for all
text strings coming out of the database (this feature is currently disabled
for perl < 5.8.5). For more details on the UTF-8 flag see
L. The default is for the UTF-8 flag to be turned off.
=end original
true¤ËÀßÄꤹ¤ë¤È¡¢B¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é½ÐÎϤµ¤ì¤ë¤¹¤Ù¤Æ¤Î¥Æ¥¥¹¥Èʸ»úÎó¤ËÂФ·¤ÆUTF-8¥Õ¥é¥°¤ò¥ª¥ó¤Ë¤·¤Þ¤¹(perl<5.8.5¤Ç¤Ï¡¢¤³¤Îµ¡Ç½¤Ï¸½ºß̵¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹)¡£
UTF-8¥Õ¥é¥°¤Î¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢L¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢UTF-8¥Õ¥é¥°¤Ï¥ª¥Õ¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£
(TBR)
=begin original
Also note that due to some bizarreness in SQLite's type system (see
L), if you want to retain
blob-style behavior for B columns under C<< $dbh->{sqlite_unicode} = 1
>> (say, to store images in the database), you have to state so
explicitly using the 3-argument form of L when doing
updates:
=end original
¤Þ¤¿¡¢SQLite¤Î·¿¥·¥¹¥Æ¥à(L¤ò»²¾È)¤Î¤¤¤¯¤Ä¤«¤Î´ñ̯¤µ¤Î¤¿¤á¤Ë¡¢C<< $dbh->{SQLite_unicode}=1>>¤Î²¼¤ÎBÎó¤Î¥Ö¥í¥Ö¥¹¥¿¥¤¥ë¤ÎÆ°ºî¤òÊÝ»ý¤·¤¿¤¤¾ì¹ç(¤¿¤È¤¨¤Ð¡¢¥¤¥á¡¼¥¸¤ò¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë³ÊǼ¤¹¤ë¾ì¹ç)¡¢¹¹¿·¤ò¹Ô¤¦¤È¤¤ËL¤Î3°ú¿ô·Á¼°¤ò»ÈÍѤ·¤ÆÌÀ¼¨Åª¤ËÀë¸À¤¹¤ëɬÍפ¬¤¢¤ë¤³¤È¤Ë¤âÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
(TBR)
use DBI qw(:sql_types);
$dbh->{sqlite_unicode} = 1;
my $sth = $dbh->prepare("INSERT INTO mytable (blobcolumn) VALUES (?)");
# Binary_data will be stored as is.
$sth->bind_param(1, $binary_data, SQL_BLOB);
=begin original
Defining the column type as C in the DDL is B sufficient.
=end original
DDL¤ÇÎ󥿥¤¥×¤òC¤È¤·¤ÆÄêµÁ¤¹¤ë¤³¤È¤Ï¡¢B¤Ç½½Ê¬¤Ç¤¹¡£
(TBR)
=begin original
This attribute was originally named as C, and renamed to
C for integrity since version 1.26_06. Old C
attribute is still accessible but will be deprecated in the near future.
=end original
¤³¤Î°À¤Ï¸µ¡¹C¤È¤¤¤¦Ì¾Á°¤Ç¤·¤¿¤¬¡¢¥Ð¡¼¥¸¥ç¥ó1.26_06¤«¤éÀ°¹çÀ¤Î¤¿¤á¤ËC¤Ë̾Á°¤¬Êѹ¹¤µ¤ì¤Þ¤·¤¿¡£
¸Å¤¤C°À¤Ï¤Þ¤À¥¢¥¯¥»¥¹²Äǽ¤Ç¤¹¤¬¡¢¶á¤¤¾ÍèÇѻߤµ¤ì¤ëͽÄê¤Ç¤¹¡£
(TBR)
=back
=head1 METHODS
=head2 table_info
$sth = $dbh->table_info(undef, $schema, $table, $type, \%attr);
=begin original
Returns all tables and schemas (databases) as specified in L.
The schema and table arguments will do a C search. You can specify an
ESCAPE character by including an 'Escape' attribute in \%attr. The C<$type>
argument accepts a comma seperated list of the following types 'TABLE',
'VIEW', 'LOCAL TEMPORARY' and 'SYSTEM TABLE' (by default all are returned).
Note that a statement handle is returned, and not a direct list of tables.
=end original
L¤Ç»ØÄꤵ¤ì¤¿¤¹¤Ù¤Æ¤Îɽ¤ª¤è¤Ó¥¹¥¡¼¥Þ(¥Ç¡¼¥¿¥Ù¡¼¥¹)¤¬Ìᤵ¤ì¤Þ¤¹¡£
¥¹¥¡¼¥Þ¤ª¤è¤Óɽ¤Î°ú¿ô¤Ë¤è¤ê¡¢C¸¡º÷¤¬¼Â¹Ô¤µ¤ì¤Þ¤¹¡£
\%attr¤Ë'Escape'°À¤ò´Þ¤á¤ë¤³¤È¤Ë¤è¤ê¡¢ESCAPEʸ»ú¤ò»ØÄê¤Ç¤¤Þ¤¹¡£
C<$type>°ú¿ô¤Ë¤Ï¡¢'TABLE'¡¢'VIEW'¡¢'LOCAL TEMPORARY'¡¢¤ª¤è¤Ó'SYSTEM TABLE'¥¿¥¤¥×¤Î¥«¥ó¥Þ¶èÀÚ¤ê¥ê¥¹¥È¤ò»ØÄê¤Ç¤¤Þ¤¹(¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¤¹¤Ù¤Æ¤¬Ìᤵ¤ì¤Þ¤¹)¡£
ɽ¤ÎľÀܥꥹ¥È¤Ç¤Ï¤Ê¤¯¡¢Ê¸¥Ï¥ó¥É¥ë¤¬Ìᤵ¤ì¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
(TBR)
=begin original
The following fields are returned:
=end original
¼¡¤Î¥Õ¥£¡¼¥ë¥É¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£
(TBR)
=begin original
B: Always NULL, as SQLite does not have the concept of catalogs.
=end original
B:SQLite¤Ë¤Ï¥«¥¿¥í¥°¤Î³µÇ°¤¬¤Ê¤¤¤¿¤á¡¢¾ï¤ËNULL¤Ç¤¹¡£
(TBR)
=begin original
B: The name of the schema (database) that the table or view is
in. The default schema is 'main', temporary tables are in 'temp' and other
databases will be in the name given when the database was attached.
=end original
B:ɽ¤Þ¤¿¤Ï¥Ó¥å¡¼¤¬Â¸ºß¤¹¤ë¥¹¥¡¼¥Þ(¥Ç¡¼¥¿¥Ù¡¼¥¹)¤Î̾Á°¡£
¥Ç¥Õ¥©¥ë¥È¤Î¥¹¥¡¼¥Þ¤Ï'main'¡¢°ì»þɽ¤Ï'temp'¡¢¤½¤Î¾¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ï¥Ç¡¼¥¿¥Ù¡¼¥¹¤¬Àܳ¤µ¤ì¤¿¤È¤¤Ë»ØÄꤵ¤ì¤¿Ì¾Á°¤Ë¤Ê¤ê¤Þ¤¹¡£
(TBR)
=begin original
B: The name of the table or view.
=end original
B:¥Æ¡¼¥Ö¥ë¤Þ¤¿¤Ï¥Ó¥å¡¼¤Î̾Á°¡£
(TBR)
=begin original
B: The type of object returned. Will be one of 'TABLE', 'VIEW',
'LOCAL TEMPORARY' or 'SYSTEM TABLE'.
=end original
B:Ìᤵ¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¿¥¤¥×¡£
'TABLE'¡¢'VIEW'¡¢'LOCAL TEMPORARY'¡¢¤Þ¤¿¤Ï'SYSTEM TABLE'¤Î¤¤¤º¤ì¤«¤Ç¤¹¡£
(TBR)
=head1 DRIVER PRIVATE METHODS
=begin original
The following methods can be called via the func() method with a little
tweak, but the use of func() method is now discouraged by the L author
for various reasons (see DBI's document
L
for details). So, if you're using L >= 1.608, use these C
methods. If you need to use an older L, you can call these like this:
=end original
¼¡¤Î¥á¥½¥Ã¥É¤Ï¡¢¾¯¤·¤Ò¤Í¤ê¤ò²Ã¤¨¤Æfunc()¥á¥½¥Ã¥É¤ò²ð¤·¤Æ¸Æ¤Ó½Ð¤¹¤³¤È¤¬¤Ç¤¤Þ¤¹¤¬¡¢L¤ÎºîÀ®¼Ô¤Ï¡¢¤µ¤Þ¤¶¤Þ¤ÊÍýͳ¤«¤éfunc()¥á¥½¥Ã¥É¤Î»ÈÍѤò¿ä¾©¤·¤Æ¤¤¤Þ¤»¤ó(¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢DBI¤Îʸ½ñL¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤)¡£
¤·¤¿¤¬¤Ã¤Æ¡¢L>=1.608¤ò»ÈÍѤ·¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¤³¤ì¤é¤ÎC¥á¥½¥Ã¥É¤ò»ÈÍѤ·¤Þ¤¹¡£
¸Å¤¤L¤ò»ÈÍѤ¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ï¡¢¼¡¤Î¤è¤¦¤Ë¸Æ¤Ó½Ð¤¹¤³¤È¤¬¤Ç¤¤Þ¤¹:
(TBR)
$dbh->func( ..., "(method name without sqlite_ prefix)" );
=head2 $dbh->sqlite_last_insert_rowid()
=begin original
This method returns the last inserted rowid. If you specify an INTEGER PRIMARY
KEY as the first column in your table, that is the column that is returned.
Otherwise, it is the hidden ROWID column. See the sqlite docs for details.
=end original
¤³¤Î¥á¥½¥Ã¥É¤ÏºÇ¸å¤ËÁÞÆþ¤µ¤ì¤¿ rowid ¤òÊÖ¤·¤Þ¤¹¡£
¤â¤· INTEGER PRIMARY KEY ¤ò¤¢¤Ê¤¿¤Î¥Æ¡¼¥Ö¥ë¤Ç¤ÎÀèƬ¥«¥é¥à¤È¤·¤Æ»ØÄꤹ¤ì¤Ð¡¢
ÊÖ¤µ¤ì¤ë¤Î¤Ï¤½¤Î¥«¥é¥à¤Ë¤Ê¤ê¤Þ¤¹¡£
¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢¤½¤ì¤Ï±£¤µ¤ì¤¿ ROWID ¥«¥é¥à¤Ë¤Ê¤ê¤Þ¤¹¡£
¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï sqlite ¥É¥¥å¥á¥ó¥È¤ò¤´Í÷¤¯¤À¤µ¤¤¡£
=begin original
Generally you should not be using this method. Use the L last_insert_id
method instead. The usage of this is:
=end original
Ä̾¤³¤Î¥á¥½¥Ã¥É¤Ï»ÈÍѤ·¤Þ¤»¤ó¡£
¤«¤ï¤ê¤ËLlast_insert_id¥á¥½¥Ã¥É¤ò»ÈÍѤ·¤Þ¤¹¡£
¤³¤Î¥á¥½¥Ã¥É¤Î»ÈÍÑÊýË¡¤Ï¼¡¤Î¤È¤ª¤ê¤Ç¤¹:
(TBR)
$h->last_insert_id($catalog, $schema, $table_name, $field_name [, \%attr ])
=begin original
Running C<$h-Elast_insert_id("","","","")> is the equivalent of running
C<$dbh-Esqlite_last_insert_rowid()> directly.
=end original
C<$h-Elast_insert_id("","","","")>¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ï¡¢C<$dbh-Esqlite_last_insert_rowid()>¤òľÀܼ¹Ԥ¹¤ë¤³¤È¤ÈƱ¤¸¤Ç¤¹¡£
(TBR)
=head2 $dbh->sqlite_busy_timeout()
=begin original
Retrieve the current busy timeout.
=end original
¸½ºß¤Î¥Ó¥¸¡¼¥¿¥¤¥à¥¢¥¦¥È¤ò¼èÆÀ¤·¤Þ¤¹¡£
(TBR)
=head2 $dbh->sqlite_busy_timeout( $ms )
=begin original
Set the current busy timeout. The timeout is in milliseconds.
=end original
¸½ºß¤Î¥Ó¥¸¡¼¥¿¥¤¥à¥¢¥¦¥È¤òÀßÄꤷ¤Þ¤¹¡£
¥¿¥¤¥à¥¢¥¦¥È¤Ï¥ß¥êÉÃñ°Ì¤Ç¤¹¡£
(TBR)
=head2 $dbh->sqlite_create_function( $name, $argc, $code_ref )
=begin original
This method will register a new function which will be useable in an SQL
query. The method's parameters are:
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢SQL¥¯¥¨¥ê¤Ç»ÈÍѤǤ¤ë¿·¤·¤¤´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
¥á¥½¥Ã¥É¤Î¥Ñ¥é¥á¡¼¥¿¤Ï¼¡¤Î¤È¤ª¤ê¤Ç¤¹¡£
(TBR)
=over
=item $name
=begin original
The name of the function. This is the name of the function as it will
be used from SQL.
=end original
´Ø¿ô¤Î̾Á°¡£
¤³¤ì¤ÏSQL¤«¤é»ÈÍѤµ¤ì¤ë´Ø¿ô¤Î̾Á°¤Ç¤¹¡£
(TBR)
=item $argc
=begin original
The number of arguments taken by the function. If this number is -1,
the function can take any number of arguments.
=end original
´Ø¿ô¤¬¼è¤ë°ú¿ô¤Î¿ô¡£
¤³¤Î¿ô¤¬-1¤Î¾ì¹ç¡¢´Ø¿ô¤ÏǤ°Õ¤Î¿ô¤Î°ú¿ô¤ò¼è¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
(TBR)
=item $code_ref
=begin original
This should be a reference to the function's implementation.
=end original
¤³¤ì¤Ï¡¢´Ø¿ô¤Î¼ÂÁõ¤Ø¤Î»²¾È¤Ç¤¢¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
(TBR)
=back
=begin original
For example, here is how to define a now() function which returns the
current number of seconds since the epoch:
=end original
¤¿¤È¤¨¤Ð¡¢¥¨¥Ý¥Ã¥¯¤«¤é¤Î¸½ºß¤ÎÉÿô¤òÊÖ¤¹now()´Ø¿ô¤òÄêµÁ¤¹¤ëÊýË¡¤ò¼¡¤Ë¼¨¤·¤Þ¤¹¡£
(TBR)
$dbh->sqlite_create_function( 'now', 0, sub { return time } );
=begin original
After this, it could be use from SQL as:
=end original
¤³¤Î¸å¡¢SQL¤«¤é¼¡¤Î¤è¤¦¤Ë»ÈÍѤǤ¤Þ¤¹¡£
(TBR)
INSERT INTO mytable ( now() );
=head3 REGEXP function
=begin original
SQLite includes syntactic support for an infix operator 'REGEXP', but
without any implementation. The C driver
automatically registers an implementation that performs standard
perl regular expression matching, using current locale. So for example
you can search for words starting with an 'A' with a query like
=end original
SQLite¤Ë¤Ï¡¢¥¤¥ó¥Õ¥£¥Ã¥¯¥¹±é»»»Ò'REGEXP'¤Î¹½Ê¸¥µ¥Ý¡¼¥È¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢¼ÂÁõ¤Ï¤¢¤ê¤Þ¤»¤ó¡£
C¥É¥é¥¤¥Ð¤Ï¡¢¸½ºß¤Î¥í¥±¡¼¥ë¤ò»ÈÍѤ·¤Æ¡¢É¸½àŪ¤ÊperlÀµµ¬É½¸½¤Î¾È¹ç¤ò¼Â¹Ô¤¹¤ë¼ÂÁõ¤ò¼«Æ°Åª¤ËÅÐÏ¿¤·¤Þ¤¹¡£
¤·¤¿¤¬¤Ã¤Æ¡¢¤¿¤È¤¨¤Ð¡¢¼¡¤Î¤è¤¦¤Ê¥¯¥¨¥ê¤ò»ÈÍѤ·¤Æ¡¢'A'¤Ç»Ï¤Þ¤ëñ¸ì¤ò¸¡º÷¤Ç¤¤Þ¤¹¡£
(TBR)
SELECT * from table WHERE column REGEXP '\bA\w+'
=begin original
If you want case-insensitive searching, use perl regex flags, like this :
=end original
Âçʸ»ú¤È¾®Ê¸»ú¤ò¶èÊ̤·¤Ê¤¤¸¡º÷¤¬É¬Íפʾì¹ç¤Ï¡¢¼¡¤Î¤è¤¦¤Ëperl regex¥Õ¥é¥°¤ò»ÈÍѤ·¤Þ¤¹¡£
(TBR)
SELECT * from table WHERE column REGEXP '(?i:\bA\w+)'
=begin original
The default REGEXP implementation can be overriden through the
C API described above.
=end original
¥Ç¥Õ¥©¥ë¥È¤ÎREGEXP¼ÂÁõ¤Ï¡¢Á°½Ò¤ÎCAPI¤ò²ð¤·¤Æ¾å½ñ¤¤Ç¤¤Þ¤¹¡£
(TBR)
=begin original
Note that regexp matching will B use SQLite indices, but will iterate
over all rows, so it could be quite costly in terms of performance.
=end original
Àµµ¬É½¸½¥Þ¥Ã¥Á¥ó¥°¤ÏSQLite¥¤¥ó¥Ç¥Ã¥¯¥¹¤ò»ÈÍÑ<¤·¤Þ¤»¤ó>¤·¤Þ¤¹¤¬¡¢¤¹¤Ù¤Æ¤Î¹Ô¤ËÂФ·¤Æ·«¤êÊÖ¤µ¤ì¤ë¤¿¤á¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤ÎÅÀ¤ÇÈó¾ï¤Ë¥³¥¹¥È¤¬¤«¤«¤ë²ÄǽÀ¤¬¤¢¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡£
(TBR)
=head2 $dbh->sqlite_create_collation( $name, $code_ref )
=begin original
This method manually registers a new function which will be useable in an SQL
query as a COLLATE option for sorting. Such functions can also be registered
automatically on demand: see section L"COLLATION FUNCTIONS"> below.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢SQL¥¯¥¨¥ê¡¼¤Ç¥½¡¼¥ÈÍѤÎCOLLATE¥ª¥×¥·¥ç¥ó¤È¤·¤Æ»ÈÍѤǤ¤ë¿·¤·¤¤´Ø¿ô¤ò¼êÆ°¤ÇÅÐÏ¿¤·¤Þ¤¹¡£
¤³¤Î¤è¤¦¤Ê´Ø¿ô¤Ï¡¢É¬Íפ˱þ¤¸¤Æ¼«Æ°Åª¤ËÅÐÏ¿¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
¸å½Ò¤Î¥»¥¯¥·¥ç¥óL"COLLATION FUNCTIONS">¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
(TBR)
=begin original
The method's parameters are:
=end original
¤³¤Î¥á¥½¥Ã¥É¤Î¥Ñ¥é¥á¡¼¥¿¤Ï¼¡¤Î¤È¤ª¤ê¤Ç¤¹¡£
(TBR)
=over
=item $name
=begin original
The name of the function exposed to SQL.
=end original
SQL¤Ë¸ø³«¤µ¤ì¤Æ¤¤¤ë´Ø¿ô¤Î̾Á°¡£
(TBR)
=item $code_ref
=begin original
Reference to the function's implementation.
The driver will check that this is a proper sorting function.
=end original
´Ø¿ô¤Î¼ÂÁõ¤Ø¤Î»²¾È¡£
¥É¥é¥¤¥Ð¤Ï¡¢¤³¤ì¤¬Å¬Àڤʥ½¡¼¥È´Ø¿ô¤Ç¤¢¤ë¤³¤È¤ò³Îǧ¤·¤Þ¤¹¡£
(TBR)
=back
=head2 $dbh->sqlite_collation_needed( $code_ref )
=begin original
This method manually registers a callback function that will
be invoked whenever an undefined collation sequence is required
from an SQL statement. The callback is invoked as
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢SQLʸ¤«¤é̤ÄêµÁ¤Î¾È¹ç½ç½ø¤¬Í׵ᤵ¤ì¤ë¤¿¤Ó¤Ëµ¯Æ°¤µ¤ì¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤ò¼êÆ°¤ÇÅÐÏ¿¤·¤Þ¤¹¡£
¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¼¡¤Î¤è¤¦¤Ëµ¯Æ°¤µ¤ì¤Þ¤¹¡£
(TBR)
$code_ref->($dbh, $collation_name)
=begin original
and should register the desired collation using
L"sqlite_create_collation">.
=end original
L"sqlite_create_collation">¤ò»ÈÍѤ·¤ÆÌÜŪ¤Î¾È¹ç¤òÅÐÏ¿¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
(TBR)
=begin original
An initial callback is already registered by C,
so for most common cases it will be simpler to just
add your collation sequences in the C<%DBD::SQLite::COLLATION>
hash (see section L"COLLATION FUNCTIONS"> below).
=end original
ºÇ½é¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¤¹¤Ç¤ËC¤Ë¤è¤Ã¤ÆÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¤¿¤á¡¢¤Û¤È¤ó¤É¤Î°ìÈÌŪ¤Ê¥±¡¼¥¹¤Ç¤Ï¡¢C<%DBD::SQLite::COLLATION>¥Ï¥Ã¥·¥å¤Ë¾È¹ç½ç½ø¤òÄɲ乤ëÊý¤¬´Êñ¤Ç¤¹(¸å½Ò¤Î¥»¥¯¥·¥ç¥óL"COLLATION FUNCTIONS">¤ò»²¾È)¡£
(TBR)
=head2 $dbh->sqlite_create_aggregate( $name, $argc, $pkg )
=begin original
This method will register a new aggregate function which can then be used
from SQL. The method's parameters are:
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢SQL¤«¤é»ÈÍѤǤ¤ë¿·¤·¤¤½¸·×´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
¥á¥½¥Ã¥É¤Î¥Ñ¥é¥á¡¼¥¿¤Ï¼¡¤Î¤È¤ª¤ê¤Ç¤¹¡£
(TBR)
=over
=item $name
=begin original
The name of the aggregate function, this is the name under which the
function will be available from SQL.
=end original
½¸Ìó´Ø¿ô¤Î̾Á°¡£
¤³¤ì¤Ï¡¢SQL¤«¤é»ÈÍѤǤ¤ë´Ø¿ô¤Î̾Á°¤Ç¤¹¡£
(TBR)
=item $argc
=begin original
This is an integer which tells the SQL parser how many arguments the
function takes. If that number is -1, the function can take any number
of arguments.
=end original
¤³¤ì¤Ï¡¢´Ø¿ô¤¬¼è¤ë°ú¿ô¤Î¿ô¤òSQL¥Ñ¡¼¥µ¡¼¤ËÅÁ¤¨¤ëÀ°¿ô¤Ç¤¹¡£
¤½¤Î¿ô¤¬-1¤Î¾ì¹ç¡¢´Ø¿ô¤ÏǤ°Õ¤Î¿ô¤Î°ú¿ô¤ò¼è¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
(TBR)
=item $pkg
=begin original
This is the package which implements the aggregator interface.
=end original
¤³¤ì¤Ï¡¢¥¢¥°¥ê¥²¡¼¥¿¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¥Ñ¥Ã¥±¡¼¥¸¤Ç¤¹¡£
(TBR)
=back
=begin original
The aggregator interface consists of defining three methods:
=end original
¥¢¥°¥ê¥²¡¼¥¿¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ï¡¢¼¡¤Î3¤Ä¤Î¥á¥½¥Ã¥É¤ÎÄêµÁ¤Ç¹½À®¤µ¤ì¤Æ¤¤¤Þ¤¹¡£
(TBR)
=over
=item new()
=begin original
This method will be called once to create an object which should
be used to aggregate the rows in a particular group. The step() and
finalize() methods will be called upon the reference return by
the method.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢ÆÃÄê¤Î¥°¥ë¡¼¥×Æâ¤Î¹Ô¤ò½¸·×¤¹¤ë¤¿¤á¤Ë»ÈÍѤ¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤¹¤ë¤¿¤á¤Ë1²ó¥³¡¼¥ë¤µ¤ì¤Þ¤¹¡£
step()¤ª¤è¤Ófinalize()¥á¥½¥Ã¥É¤Ï¡¢¥á¥½¥Ã¥É¤«¤é¤Î»²¾È¤¬ÊÖ¤µ¤ì¤¿¤È¤¤Ë¥³¡¼¥ë¤µ¤ì¤Þ¤¹¡£
(TBR)
=item step(@_)
=begin original
This method will be called once for each row in the aggregate.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢½¸Ìó¤Î³Æ¹Ô¤ËÂФ·¤Æ1²ó¤º¤Ä¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
(TBR)
=item finalize()
=begin original
This method will be called once all rows in the aggregate were
processed and it should return the aggregate function's result. When
there is no rows in the aggregate, finalize() will be called right
after new().
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢½¸·×¤Î¤¹¤Ù¤Æ¤Î¹Ô¤¬½èÍý¤µ¤ì¤ë¤È¸Æ¤Ó½Ð¤µ¤ì¡¢½¸·×´Ø¿ô¤Î·ë²Ì¤òÊÖ¤¹É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
½¸·×¤Ë¹Ô¤¬¤Ê¤¤¾ì¹ç¤Ï¡¢new()¤Îľ¸å¤Ëfinalize()¤¬¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
(TBR)
=back
=begin original
Here is a simple aggregate function which returns the variance
(example adapted from pysqlite):
=end original
¼¡¤Ë¡¢Ê¬»¶¤òÊÖ¤¹Ã±½ã¤Ê½¸Ìó´Ø¿ô¤ò¼¨¤·¤Þ¤¹(pysqlite¤«¤éºÎÍѤµ¤ì¤¿Îã)¡£
(TBR)
package variance;
sub new { bless [], shift; }
sub step {
my ( $self, $value ) = @_;
push @$self, $value;
}
sub finalize {
my $self = $_[0];
my $n = @$self;
# Variance is NULL unless there is more than one row
return undef unless $n || $n == 1;
my $mu = 0;
foreach my $v ( @$self ) {
$mu += $v;
}
$mu /= $n;
my $sigma = 0;
foreach my $v ( @$self ) {
$sigma += ($x - $mu)**2;
}
$sigma = $sigma / ($n - 1);
return $sigma;
}
$dbh->sqlite_create_aggregate( "variance", 1, 'variance' );
=begin original
The aggregate function can then be used as:
=end original
½¸Ìó´Ø¿ô¤Ï¡¢¼¡¤Î¤è¤¦¤Ë»ÈÍѤǤ¤Þ¤¹¡£
(TBR)
SELECT group_name, variance(score)
FROM results
GROUP BY group_name;
=begin original
For more examples, see the L.
=end original
¤½¤Î¾¤ÎÎã¤Ë¤Ä¤¤¤Æ¤Ï¡¢L¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
(TBR)
=head2 $dbh->sqlite_progress_handler( $n_opcodes, $code_ref )
=begin original
This method registers a handler to be invoked periodically during long
running calls to SQLite.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢Ä¹»þ´Ö¼Â¹Ô¤µ¤ì¤ëSQLite¤Î¸Æ¤Ó½Ð¤·Ãæ¤ËÄê´üŪ¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¥Ï¥ó¥É¥é¤òÅÐÏ¿¤·¤Þ¤¹¡£
(TBR)
=begin original
An example use for this interface is to keep a GUI updated during a
large query. The parameters are:
=end original
¤³¤Î¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Î»ÈÍÑÎã¤È¤·¤Æ¤Ï¡¢Â絬ÌϤʥ¯¥¨¥ê¡¼¤Î¼Â¹ÔÃæ¤ËGUI¤ò¹¹¿·¤·¤Æ¤ª¤¯¤³¤È¤¬µó¤²¤é¤ì¤Þ¤¹¡£
¥Ñ¥é¥á¡¼¥¿¤Ï¼¡¤Î¤È¤ª¤ê¤Ç¤¹¡£
(TBR)
=over
=item $n_opcodes
=begin original
The progress handler is invoked once for every C<$n_opcodes>
virtual machine opcodes in SQLite.
=end original
progress¥Ï¥ó¥É¥é¤Ï¡¢SQLite¤ÎC<$n_opcodes>²¾ÁÛ¥Þ¥·¥ó¤Î¥ª¥Ú¥³¡¼¥É¤´¤È¤Ë1²ó¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
(TBR)
=item $code_ref
=begin original
Reference to the handler subroutine. If the progress handler returns
non-zero, the SQLite operation is interrupted. This feature can be used to
implement a "Cancel" button on a GUI dialog box.
=end original
¥Ï¥ó¥É¥é¥µ¥Ö¥ë¡¼¥Á¥ó¤Ø¤Î»²¾È¡£
¿Ê¹Ô¾õ¶·¥Ï¥ó¥É¥é¤¬¥¼¥í°Ê³°¤òÊÖ¤¹¾ì¹ç¡¢SQLiteÁàºî¤ÏÃæÃǤµ¤ì¤Þ¤¹¡£
¤³¤Îµ¡Ç½¤ò»ÈÍѤ·¤Æ¡¢GUI¥À¥¤¥¢¥í¥°¥Ü¥Ã¥¯¥¹¤Ë¡Ö¥¥ã¥ó¥»¥ë¡×¥Ü¥¿¥ó¤ò¼ÂÁõ¤Ç¤¤Þ¤¹¡£
(TBR)
=begin original
Set this argument to C if you want to unregister a previous
progress handler.
=end original
°ÊÁ°¤Î¿ÊĽ¥Ï¥ó¥É¥é¤ÎÅÐÏ¿¤ò²ò½ü¤¹¤ë¾ì¹ç¤Ï¡¢¤³¤Î°ú¿ô¤òC¤ËÀßÄꤷ¤Þ¤¹¡£
(TBR)
=back
=head2 $dbh->sqlite_commit_hook( $code_ref )
=begin original
This method registers a callback function to be invoked whenever a
transaction is committed. Any callback set by a previous call to
C is overridden. A reference to the previous
callback (if any) is returned. Registering an C disables the
callback.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤¬¥³¥ß¥Ã¥È¤µ¤ì¤ë¤¿¤Ó¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
°ÊÁ°¤ÎC¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤¿¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¤¹¤Ù¤Æ¾å½ñ¤¤µ¤ì¤Þ¤¹¡£
°ÊÁ°¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤Ø¤Î»²¾È(¸ºß¤¹¤ë¾ì¹ç)¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£
C¤òÅÐÏ¿¤¹¤ë¤È¡¢¥³¡¼¥ë¥Ð¥Ã¥¯¤¬Ìµ¸ú¤Ë¤Ê¤ê¤Þ¤¹¡£
(TBR)
=begin original
When the commit hook callback returns zero, the commit operation is
allowed to continue normally. If the callback returns non-zero, then
the commit is converted into a rollback (in that case, any attempt to
I call C<< $dbh->rollback() >> afterwards would yield an
error).
=end original
¥³¥ß¥Ã¥È¥Õ¥Ã¥¯¥³¡¼¥ë¥Ð¥Ã¥¯¤¬¥¼¥í¤òÊÖ¤¹¤È¡¢¥³¥ß¥Ã¥ÈÁàºî¤ÏÀµ¾ï¤Ë³¹Ô¤Ç¤¤Þ¤¹¡£
¥³¡¼¥ë¥Ð¥Ã¥¯¤¬¥¼¥í°Ê³°¤òÊÖ¤¹¤È¡¢¥³¥ß¥Ã¥È¤Ï¥í¡¼¥ë¥Ð¥Ã¥¯¤ËÊÑ´¹¤µ¤ì¤Þ¤¹(¤½¤Î¾ì¹ç¡¢¸å¤ÇC<< $dbh->rollback()>>¤ò<ÌÀ¼¨Åª¤Ë>¸Æ¤Ó½Ð¤½¤¦¤È¤¹¤ë¤È¡¢¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤¹)¡£
(TBR)
=head2 $dbh->sqlite_rollback_hook( $code_ref )
=begin original
This method registers a callback function to be invoked whenever a
transaction is rolled back. Any callback set by a previous call to
C is overridden. A reference to the previous
callback (if any) is returned. Registering an C disables the
callback.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤¬¥í¡¼¥ë¥Ð¥Ã¥¯¤µ¤ì¤ë¤¿¤Ó¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
°ÊÁ°¤ÎC¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤¿¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¤¹¤Ù¤Æ¾å½ñ¤¤µ¤ì¤Þ¤¹¡£
°ÊÁ°¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤Ø¤Î»²¾È(¸ºß¤¹¤ë¾ì¹ç)¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£
C¤òÅÐÏ¿¤¹¤ë¤È¡¢¥³¡¼¥ë¥Ð¥Ã¥¯¤¬Ìµ¸ú¤Ë¤Ê¤ê¤Þ¤¹¡£
(TBR)
=head2 $dbh->sqlite_update_hook( $code_ref )
=begin original
This method registers a callback function to be invoked whenever a row
is updated, inserted or deleted. Any callback set by a previous call to
C is overridden. A reference to the previous
callback (if any) is returned. Registering an C disables the
callback.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢¹Ô¤¬¹¹¿·¡¢ÁÞÆþ¡¢¤Þ¤¿¤Ïºï½ü¤µ¤ì¤ë¤¿¤Ó¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¥³¡¼¥ë¥Ð¥Ã¥¯´Ø¿ô¤òÅÐÏ¿¤·¤Þ¤¹¡£
°ÊÁ°¤ÎC¤Î¸Æ¤Ó½Ð¤·¤Ë¤è¤Ã¤ÆÀßÄꤵ¤ì¤¿¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¤¹¤Ù¤Æ¾å½ñ¤¤µ¤ì¤Þ¤¹¡£
°ÊÁ°¤Î¥³¡¼¥ë¥Ð¥Ã¥¯¤Ø¤Î»²¾È(¸ºß¤¹¤ë¾ì¹ç)¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£
C¤òÅÐÏ¿¤¹¤ë¤È¡¢¥³¡¼¥ë¥Ð¥Ã¥¯¤¬Ìµ¸ú¤Ë¤Ê¤ê¤Þ¤¹¡£
(TBR)
=begin original
The callback will be called as
=end original
¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¼¡¤Î¤è¤¦¤Ë¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
(TBR)
$code_ref->($action_code, $database, $table, $rowid)
=begin original
where
=end original
¤³¤³¤Ç
(TBR)
=over
=item $action_code
=begin original
is an integer equal to either C,
C or C
(see L"Action Codes">);
=end original
C¡¢C¡¢¤Þ¤¿¤ÏC(L"Action Codes">¤ò»²¾È)¤Î¤¤¤º¤ì¤«¤ÈÅù¤·¤¤À°¿ô¤Ç¤¹¡£
(TBR)
=item $database
=begin original
is the name of the database containing the affected row;
=end original
¤Ï¡¢±Æ¶Á¤ò¼õ¤±¤ë¹Ô¤ò´Þ¤à¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î̾Á°¤Ç¤¹¡£
(TBR)
=item $table
=begin original
is the name of the table containing the affected row;
=end original
¤Ï¡¢±Æ¶Á¤ò¼õ¤±¤ë¹Ô¤ò´Þ¤à¥Æ¡¼¥Ö¥ë¤Î̾Á°¤Ç¤¹¡£
(TBR)
=item $rowid
=begin original
is the unique 64-bit signed integer key of the affected row within that table.
=end original
¤Ï¡¢¤½¤Î¥Æ¡¼¥Ö¥ëÆâ¤Î±Æ¶Á¤ò¼õ¤±¤ë¥í¡¼¤Î°ì°Õ¤Î64¥Ó¥Ã¥ÈÉä¹æÉÕ¤À°¿ô¥¡¼¤Ç¤¹¡£
(TBR)
=back
=head2 $dbh->sqlite_set_authorizer( $code_ref )
=begin original
This method registers an authorizer callback to be invoked whenever
SQL statements are being compiled by the L method. The
authorizer callback should return C to allow the
action, C to disallow the specific action but
allow the SQL statement to continue to be compiled, or
C to cause the entire SQL statement to be rejected
with an error. If the authorizer callback returns any other value,
then then C call that triggered the authorizer will fail with
an error message.
=end original
¤³¤Î¥á¥½¥Ã¥É¤Ï¡¢L¥á¥½¥Ã¥É¤Ë¤è¤Ã¤ÆSQLʸ¤¬¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤ë¤¿¤Ó¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¾µÇ§¼Ô¥³¡¼¥ë¥Ð¥Ã¥¯¤òÅÐÏ¿¤·¤Þ¤¹¡£
¾µÇ§¼Ô¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¡¢¥¢¥¯¥·¥ç¥ó¤òµö²Ä¤¹¤ë¾ì¹ç¤ÏC¡¢ÆÃÄê¤Î¥¢¥¯¥·¥ç¥ó¤ò¶Ø»ß¤¹¤ë¤¬SQLʸ¤Î¥³¥ó¥Ñ¥¤¥ë¤ò³¹Ô¤¹¤ë¾ì¹ç¤ÏC¡¢¤Þ¤¿¤ÏSQLʸÁ´ÂΤò¥¨¥é¡¼¤ÇµñÈݤ¹¤ë¾ì¹ç¤ÏC¤òÊÖ¤¹É¬Íפ¬¤¢¤ê¤Þ¤¹¡£
¾µÇ§¼Ô¥³¡¼¥ë¥Ð¥Ã¥¯¤¬¤½¤Î¾¤ÎÃͤòÊÖ¤¹¾ì¹ç¡¢¾µÇ§¼Ô¤ò¥È¥ê¥¬¡¼¤·¤¿C¸Æ¤Ó½Ð¤·¤Ï¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Ç¼ºÇÔ¤·¤Þ¤¹¡£
(TBR)
=begin original
An authorizer is used when preparing SQL statements from an untrusted
source, to ensure that the SQL statements do not try to access data
they are not allowed to see, or that they do not try to execute
malicious statements that damage the database. For example, an
application may allow a user to enter arbitrary SQL queries for
evaluation by a database. But the application does not want the user
to be able to make arbitrary changes to the database. An authorizer
could then be put in place while the user-entered SQL is being
prepared that disallows everything except SELECT statements.
=end original
¾µÇ§¼Ô¤Ï¡¢¿®Íê¤Ç¤¤Ê¤¤¥½¡¼¥¹¤«¤éSQLʸ¤ò½àÈ÷¤¹¤ë¤È¤¤Ë¡¢SQLʸ¤¬É½¼¨¤òµö²Ä¤µ¤ì¤Æ¤¤¤Ê¤¤¥Ç¡¼¥¿¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¤·¤¿¤ê¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë»³²¤òÍ¿¤¨¤ë°°Õ¤Î¤¢¤ëʸ¤ò¼Â¹Ô¤·¤è¤¦¤È¤·¤¿¤ê¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¤¿¤á¤Ë»ÈÍѤµ¤ì¤Þ¤¹¡£
¤¿¤È¤¨¤Ð¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë¤è¤ëɾ²Á¤Î¤¿¤á¤Ë¥æ¡¼¥¶¡¼¤¬Ç¤°Õ¤ÎSQLÌä¹ç¤»¤òÆþÎϤǤ¤ë¤è¤¦¤Ë¤¹¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹¡£
¤¿¤À¤·¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢¥æ¡¼¥¶¡¼¤¬¥Ç¡¼¥¿¥Ù¡¼¥¹¤ËǤ°Õ¤ÎÊѹ¹¤ò²Ã¤¨¤é¤ì¤Ê¤¤¤è¤¦¤Ë¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
¾µÇ§¼Ô¤Ï¡¢SELECTʸ°Ê³°¤Î¤¹¤Ù¤Æ¤ò¶Ø»ß¤¹¤ë¥æ¡¼¥¶¡¼ÆþÎÏSQL¤¬½àÈ÷¤µ¤ì¤Æ¤¤¤ë´Ö¤ËÇÛÃ֤Ǥ¤Þ¤¹¡£
(TBR)
=begin original
The callback will be called as
=end original
¥³¡¼¥ë¥Ð¥Ã¥¯¤Ï¼¡¤Î¤è¤¦¤Ë¸Æ¤Ó½Ð¤µ¤ì¤Þ¤¹¡£
(TBR)
$code_ref->($action_code, $string1, $string2, $database, $trigger_or_view)
=begin original
where
=end original
¤³¤³¤Ç
(TBR)
=over
=item $action_code
=begin original
is an integer that specifies what action is being authorized
(see L"Action Codes">).
=end original
¤Ï¡¢µö²Ä¤µ¤ì¤Æ¤¤¤ë¥¢¥¯¥·¥ç¥ó¤ò»ØÄꤹ¤ëÀ°¿ô¤Ç¤¹(L"Action Codes">¤ò»²¾È)¡£
(TBR)
=item $string1, $string2
=begin original
are strings that depend on the action code
(see L"Action Codes">).
=end original
¤Ï¡¢¥¢¥¯¥·¥ç¥ó¥³¡¼¥É¤Ë°Í¸¤¹¤ëʸ»úÎó¤Ç¤¹(L"Action Codes">¤ò»²¾È)¡£
(TBR)
=item $database
=begin original
is the name of the database (C, C, etc.) if applicable.
=end original
¤Ï¡¢¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î̾Á°¤Ç¤¹(C¡¢C¤Ê¤É)¡£
(TBR)
=item $trigger_or_view
=begin original
is the name of the inner-most trigger or view that is responsible for
the access attempt, or C if this access attempt is directly from
top-level SQL code.
=end original
¤Ï¡¢¥¢¥¯¥»¥¹»î¹Ô¤Î¸¶°ø¤È¤Ê¤Ã¤¿ºÇ¤âÆ⦤Υȥꥬ¤Þ¤¿¤Ï¥Ó¥å¡¼¤Î̾Á°¤Ç¤¹¡£
¥¢¥¯¥»¥¹»î¹Ô¤¬¥È¥Ã¥×¥ì¥Ù¥ë¤ÎSQL¥³¡¼¥É¤«¤éľÀܹԤï¤ì¤¿¾ì¹ç¤Ï¡¢C¤Ç¤¹¡£
(TBR)
=back
=head2 $dbh->sqlite_backup_from_file( $filename )
=begin original
This method accesses the SQLite Online Backup API, and will take a backup of
the named database file, copying it to, and overwriting, your current database
connection. This can be particularly handy if your current connection is to the
special :memory: database, and you wish to populate it from an existing DB.
=end original
¤³¤Î¥á¥½¥Ã¥É¤ÏSQLite Online Backup API¤Ë¥¢¥¯¥»¥¹¤·¡¢»ØÄꤵ¤ì¤¿¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×¤ò¼èÆÀ¤·¡¢¸½ºß¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹Àܳ¤Ë¥³¥Ô¡¼¤·¤Æ¾å½ñ¤¤·¤Þ¤¹¡£
¤³¤ì¤Ï¡¢¸½ºß¤ÎÀܳ¤¬ÆÃÊ̤Ê:memory:¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ç¤¢¤ê¡¢´û¸¤ÎDB¤«¤é¥Ç¡¼¥¿¤òÆþÎϤ¹¤ë¾ì¹ç¤ËÆäËÊØÍø¤Ç¤¹¡£
(TBR)
=head2 $dbh->sqlite_backup_to_file( $filename )
=begin original
This method accesses the SQLite Online Backup API, and will take a backup of
the currently connected database, and write it out to the named file.
=end original
¤³¤Î¥á¥½¥Ã¥É¤ÏSQLite Online Backup API¤Ë¥¢¥¯¥»¥¹¤·¡¢¸½ºßÀܳ¤µ¤ì¤Æ¤¤¤ë¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×¤ò¼èÆÀ¤·¤Æ¡¢»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ë½ñ¤½Ð¤·¤Þ¤¹¡£
(TBR)
=head2 $dbh->sqlite_enable_load_extension( $bool )
=begin original
Calling this method with a true value enables loading (external)
sqlite3 extensions. After the call, you can load extensions like this:
=end original
trueÃͤò»ØÄꤷ¤Æ¤³¤Î¥á¥½¥Ã¥É¤ò¸Æ¤Ó½Ð¤¹¤È¡¢(³°Éô)sqlite3³ÈÄ¥µ¡Ç½¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¸Æ¤Ó½Ð¤·¸å¡¢¼¡¤Î¤è¤¦¤Ë³ÈÄ¥µ¡Ç½¤òÆɤ߹þ¤à¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
(TBR)
$dbh->sqlite_enable_load_extension(1);
$sth = $dbh->prepare("select load_extension('libsqlitefunctions.so')")
or die "Cannot prepare: " . $dbh->errstr();
=head1 DRIVER CONSTANTS
=begin original
A subset of SQLite C constants are made available to Perl,
because they may be needed when writing
hooks or authorizer callbacks. For accessing such constants,
the C module must be explicitly C