/***************************************************************************
                            QSqlDriver.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QSqlDriver.h>
#include <qtobjc/QSqlDriver.h>
#include <qtobjc/QSqlField.h>
#include <qtobjc/QSqlQuery.h>


@implementation  QSqlDriver


- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld] && [self parent] == nil) {
			qt_del_QSqlDriver((qt_QSqlDriver *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) isOpen
{
	return (BOOL) qt_QSqlDriver_isOpen((qt_QSqlDriver *)[self qt]);
}

- (BOOL) isOpenError
{
	return (BOOL) qt_QSqlDriver_isOpenError((qt_QSqlDriver *)[self qt]);
}

- (BOOL) beginTransaction
{
	return (BOOL) qt_QSqlDriver_beginTransaction((qt_QSqlDriver *)[self qt]);
}

- (BOOL) commitTransaction
{
	return (BOOL) qt_QSqlDriver_commitTransaction((qt_QSqlDriver *)[self qt]);
}

- (BOOL) rollbackTransaction
{
	return (BOOL) qt_QSqlDriver_rollbackTransaction((qt_QSqlDriver *)[self qt]);
}

- (NSArray *) tables: (NSString *)user
{
static qt_QStringList * _qlist = 0L;
static qt_QString * _qstring_user = 0L;
	_qlist = qt_QSqlDriver_tables((qt_QSqlDriver *)[self qt], (qt_QString *) [user toQString: &_qstring_user]);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

- (QSqlIndex*) primaryIndex: (NSString *)tableName
{
static qt_QString * _qstring_tableName = 0L;
	return (QSqlIndex*) [QtSupport objectForQtKey: qt_QSqlDriver_primaryIndex((qt_QSqlDriver *)[self qt], (qt_QString *) [tableName toQString: &_qstring_tableName]) withClass: [QSqlIndex class] allocatedInObjcWorld: YES];
}

- (QSqlRecord*) recordFromTable: (NSString *)tableName
{
static qt_QString * _qstring_tableName = 0L;
	return (QSqlRecord*) [QtSupport objectForQtKey: qt_QSqlDriver_record((qt_QSqlDriver *)[self qt], (qt_QString *) [tableName toQString: &_qstring_tableName]) withClass: [QSqlRecord class] allocatedInObjcWorld: YES];
}

- (QSqlRecord*) recordFromQuery: (QSqlQuery*)query
{
	return (QSqlRecord*) [QtSupport objectForQtKey: qt_QSqlDriver_record1((qt_QSqlDriver *)[self qt], (qt_QSqlQuery*) [query qt]) withClass: [QSqlRecord class] allocatedInObjcWorld: YES];
}

//- (QSqlRecordInfo*) recordInfoFromTable: (NSString *)tablename
//{
//static qt_QString * _qstring_tablename = 0L;
//	return (QSqlRecordInfo*) [QtSupport objectForQtKey: qt_QSqlDriver_recordInfo((qt_QSqlDriver *)[self qt], (qt_QString *) [tablename toQString: &_qstring_tablename]) withClass: [QSqlRecordInfo class] allocatedInObjcWorld: YES];
//}

//- (QSqlRecordInfo*) recordInfoFromQuery: (QSqlQuery*)query
//{
//	return (QSqlRecordInfo*) [QtSupport objectForQtKey: qt_QSqlDriver_recordInfo1((qt_QSqlDriver *)[self qt], (qt_QSqlQuery*) [query qt]) withClass: [QSqlRecordInfo class] allocatedInObjcWorld: YES];
//}

- (NSString *) nullText
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QSqlDriver_nullText((qt_QSqlDriver *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) formatValue: (QSqlField*)field trimStrings: (BOOL)trimStrings
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QSqlDriver_formatValue((qt_QSqlDriver *)[self qt], (qt_QSqlField*) [field qt], (int)trimStrings);
	return [NSString fromQString: _qstring];
}

- (QSqlError*) lastError
{
	return (QSqlError*) [QtSupport objectForQtKey: qt_QSqlDriver_lastError((qt_QSqlDriver *)[self qt]) withClass: [QSqlError class] allocatedInObjcWorld: YES];
}

- (BOOL) hasFeature: (int)f
{
	return (BOOL) qt_QSqlDriver_hasFeature((qt_QSqlDriver *)[self qt], (int)f);
}

- (BOOL) open: (NSString *)db user: (NSString *)user password: (NSString *)password host: (NSString *)host port: (int)port
{
static qt_QString * _qstring_host = 0L;
static qt_QString * _qstring_password = 0L;
static qt_QString * _qstring_user = 0L;
static qt_QString * _qstring_db = 0L;
	return (BOOL) qt_QSqlDriver_open((qt_QSqlDriver *)[self qt], (qt_QString *) [db toQString: &_qstring_db], (qt_QString *) [user toQString: &_qstring_user], (qt_QString *) [password toQString: &_qstring_password], (qt_QString *) [host toQString: &_qstring_host], (int)port);
}

- (BOOL) open: (NSString *)db 
{
static qt_QString * _qstring_db = 0L;
	return (BOOL) qt_QSqlDriver_open((qt_QSqlDriver *)[self qt], (qt_QString *) [db toQString: &_qstring_db], qt_QString_null(), qt_QString_null(), qt_QString_null(), -1);
}

- close
{
	qt_QSqlDriver_close((qt_QSqlDriver *)[self qt]);
	return self;
}

- (QSqlQuery*) createQuery
{
	return (QSqlQuery*) [QtSupport objectForQtKey: qt_QSqlDriver_createQuery((qt_QSqlDriver *)[self qt]) withClass: [QSqlQuery class] allocatedInObjcWorld: YES];
}

+ (int) Transactions
{
	return (int) QSQLDRIVER_Transactions;
}

+ (int) QuerySize
{
	return (int) QSQLDRIVER_QuerySize;
}

+ (int) BLOB
{
	return (int) QSQLDRIVER_BLOB;
}

@end
