dikkini

sql

Jan 24th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. #-*- coding: utf8 -*-
  2.  
  3. import sys
  4. import sqlite3
  5.  
  6. class sqliteDB():
  7.     def __init__(self):
  8.         self.db = sqlite3.connect('./data_quality.db')
  9.    
  10.     def add_regexp(self, param, table, regexp):
  11.         crtable = ('%s(%s)' % (param, table))
  12.         self.db.execute('create table if not exists %s' %  (crtable))
  13.         data = (u'%s' % (unicode(regexp)))
  14.         sql = ('insert into %s (%s) values ("%s")' % (param, table, data))
  15.         self.db.execute('%s' % (sql))
  16.         self.db.commit()
  17.        
  18.     def take_all(self, param, table):
  19.         ttable = ('%s from %s' % (str(table), str(param)))
  20.         cur = self.db.execute('select %s' % (ttable))
  21.         rows = []
  22.         data = []
  23.         for row in cur:
  24.             rows.append(map(lambda a: a.encode('utf-8'), row))
  25.            
  26.         for s in rows:
  27.             data.append(s[0])
  28.         print data
  29.         return data
Advertisement
Add Comment
Please, Sign In to add comment