SQLiteÖеÄʱ¼äÈÕÆÚº¯Êý
SQLite°üº¬ÁËÈçÏÂʱ¼ä/ÈÕÆÚº¯Êý£º
datetime().......................²úÉúÈÕÆÚºÍʱ¼ä
date()...........................²úÉúÈÕÆÚ
time()...........................²úÉúʱ¼ä
strftime().......................¶ÔÒÔÉÏÈý¸öº¯Êý²úÉúµÄÈÕÆÚºÍʱ¼ä½øÐиñʽ»¯
datetime()µÄÓ÷¨ÊÇ£ºdatetime(ÈÕÆÚ/ʱ¼ä,ÐÞÕý·û,ÐÞÕý·û...)
date()ºÍtime()µÄÓï·¨Óëdatetime()Ïàͬ¡£
ÔÚʱ¼ä/ÈÕÆÚº¯ÊýÀï¿ÉÒÔʹÓÃÈçϸñʽµÄ×Ö·û´®×÷Ϊ²ÎÊý£º
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
ÆäÖÐnowÊDzúÉúÏÖÔÚµÄʱ¼ä¡£
¾ÙÀý£¨Ð´Õâ¸ö±Ê¼ÇµÄʱ¼äÊÇ2006Äê10ÔÂ17ÈÕÍí8µãµ½10µã£¬²âÊÔ»·¾³£ºSQLite 2.8.17£¬WinXP£¬±±¾©Ê±¼ä£©£º
Àý1.
select datetime('now');
½á¹û£º2006-10-17 12:55:54
Àý2.
select datetime('2006-10-17');
½á¹û£º2006-10-17 12:00:00
Àý3.
select datetime('2006-10-17 00:20:00','+1 hour','-12 minute');
½á¹û£º2006-10-17 01:08:00
Àý4.
select date('2006-10-17','+1 day','+1 year');
½á¹û£º2007-10-18
Àý5.
select datetime('now','start of year');
½á¹û£º2006-01-01 00:00:00
Àý6.
select datetime('now','start of month');
½á¹û£º2006-10-01 00:00:00
Àý7.
select datetime('now','start of day');
½á¹û£º2006-10-17 00:00:00
Àý8.
select datetime('now','+10 hour','start of day','+10 hour');
½á¹û£º2006-10-17 10:00:00
Àý9.
select datetime('now','localtime');
½á¹û£º2006-10-17 21:21:47
Àý10.
select datetime('now','+8 hour');
½á¹û£º2006-10-17 21:24:45
Àý3ÖеÄ+1 hourºÍ-12 minute±íʾ¿ÉÒÔÔÚ»ù±¾Ê±¼äÉÏ£¨datetimeº¯ÊýµÄµÚÒ»¸ö²ÎÊý£©Ôö¼Ó»ò¼õÉÙÒ»¶¨Ê±¼ä¡£
Àý5ÖеÄstart of year±íʾһÄ꿪ʼµÄʱ¼ä¡£
´ÓÀý8¿ÉÒÔ¿´³ö£¬¾¡¹ÜµÚ2¸ö²ÎÊý¼ÓÉÏÁË10¸öСʱ£¬µ«ÊÇÈ´±»µÚ3¸ö²ÎÊý“start of day”°Ñʱ¼ä¹éÁãµ½00:00:00£¬ËæºóµÄµÚ4¸ö²ÎÊýÔÚ00:00:00
µÄ»ù´¡ÉÏ°Ñʱ¼äÔö¼ÓÁË10¸öСʱ±ä³ÉÁË10:00:00¡£
Àý9°Ñ¸ñÁÖÍþÖÎʱÇøת»»³É±¾µØʱÇø¡£
Àý10°Ñ¸ñÁÖÍþÖÎʱÇøת»»³É¶«°ËÇø¡£
strftime()º¯Êý¿ÉÒÔ°ÑYYYY-MM-DD HH:MM:SS¸ñʽµÄÈÕÆÚ×Ö·û´®×ª»»³ÉÆäËüÐÎʽµÄ×Ö·û´®¡£
strftime()µÄÓï·¨ÊÇstrftime(¸ñʽ, ÈÕÆÚ/ʱ¼ä, ÐÞÕý·û, ÐÞÕý·û, ...)
Ëü¿ÉÒÔÓÃÒÔϵķûºÅ¶ÔÈÕÆÚºÍʱ¼ä½øÐиñʽ»¯£º
%d Ô·Ý, 01-31
%f СÊýÐÎʽµÄÃ룬SS.SSS
Ïà¹ØÎĵµ£º
import os
import unittest # °üº¬µ¥Ôª²âÊÔÄ£¿é
import sqlite3 as sqlite # °üº¬sqlite3Ä£¿é
def get_db_path():
return "sqlite_testdb"
class TransactionTests(unittest.TestCase): # µ¥Ôª²âÊÔµÚÒ»²½:¡¡ÓÉTestCaseÅÉÉúÀà
def setUp(self): # µ¥Ôª²âÊÔ»·¾³ÅäÖÃ
......
1¡£´Ówww.sqlite.orgÏÂÔØSQLite 3.3.4µÄ°æ±¾
ΪÁË·½±ã£¬ÎÒ°ÑËü½âѹÁË£¬¾ÍÒ»¸öSQLite3.exe£¬·ÅÈëWindowsĿ¼Ï¡£
Cmd ½øÈëÃüÁîÐÐ
1)
´´½¨Êý¾Ý¿âÎļþ:
>SQLite3 d:\test.db »Ø³µ
¾ÍÉú³ÉÁËÒ»¸ötest.dbÔÚdÅÌ¡£
ÕâÑùͬʱҲSQLite3¹ÒÉÏÁËÕâ¸ötest.db
2)
ÓÃ.help¿ÉÒÔ¿´¿´ÓÐʲôÃüÁî
>.help »Ø³µ¼´¿É
3)¿ÉÒ ......
×Ô¼¸Ê®ÄêÇ°³öÏÖµÄÉÌÒµÓ¦ÓóÌÐòÒÔÀ´£¬Êý¾Ý¿â¾Í³ÉΪÈí¼þÓ¦ÓóÌÐòµÄÖ÷Òª×é³É²¿·Ö¡£ÕýÓëÊý¾Ý¿â¹ÜÀíϵͳ·Ç³£¹Ø¼üÒ»Ñù£¬ËüÃÇÒ²±äµÃ·Ç³£ÅӴ󣬲¢Õ¼ÓÃÁËÏ൱¶àµÄϵ
ͳ×ÊÔ´£¬Ôö¼ÓÁ˹ÜÀíµÄ¸´ÔÓÐÔ¡£Ëæ×ÅÈí¼þÓ¦ÓóÌÐòÖð½¥Ä£¿éÄ£¿é»¯£¬Ò»ÖÖÐÂÐÍÊý¾Ý¿â»á±È´óÐ͸´ÔӵĴ«Í³Êý¾Ý¿â¹ÜÀíϵͳ¸üÊÊÓ¦¡£Ç¶ÈëʽÊý¾Ý¿âÖ±½ÓÔÚÓ¦ÓóÌÐò½ø³Ì
ÖÐ ......
×î½üÔÚÏîÄ¿ÖÐÓõ½ÁËSQLite¡£Ö÷ÒªÊÇ¿Í»§¶ËÓõ½£¬ÕâÖÖСÐÍÄÚǶÊý¾Ý¿â»¹ÊÇÂùʵÓõġ£
ÌáÆðSQLiteÎÒ²»×Ô¾õµÄ¾ÍÏëÆðÁË΢Èí³öµÄACCESS¡£ËûÃÇÁ½¸öȷʵÊÇÓпɱÈÐԵġ£Ôø¾£¬Ð¡ÐÍÍøÕ¾Êý¾Ý¿â£¬ASP¿ÉÒÔÓõ½ACCESS¡£µ«ÊÇ£¬PHPÈ´ÊÇûÓÐÏà¶ÔÓ¦µÄ½â¾ö·½°¸£¬×Ô´ÓSQLiteµÄ³öÏÖ£¬¸øPHPÌṩÁËÒ»¸ö½â¾ö·½°¸¡£
ÔÚ¿Í»§¶ËÀïÃ棬ÎÒÓõ½µÄÊý¾Ý±£ ......
sqlite¹Ù·½Õ¾
http://www.sqlite.org/
SQL Syntax
http://www.sqlite.org/lang.html
sqliteÖÐÎÄÕ¾
http://www.sqlite.com.cn/
http://www.sqlitechina.org/
½¨Á¢Êý¾Ý¿âµµ°¸
ÓÃsqlite3½¨Á¢Êý¾Ý¿âµÄ·½·¨ºÜ¼òµ¥£¬Ö»ÒªÔÚshellϼüÈ루ÒÔÏÂ$·ûºÅΪshellÌáʾºÅ£¬ÇëÎð¼üÈ룩£º
$ sqlite3 foo.db
Èç¹ûĿ¼ÏÂûÓÐfo ......