scratch – Diff between revs 125 and 126

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 125 Rev 126
Line 94... Line 94...
94 ) 94 )
95 ); 95 );
Line 96... Line 96...
96 96
97 ## If we have any tags then insert them into the database. 97 ## If we have any tags then insert them into the database.
98 if(!empty($tags)) { -  
99 try { 98 if(!empty($tags)) {
100 ## Connect or create the scratch database. 99 ## Connect or create the scratch database.
101 $db = new PDO('sqlite:db/scratch.sqlite3'); 100 $db = new PDO('sqlite:db/scratch.sqlite3');
102 ## Set the error mode to exceptions. 101 ## Set the error mode to exceptions.
-   102 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Line 103... Line -...
103 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -  
104 103 try {
Line 105... Line 104...
105 ## Begin the transaction 104
106 $db->beginTransaction(); 105 $db->beginTransaction();
Line 107... Line 106...
107 106
108 ## Create the tags table if it does not exist. 107 ## Create tags table if it does not exist.
109 $db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)'); 108 $db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)');
110 -  
111 ## Insert all the tags for the file. -  
112 foreach($tags as $tag) { 109
113 $q = $db->prepare("INSERT INTO tags(hash, tag) VALUES(:hash, :tag)"); 110 ## Now add all the tags.
114 $q->execute( -  
115 array( 111 foreach($tags as $tag) {
116 ':hash' => $file, 112 $q = $db->prepare('REPLACE INTO "tags" ("hash", "tag") VALUES(:hash, :tag)');
117 ':name' => $tag -  
118 ) -  
119 ); 113 $q->bindParam(':hash', $file);
120 } 114 $q->bindParam(':tag', $tag);
-   115 $q->execute();
121 116 }
122 ## Commit the transaction. 117 $db->commit();
123 $db->commit(); 118 } catch (Exception $e) {
124 } catch (Exception $e) { 119 error_log($e);
125 ## Rollback. 120 ## Rollback.