From 19774260f79072ee0559972d36fbfe3e1e4a0744 Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Sat, 27 Aug 2011 03:01:19 -0600 Subject: [PATCH] improve Continue db code: use table-exists? instead of catch all exn? --- collects/web-server/scribblings/tutorial/continue.scrbl | 8 +++++--- .../web-server/scribblings/tutorial/examples/model-3.rkt | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/collects/web-server/scribblings/tutorial/continue.scrbl b/collects/web-server/scribblings/tutorial/continue.scrbl index 44bea82d9f..d91f2c2af5 100644 --- a/collects/web-server/scribblings/tutorial/continue.scrbl +++ b/collects/web-server/scribblings/tutorial/continue.scrbl @@ -975,7 +975,8 @@ following to the top of our model: We will use the following bindings from the @racketmodname[db] library: @racket[connection?], @racket[sqlite3-connect], -@racket[query-exec], @racket[query-list], and @racket[query-value]. +@racket[table-exists?], @racket[query-exec], @racket[query-list], and +@racket[query-value]. The first thing we should do is decide on the relational structure of our model. We will use the following tables: @@ -1011,7 +1012,7 @@ We can now write the code to initialize a @racket[blog] structure: (define (initialize-blog! home) (define db (sqlite3-connect #:database home #:mode 'create)) (define the-blog (blog db)) - (with-handlers ([exn? void]) + (unless (table-exists? db "posts") (query-exec db (string-append "CREATE TABLE posts " @@ -1019,7 +1020,8 @@ We can now write the code to initialize a @racket[blog] structure: (blog-insert-post! the-blog "First Post" "This is my first post") (blog-insert-post! - the-blog "Second Post" "This is another post") + the-blog "Second Post" "This is another post")) + (unless (table-exists? db "comments") (query-exec db "CREATE TABLE comments (pid INTEGER, content TEXT)") (post-insert-comment! diff --git a/collects/web-server/scribblings/tutorial/examples/model-3.rkt b/collects/web-server/scribblings/tutorial/examples/model-3.rkt index 19eb63e21c..9bcd48322e 100644 --- a/collects/web-server/scribblings/tutorial/examples/model-3.rkt +++ b/collects/web-server/scribblings/tutorial/examples/model-3.rkt @@ -14,7 +14,7 @@ (define (initialize-blog! home) (define db (sqlite3-connect #:database home #:mode 'create)) (define the-blog (blog db)) - (with-handlers ([exn? void]) + (unless (table-exists? db "posts") (query-exec db (string-append "CREATE TABLE posts " @@ -22,7 +22,8 @@ (blog-insert-post! the-blog "First Post" "This is my first post") (blog-insert-post! - the-blog "Second Post" "This is another post") + the-blog "Second Post" "This is another post")) + (unless (table-exists? db "comments") (query-exec db "CREATE TABLE comments (pid INTEGER, content TEXT)") (post-insert-comment!