summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlshprung <lshprung@yahoo.com>2021-09-15 17:23:38 -0700
committerlshprung <lshprung@yahoo.com>2021-09-15 17:23:38 -0700
commitec07b105fed222b737ba2a69d380c3adb841e0cf (patch)
tree068dd196fa033a22c0e07b2a5289cd003c1d4a09
parente7ba8b935bcc8bc956629b2332f9214e2cac57d0 (diff)
PATH column is unique
-rwxr-xr-xbuild_db.plx10
1 files changed, 7 insertions, 3 deletions
diff --git a/build_db.plx b/build_db.plx
index 7bb6072..1b01b58 100755
--- a/build_db.plx
+++ b/build_db.plx
@@ -205,7 +205,7 @@ if (!$options{append}){
# Need to create additional columns for ID and PATH
$statement = "CREATE TABLE $table_name
(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
- PATH TEXT NOT NULL";
+ PATH TEXT NOT NULL UNIQUE";
for my $i (sort(keys %columns)){
$statement = $statement . ",
\"$i\" TEXT";
@@ -215,7 +215,6 @@ if (!$options{append}){
}
# If appending, add columns where necessary
-# FIXME add check to avoid duplicate rows with the same PATH
else {
for my $i (sort(keys %columns)){
$statement = "SELECT COUNT(*) AS CNTREC FROM pragma_table_info('$table_name') WHERE name='$i';";
@@ -231,7 +230,12 @@ else {
$statement = "INSERT INTO $table_name(PATH)
VALUES";
for my $file (@file_list){
- $statement = $statement . "(\"$file\"),";
+ # Skip existing files
+ @db_output = flatten_array(db_cmd($dbh, "SELECT count(*) FROM $table_name WHERE PATH='$file';"));
+
+ if(!$db_output[0]){
+ $statement = $statement . "(\"$file\"),";
+ }
}
$statement =~ s/[,]$/;/g;
db_cmd($dbh, $statement);