Code: Alles auswählen
# -*- coding: utf-8 -*-
"""
Base Database System
--------------------
Each database system uses this unit for loading the configuration data
and inheriting the BaseDatabase.
This unit also loads the real database, no further work for the programmer
:-)
"""
__author__ = u"Armin Ronacher <armin.ronacher@active-4.com>"
__version__ = u"0.1alpha"
import os, sys
class DatabaseError: pass
class BaseDatabase:
def __init__(self, host, user, password, database, prefix): pass
def fetchall(self, sql, values): pass
def get_tables(self): pass
def insert(self, table, data): pass
def update(self, table, data, where, limit=None): pass
def select(self, items, table, where=None, order=None, limit=None): pass
def delete(self, table, where, limit=None): pass
def close(self): pass
#
# Load Configuration File
#
system = None
host = None
user = None
password = None
database = None
prefix = ""
lines = file(os.path.realpath(os.path.dirname(__file__) +
u"/../config/database"))
for line in lines:
line = line.strip()
if line and line[0] != "#":
p = line.split("=", 1)
key = p[0].strip()
value = p[1].strip()
if key == u"system": system = value
if key == u"host": host = value
if key == u"user": user = value
if key == u"password": password = value
if key == u"database": database = value
if key == u"prefix": prefix = value
#
# Load Database System
#
sys.path.append(os.path.dirname(__file__))
dbsys = __import__(system)
Connection = dbsys.Database(host, user, password, database, prefix)
#
# Get rid of unused data
#
del p, key, value, line, lines, os, sys
Code: Alles auswählen
# -*- coding: utf-8 -*-
"""
MySQL Database System
---------------------
"""
__author__ = u"Armin Ronacher <armin.ronacher@active-4.com>"
__version__ = u"0.1alpha"
import sys
import os
#
# Get Base Database
#
sys.path.append(os.path.dirname(__file__))
BaseDatabase = __import__("database").BaseDatabase
class Database(BaseDatabase):
def __init__(self, host, user, password, database, prefix):
print u"Hallo Welt"
Code: Alles auswählen
>>> import database
Hallo Welt
>>> dir(database)
['BaseDatabase', 'Connection', 'DatabaseError', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', '__version__', 'database', 'dbsys', 'host', 'password', 'prefix', 'system', 'user']