aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar tfarina <tfarina@chromium.org>2014-09-30 08:17:10 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-30 08:17:11 -0700
commitfffa16cc277c286687b0f42a7cc87217dd94938e (patch)
tree3ca907bb6e5efb91a7d54f86cf2b053c75839514 /experimental
parent1b466f7e21004257afeb35cd008768e3b541dca9 (diff)
webtry: Only create sqlite3 tables if they don't exist yet.
Otherwise it will through an error like the following: 2014/09/28 21:22:24 Info: status creating sqlite table for sources: "table source_images already exists" 2014/09/28 21:22:24 Info: status creating sqlite table for webtry: "table webtry already exists" 2014/09/28 21:22:24 Info: status creating sqlite table for workspace: "table workspace already exists" 2014/09/28 21:22:24 Info: status creating sqlite table for workspace try: "table workspacetry already exists" To test locally the following was done: $ ./gyp_skia gyp/webtry.gyp gyp/most.gyp -Dskia_gpu=0 $ ninja -C out/Debug webtry $ cd experimental/webtry $ go get -d $ go build webtry.go $ ./webtry $ google-chrome http://localhost:8000 Expected: see no more the above messages. BUG=None TEST=see above R=stephana@google.com, jcgregorio@google.com Author: tfarina@chromium.org Review URL: https://codereview.chromium.org/613593002
Diffstat (limited to 'experimental')
-rw-r--r--experimental/webtry/webtry.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go
index fd512de9d8..a4fe9e0ef5 100644
--- a/experimental/webtry/webtry.go
+++ b/experimental/webtry/webtry.go
@@ -238,7 +238,7 @@ func init() {
log.Printf("ERROR: Failed to open: %q\n", err)
panic(err)
}
- sql := `CREATE TABLE source_images (
+ sql := `CREATE TABLE IF NOT EXISTS source_images (
id INTEGER PRIMARY KEY NOT NULL,
image MEDIUMBLOB DEFAULT '' NOT NULL, -- formatted as a PNG.
width INTEGER DEFAULT 0 NOT NULL,
@@ -247,9 +247,11 @@ func init() {
hidden INTEGER DEFAULT 0 NOT NULL
)`
_, err = db.Exec(sql)
- log.Printf("Info: status creating sqlite table for sources: %q\n", err)
+ if err != nil {
+ log.Printf("Info: status creating sqlite table for sources: %q\n", err)
+ }
- sql = `CREATE TABLE webtry (
+ sql = `CREATE TABLE IF NOT EXISTS webtry (
code TEXT DEFAULT '' NOT NULL,
create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
hash CHAR(64) DEFAULT '' NOT NULL,
@@ -258,17 +260,21 @@ func init() {
PRIMARY KEY(hash)
)`
_, err = db.Exec(sql)
- log.Printf("Info: status creating sqlite table for webtry: %q\n", err)
+ if err != nil {
+ log.Printf("Info: status creating sqlite table for webtry: %q\n", err)
+ }
- sql = `CREATE TABLE workspace (
+ sql = `CREATE TABLE IF NOT EXISTS workspace (
name CHAR(64) DEFAULT '' NOT NULL,
create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY(name)
)`
_, err = db.Exec(sql)
- log.Printf("Info: status creating sqlite table for workspace: %q\n", err)
+ if err != nil {
+ log.Printf("Info: status creating sqlite table for workspace: %q\n", err)
+ }
- sql = `CREATE TABLE workspacetry (
+ sql = `CREATE TABLE IF NOT EXISTS workspacetry (
name CHAR(64) DEFAULT '' NOT NULL,
create_ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
hash CHAR(64) DEFAULT '' NOT NULL,
@@ -278,7 +284,9 @@ func init() {
FOREIGN KEY (name) REFERENCES workspace(name)
)`
_, err = db.Exec(sql)
- log.Printf("Info: status creating sqlite table for workspace try: %q\n", err)
+ if err != nil {
+ log.Printf("Info: status creating sqlite table for workspace try: %q\n", err)
+ }
}
// Ping the database to keep the connection fresh.