summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2021-09-12 11:34:50 -0700
committerlshprung <lshprung@yahoo.com>2021-09-12 11:34:50 -0700
commit7b6dfdf08f6e81bdf0cec9bc4157c12334c64898 (patch)
tree50a0ccfd1d9941f833af76d41eeb7a244dda1dfa
parent74ae4b9cf4ae0e56125b0414a62e38ffed8ca19b (diff)
Fixed issue with db_cmd wrapper and append flag
-rw-r--r--.gitignore1
-rwxr-xr-xbuild_db.plx24
-rw-r--r--shared.pl24
3 files changed, 29 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index f89bba4..aa349a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
!.gitignore
!build_db.plx
+!shared.pl
diff --git a/build_db.plx b/build_db.plx
index b9bca12..e98423a 100755
--- a/build_db.plx
+++ b/build_db.plx
@@ -7,6 +7,8 @@ use DBI;
use Audio::Scan;
use File::HomeDir;
+require "./shared.pl";
+
# Keep track of columns that need to be created in the database
our %columns;
@@ -64,24 +66,6 @@ sub build_extension_hash {
}
}
-# Wrapper to handle sqlite commands
-# @_[0] -> database handle
-# @_[1] -> command/statement
-# @_[2] (optional) -> output statement
-sub db_cmd {
- my $rv = $_[0]->do($_[1]);
- if ($rv < 0){
- die $DBI::errstr;
- }
-
- # DEBUG
- if (!$options{quiet} and defined $_[2]){
- print "$_[2]\n";
- }
-
- return $rv;
-}
-
# Scan a directory recursively, return an array of files (optionally, matching a certain file extension or extensions)
# @_[0] -> $music_dir
@@ -252,8 +236,8 @@ if (!$options{append}){
# If appending, add columns where necessary
else {
for my $i (sort(keys %columns)){
- $statement = "SELECT COUNT(*) AS CNTREC FROM pragma_table_info('$table_name') WHERE name=\"$i\";";
- if (db_cmd($dbh, $statement) > 0){
+ $statement = "SELECT COUNT(*) AS CNTREC FROM pragma_table_info('$table_name') WHERE name='$i';";
+ if (db_cmd($dbh, $statement) == 0){
$statement = "ALTER TABLE $table_name ADD COLUMN \"$i\";";
db_cmd($dbh, $statement);
}
diff --git a/shared.pl b/shared.pl
new file mode 100644
index 0000000..ea2fdfd
--- /dev/null
+++ b/shared.pl
@@ -0,0 +1,24 @@
+# File to hold shared variables and subroutines
+
+
+# Wrapper to handle sqlite commands, return an array of returned lines from sqlite output
+# @_[0] -> database handle
+# @_[1] -> command/statement
+# @_[2] (optional) -> output statement
+sub db_cmd {
+ my $sth = $_[0]->prepare($_[1]);
+
+ if ($sth->execute < 0){
+ die $DBI::errstr;
+ }
+
+ # DEBUG
+ if (!$options{quiet} and defined $_[2]){
+ print "$_[2]\n";
+ }
+
+ # Build output array
+ return($sth->fetchrow_array);
+}
+
+1;