mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
fetchmail.pl: add SQLite support
Accept $db_type = 'SQLite' with $db_name as the path to the database
file. SQLite has no now() or unix_timestamp(), so use strftime('%s', ...)
for the poll interval check and datetime('now') when storing the poll
time. Booleans are 1/0 on SQLite, the same as MySQL.
Requested in https://github.com/postfixadmin/postfixadmin/discussions/1197
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9e8c3d9c2a
commit
a2ee929eda
1 file changed
+11
-3
+11
-3
@@ -16,10 +16,11 @@ use LockFile::Simple qw(lock trylock unlock);
|
||||
# database backend - uncomment one of these
|
||||
our $db_type = 'Pg';
|
||||
#my $db_type = 'mysql';
|
||||
#my $db_type = 'SQLite';
|
||||
|
||||
# host name
|
||||
# host name (ignored for SQLite)
|
||||
our $db_host="127.0.0.1";
|
||||
# database name
|
||||
# database name (for SQLite: full path to the database file)
|
||||
our $db_name="postfix";
|
||||
# database username
|
||||
our $db_username="mail";
|
||||
@@ -87,6 +88,8 @@ if (-e $configfile) {
|
||||
|
||||
if($db_type eq "Pg" || $db_type eq "mysql") {
|
||||
$dsn = "DBI:$db_type:database=$db_name;host=$db_host";
|
||||
} elsif($db_type eq "SQLite") {
|
||||
$dsn = "DBI:SQLite:dbname=$db_name";
|
||||
} else {
|
||||
log_and_die "unsupported db_type $db_type";
|
||||
}
|
||||
@@ -107,8 +110,13 @@ if($db_type eq "Pg") {
|
||||
$sql_cond = "active = 't' AND date_part('epoch',now())-date_part('epoch',date)";
|
||||
} elsif($db_type eq "mysql") {
|
||||
$sql_cond = "active = 1 AND unix_timestamp(now())-unix_timestamp(date)";
|
||||
} elsif($db_type eq "SQLite") {
|
||||
$sql_cond = "active = 1 AND strftime('%s','now')-strftime('%s',date)";
|
||||
}
|
||||
|
||||
# SQLite has no now()
|
||||
$sql_now = ($db_type eq "SQLite") ? "datetime('now')" : "now()";
|
||||
|
||||
$sql = "
|
||||
SELECT id,mailbox,src_server,src_auth,src_user,src_password,src_folder,fetchall,keep,protocol,mda,extra_options,usessl, sslcertck, sslcertpath, sslfingerprint, src_port
|
||||
FROM fetchmail
|
||||
@@ -164,7 +172,7 @@ TXT
|
||||
|
||||
unlink $filename;
|
||||
|
||||
$sql="UPDATE fetchmail SET returned_text=".$dbh->quote($ret).", date=now() WHERE id=".$id;
|
||||
$sql="UPDATE fetchmail SET returned_text=".$dbh->quote($ret).", date=$sql_now WHERE id=".$id;
|
||||
$dbh->do($sql);
|
||||
}@{$dbh->selectall_arrayref($sql)};
|
||||
|
||||
|
||||
Reference in new issue
Block a user