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'))
)
测试一下,一切正常:)
相关文档:
这是一个有关分页的实例,仅供参考(代码来自网络)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Threading;
using System.Collections;
us ......
// sqlite解决中文路径问题,以前研究sqlite时候遇到的中文路径问题的解决方法
// AnsiString cb中的字符串类,其它编译器用std::string替换即可.
// MultiByteToWideChar是windows api
AnsiString fileName;
int strSize = fileName.Length();
char *ansi = new char[strSize+1];
wchar_t *unico ......
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 ......
从网上找的例子,创建了一个数据库,追加了几条记录后,然后关闭数据库,然后准备向PDA下载数据库,发现文件竟然被占用了,已经关闭了数据库连接也无效,后来从网上看到需要清除连接池
using (SQLiteConnection cn = new SQLiteConnection("Data Source=" + strTempPath + "\\Smoke.db3;Pooling=true;FailIfMissing=false ......