view av_db.py @ 508:64f8666690d8

README update (Logical change 1.149)
author optonline.net!jeffpc
date Fri, 16 Jan 2004 02:53:48 +0000
parents 524a0baf7f24
children 903781c081b7
line wrap: on
line source

#/*
# * AV Admin - Helps to manage an AV department
# *
# * Copyright (C) 2003, 2004 Josef "Jeff" Sipek
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# *
# * $Id$
# */

import MySQLdb

import av_consts
import av_debug

class DBCursor:
	""" Class to hold all db cursors data and more """
	def __init__(self,cur):
		""" Set all variables to their default values
		
		does not return anything """
		self.cursor = cur
		
	def execute(self,sql):
		""" Executes arbitrary SQL statement
		
		does not return anything """
		rows = self.cursor.execute(sql)

	def rowcount(self):
		""" Returns the number of results returned
		
		returns integer """
		return self.cursor.rowcount
	
	def fetchone(self):
		""" Returns one row from the database
		
		returns list """
		return self.cursor.fetchone()
	
	def fetchall(self):
		""" Returns list of rows from the database
		
		returns list """
		return self.cursor.fetchall()


class DB:
	""" Class to hold all db data and more """
	def __init__(self):
		""" Set all variables to their default values

		does not return anything """
		self.__conn = None
		self.__cursor = None
		
		self.connect()

	def attach(self,conn):
		self.conn = conn
		self.html = conn.html
		self.user = conn.user
		self.utils = conn.utils

	def connect(self):
		""" Connects to mysql database

		does not return anything """
		if (not self.__conn):
			self.__conn = MySQLdb.connect(host=av_consts.DBHost, user=av_consts.DBUser, passwd=av_consts.DBPass,db=av_consts.DBName)
		if (not self.__cursor):
			self.__cursor = self.__conn.cursor()
			
	def execSQL(self, sql):
		""" Execute sql and return the results
		
		returns list """
		self.__cursor.execute(sql)
		return self.__cursor.fetchall()
	
	def disconnect(self):
		""" Disconnects from mysql database
		
		does not return anything """
		if (self.__conn):
			self.__conn = None
			
	def newid(self):
		""" Creates a 
		
		returns hashid """
		return DBCursor(self.__conn.cursor())
		
if __name__ == "__main__":
	print "ERROR"