Sqlite实现默认时间为当前时间列的方法
在SQL Server中,创建表格的时候,对于时间列有时候我们可以根据需要指定默认值为当前时间(也就是说记录生成的时候有默认的时间戳)。例如:
create table log(
content varchar(256),
logtime datetime default getdate()
)
然而在Sqlite中如何实现呢?查文档得知Sqlite中并没有getdate()函数,但其系统内置函数有datetime(),因此能不能按照下面的写法实现默认时间戳呢:
create table log(
content varchar(256),
logtime datetime default datetime('now')
)
答案是否定的,会提示语法错误。那么应该如何声明呢?如下所示:
create table log(
content varchar(256),
logtime TIMESTAMP default CURRENT_TIMESTAMP
)
这个可以达到效果,但是默认的时间是以格林尼治标准时间为基准的,因此在中国使用的话会正好早8个小时。为了解决这个问题,我们可以这样声明:
create table log(
content varchar(256),
logtime TIMESTAMP default (datetime('now', 'localtime'))
)
测试一下,一切正常:)
相关文档:
最近由于项目需要, 要在wince4.2, wince5.0, mobile三种机型上面做大数据量的查询,初步估计在50W-500W条记录之间。
由于以前做mobile5的数据库项目主要是采用C#来写,而且数据量也顶多几万条,所以,为了确保项目后期少走弯路,我特意做了一下移动数据库性能测试。下面是这周的工作记录。供大家参考。
一. 由于wince4.2 ......
1. SQLite Database Browser 是一个SQLite数据库管理工具。是开源的、免费的。
Home Page
http://sqlitebrowser.sourceforge.net/
Download
http://sourceforge.net/project/showfiles.php?group_id=87946
Wiki
http://en.wikipedia.org/wiki/SQLite_Database_Browser
2.  ......
这些天一直在忙销售管理软件易卖通客户端的程序编写,由于需要采用本地数据缓存机制来提高程序的数据访问效率,所以需要在客户端使用一个小巧的本地数据库。这个数据库当然要小而精悍的。我也不想做强盗,于是就选择Sqlite吧——文件数据库,只要一个Sqlite.dll就可以操作数据库。
不得不趁人本人是有点偷懒,Ad ......
SQLite Tutorial in PHP
SQLite is an SQL database manager used locally or on a website, and compatible
in particularly with PHP.
Summary
Installing SQLite and creating a database
.
Installing SQLite. Verifying the installation by creating a base.
Creating and using a SQLite tabl ......
使用版本:sqlite-3.6.14.2
下载地址:http://www.sqlite.org/sqlite-3.6.14.2.tar.gz
首先参考readme的提示:
“
tar xzf sqlite.tar.gz ;# Unpack the source tree into "sqlite"
mkdir bld &nbs ......