add libchat db
This commit is contained in:
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: create_table.py
|
||||
# Date: Wed Mar 25 16:43:22 2015 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
from libchat import SqliteLibChat
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Usage: {} <DB file name>"
|
||||
sys.exit()
|
||||
|
||||
db_name = sys.argv[1]
|
||||
|
||||
if os.path.exists(db_name):
|
||||
delete = raw_input("DB exists. Delete ? (y/n)")
|
||||
if delete == 'y':
|
||||
os.unlink(db_name)
|
||||
else:
|
||||
sys.exit()
|
||||
|
||||
db = SqliteLibChat(db_name)
|
||||
db.create()
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: libchat.py
|
||||
# Date: Wed Mar 25 16:43:40 2015 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
class SqliteLibChat(object):
|
||||
|
||||
def __init__(self, db_file):
|
||||
self.db_file = db_file
|
||||
self.conn = sqlite3.connect(db_file)
|
||||
|
||||
def create(self):
|
||||
c = self.conn.cursor()
|
||||
c.execute("""
|
||||
CREATE TABLE message (
|
||||
source SMALLINT,
|
||||
time INTEGER,
|
||||
sender TEXT,
|
||||
chatroom TEXT,
|
||||
image COLLATE BINARY,
|
||||
sound COLLATE BINARY,
|
||||
extra_data COLLATE BINARY
|
||||
)
|
||||
""")
|
||||
self.conn.commit()
|
||||
Reference in New Issue
Block a user