sqlite3插入动态表 [英] sqlite3 insert into dynamic table

查看:85
本文介绍了sqlite3插入动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用sqlite3(将来可能是sqlite4),并且我需要诸如动态表之类的东西. 我有许多具有相同格式的表:values_2012_12_27,values_2012_12_28,...(表的数量是动态的),我想动态选择接收某些数据的表.
我正在将_sqlite3_prepareINSERT INTO ? VALUES(?,?,?)一起使用.当然,这无法编译(语法错误在?附近).在sqlite中有一个很好的简单方法吗?

I am using sqlite3 (maybe sqlite4 in the future) and I need something like dynamic tables. I have many tables with the same format: values_2012_12_27, values_2012_12_28, ... (number of tables is dynamic) and I want to select dynamically the table that receives some data.
I am using _sqlite3_prepare with INSERT INTO ? VALUES(?,?,?). Ofcourse this fails to compile (syntax error near ?). There is a nice and simple way to do this in sqlite ?

谢谢

推荐答案

对于表或列名之类的标识符,无法使用SQL参数.

Using SQL parameters is not possible for identifiers such as table or column names.

如果您不想保留这么多准备好的语句,则在需要时随时进行准备.

If you don't want to keep so many prepared statements around, just prepare them on the fly whenever you need one.

如果数据库已正确规范化,则将只有一个大的values表,并带有一个额外的date列. 通常最好选择这种组织,除非您对两者进行了衡量,并且发现更好的性能(如果确实存在)超过了管理多个表的开销.

If your database were properly normalized, you would have a single big values table with an extra date column. This organization is usually to be preferred, unless you have measured both and found that the better performance (if it actually exists) outweighs the overhead of managing multiple tables.

这篇关于sqlite3插入动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆