我的项目有schema.sql
,其中包含用于设置我的sqlite3数据库的CREATE TABLE
语句,但我似乎无法弄清楚如何从Racket运行此文件。我收到以下错误消息:
; query-exec: multiple statements given
; value: "CREATE TABLE IF NOT EXISTS pet (\n id INTEGER PRIMARY KEY,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n owner_id REFERENCES owner(id) NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS owner (\n id INTEGER PRIMARY KEY,\n name TEXT NOT NULL\n);\n"
; Context:
; /usr/share/racket/collects/db/private/sqlite3/connection.rkt:208:4 prepare1* method in connection%
; /usr/share/racket/collects/db/private/sqlite3/connection.rkt:137:4 check-statement method in connection%
; /usr/share/racket/collects/db/private/sqlite3/connection.rkt:73:4 query1 method in connection%
; /usr/share/racket/collects/db/private/generic/functions.rkt:217:0 query-exec
; /home/winston/code/example-db-racket/main.rkt:1:1 [running body]
; [Due to errors, REPL is just module language, requires, and stub definitions]
有没有办法用db
包运行多个语句?
#lang racket
(require db)
(define database
(sqlite3-connect #:database "database.sqlite3" #:mode 'create))
(define schema
(call-with-input-file "schema.sql" port->string))
(query-exec database schema)
CREATE TABLE IF NOT EXISTS pet (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
kind TEXT NOT NULL,
owner_id REFERENCES owner(id) NOT NULL
);
CREATE TABLE IF NOT EXISTS owner (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);