Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 43ed067ef12dc23f248aedf5d56e3391 > files > 1

libdbmusic-devel-0.8.4-1mdv2008.0.i586.rpm

/***************************************************************************
                         dbinit.h  -  description
                           -------------------
                  begin                : Wed Dec 19 2001
                  copyright            : (C) 2001 by Will DeRousse
                  email                : badhack@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DBINIT_H
#define DBINIT_H

#include "dbmusicglobals.h"
#include <libpq-fe.h>
#include <qstring.h>

/**
 * This class handles the connection to 'template1' to perform db functions like searching or creating a new database.
 *
 * Example:
 * <pre>
 * dbInit *init=new dbInit("template1");
 * init->find("music");
 * // if it finds it, open the db
 * delete init;
 * </pre>
 * @author Will DeRousse
 * @short Database init and primitives.
 */

class dbInit {
	public:
		/**  Constructor
		 * @param dbname(template1)
		 */
		dbInit(const QString &);
		/**  Destructor
		 */
		~dbInit();
		/**
		 * Checks the connection to make sure the db didn't return a bad code.
		 */
		bool checkConnect() const;
		/** This function will create a database (as long as you are connected to template1).
		 * @param string Name of database to create
		 */
		bool createDb(const QString &);
		/** Returns the errorcode.
		 * @param string QString to be set to value of SELECT version()
		 */
		int dbVersion(QString &);
		/** Returns last error message from the server.
		 *
		 * Returns error code.
		 * @param QString Error string to set.
		 */
		int errorMessage(QString &);
		/** Use this function to search template1 for a particular database. Returns true if found, false otherwise.
		 * @param string Database to search for
		 */
		bool findDb(const QString &);
		/**
		 * This function goes one step farther than checkConnect by sending data to the server first in an attempt to actually communicate with it. I added this function because I think it will add another layer of stability. In other words, some dummy data will get corrupted rather than some important data in the db.
		 */
		bool testConnect();
	protected: // Protected methods
		/**
		 * Use this function often to check the status of the server. The return value is the error code.
		 */
		int execCheck() const;
		/** Wrapper to help handle local character sets.
		 *
		 * Returns QString.
		 *
		 * @param PGresult Query result
		 * @param int tuple number
		 * @param int field number
		 */
		QString GetValue(const PGresult *res, int tup_num, int field_num);
		ExecStatusType stat;
		PGconn *dbm;
		PGresult *res;
		QString sqlstring;
};


#endif