果果、 发表于 2016-11-28 12:06:02

python sqlite类

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3 as sqlite
import os.path as osp
import sys
class Sqli(object):
conn = ''
cursor = ''
def __init__(self, dbname):      
try:
self.conn = sqlite.connect(osp.abspath(dbname))
except Exception, what:
print what
sys.exit()
self.conn.row_factory = sqlite.Row         
self.cursor = self.conn.cursor()      
def createTable(self):      
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS (
INTEGER PRIMARY KEY,
TEXT,
TEXT,
TEXT,
UNIQUE());
''')
print "create table com "
self.cursor.execute('''
CREATE INDEX IF NOT EXISTS ON ();
''')
print 'create map index'
self.conn.commit()   
def query(self, sql):
try:
self.cursor.execute(sql)
self.conn.commit()
except Exception, what:
print what

def show(self):
r = self.cursor.fetchall()
return r
def showone(self):
return self.cursor.fetchone()
def __del__(self):
self.cursor.close()
self.conn.close()
页: [1]
查看完整版本: python sqlite类