加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite3 使用

发布时间:2020-12-13 00:17:52 所属栏目:百科 来源:网络整理
导读:MDB提供了用o-c封装的访问sqlite3的方法,避免了在用O-c编程中夹杂C风格的代码(不是说不能使用,而是夹杂在一块代码风格不一致)。 以下记录使用过程中的一些心得:1创建,插入,更新和删除:使用executeUpdate方法,而查询则用executeQuery2 插入的数据
MDB提供了用o-c封装的访问sqlite3的方法,避免了在用O-c编程中夹杂C风格的代码(不是说不能使用,而是夹杂在一块代码风格不一致)。
 
以下记录使用过程中的一些心得:
1创建,插入,更新和删除:使用executeUpdate方法,而查询则用executeQuery
2 插入的数据一律用oc中的对象类型:比如某列是double,插入的时候要用NSNumber对象
3 查询结果的显示:用stringForColumn,dateForColumn等等
4出错处理:[db hadError]来判断是否有错;[db lastErrorCode],[db lastErrorMessage]来查看出错类型和说明
5时间:对于事件类型,可以制定为double
以上是迄今遇到的一些问题,权且记录。
 
另sqlite3中时间函数:
datetime()/datetime('now')显示的是零时区的时间,"YYYY-MM-DD HH:MM:SS"
如果要获得当前时区的可以 datetime('now','localtime')
如果知道是哪个时区的:datetime('now','-3 hours')
其它的时间函数:(摘自官网)
 
date(timestring,modifier,...)
time(timestring,...)
julianday(timestring,...)
strftime(format,timestring,...)
 
 
 
Examples
Compute the current date.
 
SELECT date('now');
Compute the last day of the current month.
SELECT date('now','start of month','+1 month','-1 day');
Compute the date and time given a unix timestamp 1092941466.
SELECT datetime(1092941466,'unixepoch');
Compute the date and time given a unix timestamp 1092941466,and compensate for your local timezone.
SELECT datetime(1092941466,'unixepoch','localtime');
Compute the current unix timestamp.
SELECT strftime('%s','now');
Compute the number of days since the signing of the US Declaration of Independence.
SELECT julianday('now') - julianday('1776-07-04');
Compute the number of seconds since a particular moment in 2004:
SELECT strftime('%s','now') - strftime('%s','2004-01-01 02:34:56');
Compute the date of the first Tuesday in October for the current year.
SELECT date('now','start of year','+9 months','weekday 2');
Compute the time since the unix epoch in seconds (like strftime('%s','now') except includes fractional part):
SELECT (julianday('now') - 2440587.5)*86400.0;
 
转自:http://www.cnblogs.com/scorpiozj/archive/2011/01/20/1940220.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读