lldatabase.py

Go to the documentation of this file.
00001 from django.conf import settings
00002 
00003 ##
00004 # 
00005 #     Takes a database name, uses that name to grab settings for that database
00006 #     
00007 def connect(database):
00008     dbargs = {}
00009     fields = ('ENGINE', 'USER', 'HOST', 'PASSWORD', 'NAME', 'PORT')
00010     for i in range(len(fields)):
00011         dbargs['%s_%s' % ("DATABASE", fields[i])] = \
00012             settings.__getitem__('%s_%s_%s' % (database.upper(), "DB", fields[i]))
00013     #Note: this must be called before doing any further database related imports
00014     if settings.configured:
00015         fields = ("DATABASE_NAME",
00016                   "DATABASE_USER",
00017                   "DATABASE_HOST",
00018                   "DATABASE_PORT",
00019                   "DATABASE_ENGINE",
00020                   "DATABASE_PASSWORD")
00021         current_db = {}
00022         for i in range(len(fields)):
00023             current_db.update( { fields[i]: getattr(settings, fields[i]) } )
00024         # If we are already connect to the exact same database, do nothing
00025         if current_db != dbargs:
00026             from django.db import connection
00027             connection.close()
00028             for key, value in dbargs.items():
00029                 setattr(settings, key, value)
00030     else:
00031         settings.configure(**dbargs)
00032 
00033 def disconnect():
00034     connect(config.DEFAULT_DATABASE)
00035 
00036 def flush_table(table):
00037     rows = table.objects.all()
00038     rows.delete()
00039     
00040 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...