| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
|
|
|
3 |
# sits@users.sourceforge.net
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and modify it under
|
|
|
6 |
# the terms of the GPL.
|
|
|
7 |
|
|
|
8 |
package Codestriker::DB::SQLite;
|
|
|
9 |
|
|
|
10 |
use strict;
|
|
|
11 |
use DBI;
|
|
|
12 |
use Codestriker;
|
|
|
13 |
use Codestriker::DB::Database;
|
|
|
14 |
|
|
|
15 |
# Module for handling a SQLite embedded database.
|
|
|
16 |
|
|
|
17 |
@Codestriker::DB::SQLite::ISA = ("Codestriker::DB::Database");
|
|
|
18 |
|
|
|
19 |
# Type mappings.
|
|
|
20 |
my $_TYPE = {
|
|
|
21 |
$Codestriker::DB::Column::TYPE->{TEXT} => "text",
|
|
|
22 |
$Codestriker::DB::Column::TYPE->{VARCHAR} => "varchar",
|
|
|
23 |
$Codestriker::DB::Column::TYPE->{INT32} => "integer",
|
|
|
24 |
$Codestriker::DB::Column::TYPE->{INT16} => "integer",
|
|
|
25 |
$Codestriker::DB::Column::TYPE->{DATETIME} => "datetime",
|
|
|
26 |
$Codestriker::DB::Column::TYPE->{FLOAT} => "numeric"
|
|
|
27 |
};
|
|
|
28 |
|
|
|
29 |
# Create a new SQLite database object.
|
|
|
30 |
sub new {
|
|
|
31 |
my $type = shift;
|
|
|
32 |
|
|
|
33 |
# Database is parent class.
|
|
|
34 |
my $self = Codestriker::DB::Database->new();
|
|
|
35 |
return bless $self, $type;
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
# Return the DBD module this is dependent on.
|
|
|
39 |
sub get_module_dependencies {
|
|
|
40 |
return { name => 'DBD::SQLite', version => '0' };
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
# Retrieve a database connection.
|
|
|
44 |
sub get_connection {
|
|
|
45 |
my $self = shift;
|
|
|
46 |
|
|
|
47 |
# SQLite supports transactions, don't enable auto_commit.
|
|
|
48 |
return $self->_get_connection(0, 1);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
# Return the mapping for a specific type.
|
|
|
52 |
sub _map_type {
|
|
|
53 |
my ($self, $type) = @_;
|
|
|
54 |
return $_TYPE->{$type};
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
# Autoincrement type for SQLite. No need to set this, as by default if
|
|
|
58 |
# no entry is set into an integer primary key field, it will act as an
|
|
|
59 |
# auto-increment field, provided it is the first column in a table.
|
|
|
60 |
sub _get_autoincrement_type {
|
|
|
61 |
return "";
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
# Indicate if the LIKE operator can be applied on a "text" field.
|
|
|
65 |
# For SQLite, this is true.
|
|
|
66 |
sub has_like_operator_for_text_field {
|
|
|
67 |
my $self = shift;
|
|
|
68 |
return 1;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
# Function for generating an SQL subexpression for a case insensitive LIKE
|
|
|
72 |
# operation.
|
|
|
73 |
sub case_insensitive_like {
|
|
|
74 |
my ($self, $field, $expression) = @_;
|
|
|
75 |
|
|
|
76 |
$expression = $self->{dbh}->quote($expression);
|
|
|
77 |
|
|
|
78 |
# SQLite is case insensitive by default, no need to do anything.
|
|
|
79 |
return "$field LIKE $expression";
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
1;
|