Last active
January 7, 2016 12:12
-
-
Save mhanoglu/e5ae948a84c2e1287b99 to your computer and use it in GitHub Desktop.
SQLite3 handler for Android (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
''' Project Name : Android SQL Database with SQLite3 | |
Author : by MeHMeT a.k.a MaRZoCHi (Mehmet Hanoğlu) | |
Copyright : www.mehmethanoglu.com.tr | |
License : GNU License | |
Date : 08.11.2012 00:54 | |
Update : 12.11.2012 | |
''' | |
__doc__ = 'Android SQL Database with SQLite3' | |
__author__ = 'by MeHMeT a.k.a MaRZoCHi' | |
__name__ = 'aSQL' | |
__version__ = '0.1' | |
class SQLDB : | |
def __init__(self, path) : | |
self.__import() | |
self.__debug, self.__com, self.__sql = 0, 0, '' | |
self.path = path ; del path | |
self.connect = self.dbhandler.connect(self.path) | |
self.db = self.connect.cursor() | |
def super_query(self, sql) : | |
self.__sql = sql | |
self.db.execute(unicode(sql)) | |
return self.db.fetchone() | |
def query(self, sql) : | |
self.__sql = sql | |
if not (sql.lower()).startswith("select") : | |
try : | |
self.db.execute(unicode(sql)) | |
self.connect.commit() | |
self.__com = True | |
except Exception, err : | |
print str(err), '\n[SQL] :', self.__sql | |
else : | |
self.db.execute(unicode(sql)) | |
return self.db.fetchall() | |
def close(self, ) : | |
if not self.__com : self.free() | |
self.connect.close() | |
del self.__debug, self._exists | |
del self.db, self.dbhandler | |
def free(self, ) : | |
self.__sql = '' | |
self.connect.commit() | |
def __import(self, ) : | |
import sqlite3 | |
self.dbhandler = sqlite3 ; del sqlite3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment