scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 125  →  ?path2? @ 126
/file.php
@@ -96,32 +96,27 @@
## If we have any tags then insert them into the database.
if(!empty($tags)) {
## Connect or create the scratch database.
$db = new PDO('sqlite:db/scratch.sqlite3');
## Set the error mode to exceptions.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
## Connect or create the scratch database.
$db = new PDO('sqlite:db/scratch.sqlite3');
## Set the error mode to exceptions.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
## Begin the transaction
$db->beginTransaction();
## Create the tags table if it does not exist.
## Create tags table if it does not exist.
$db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)');
## Insert all the tags for the file.
## Now add all the tags.
foreach($tags as $tag) {
$q = $db->prepare("INSERT INTO tags(hash, tag) VALUES(:hash, :tag)");
$q->execute(
array(
':hash' => $file,
':name' => $tag
)
);
$q = $db->prepare('REPLACE INTO "tags" ("hash", "tag") VALUES(:hash, :tag)');
$q->bindParam(':hash', $file);
$q->bindParam(':tag', $tag);
$q->execute();
}
## Commit the transaction.
$db->commit();
} catch (Exception $e) {
error_log($e);
## Rollback.
$db->rollback();
}