Racket的sql模块提供create-table作为CREATE TABLE sql语句的抽象。
我应该如何使用AUTO INCREMENT提供列(即ID)的说明?
当我尝试
(create-table numbers
#:columns [n integer #:not-null #:auto-increment] [t text]
#:constraints (primary-key n))
然后显示错误:
create-table: unexpected term
parsing context:
while parsing ColumnDef
while parsing CreateTableInner in: #:auto-increment
是否可以在create-table中指定自动递增列?
答案 0 :(得分:0)
据我所知,create-table
包中的sql
无法处理auto-increment
。
而是考虑直接使用query-exec
。这是罗塞塔代码的片段。
#lang at-exp racket
(require db)
(define postal (sqlite3-connect #:database "/tmp/postal.db" #:mode 'create))
(define (add! name street city state zip)
(query-exec postal
@~a{INSERT INTO addresses (name, street, city, state, zip)
VALUES (?, ?, ?, ?, ?)}
name street city state zip))
(unless (table-exists? postal "addresses")
(query-exec postal
@~a{CREATE TABLE addresses(
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
street TEXT NOT NULL,
city TEXT NOT NULL,
state TEXT NOT NULL,
zip TEXT NOT NULL)}))
在此处查看更多信息:https://rosettacode.org/wiki/Table_creation/Postal_addresses#Racket