/***************************************************************************
                            QSqlQuery.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_QSqlQuery.h>
#include <qtobjc/QSqlQuery.h>
#include <qtobjc/QSqlDatabase.h>
#include <qtobjc/QSqlResult.h>


@implementation  QSqlQuery


- initWithSqlResult: (QSqlResult*)r
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QSqlQuery((qt_QSqlResult*) [r qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)query db: (QSqlDatabase*)db
{
static qt_QString * _qstring_query = 0L;
	if ([self qt] == 0L) {
		[self setQt: qt_new_QSqlQuery1((qt_QString *) [query toQString: &_qstring_query], (qt_QSqlDatabase*) [db qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QSqlQuery1(qt_QString_null(), 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- copyWithZone: (NSZone *) zone
{
	QSqlQuery * aCopy;
	aCopy = [[(QSqlQuery *)[[self class] allocWithZone: zone] setQt: qt_new_QSqlQuery2([self qt])] init];
	[aCopy setAllocatedInObjcWorld: YES];
	[QtSupport setObject: aCopy forQtKey: [aCopy qt]];
	return aCopy;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			qt_del_QSqlQuery((qt_QSqlQuery *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) isValid
{
	return (BOOL) qt_QSqlQuery_isValid((qt_QSqlQuery *)[self qt]);
}

- (BOOL) isActive
{
	return (BOOL) qt_QSqlQuery_isActive((qt_QSqlQuery *)[self qt]);
}

- (BOOL) isNull: (int)field
{
	return (BOOL) qt_QSqlQuery_isNull((qt_QSqlQuery *)[self qt], (int)field);
}

- (int) at
{
	return (int) qt_QSqlQuery_at((qt_QSqlQuery *)[self qt]);
}

- (NSString *) lastQuery
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QSqlQuery_lastQuery((qt_QSqlQuery *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (int) numRowsAffected
{
	return (int) qt_QSqlQuery_numRowsAffected((qt_QSqlQuery *)[self qt]);
}

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

- (BOOL) isSelect
{
	return (BOOL) qt_QSqlQuery_isSelect((qt_QSqlQuery *)[self qt]);
}

- (int) size
{
	return (int) qt_QSqlQuery_size((qt_QSqlQuery *)[self qt]);
}

- (QSqlDriver*) driver
{
	return (QSqlDriver*) [QtSupport objectForQtKey: qt_QSqlQuery_driver((qt_QSqlQuery *)[self qt]) withClass: [QSqlDriver class] allocatedInObjcWorld: YES];
}

- (QSqlResult*) result
{
	return (QSqlResult*) [QtSupport objectForQtKey: qt_QSqlQuery_result((qt_QSqlQuery *)[self qt]) withClass: [QSqlResult class] allocatedInObjcWorld: YES];
}

- (BOOL) exec: (NSString *)query
{
static qt_QString * _qstring_query = 0L;
	return (BOOL) qt_QSqlQuery_exec((qt_QSqlQuery *)[self qt], (qt_QString *) [query toQString: &_qstring_query]);
}

- (QVariant*) value: (int)i
{
	return (QVariant*) [QtSupport objectForQtKey: qt_QSqlQuery_value((qt_QSqlQuery *)[self qt], (int)i) withClass: [QVariant class] allocatedInObjcWorld: YES];
}

- (BOOL) seek: (int)i relative: (BOOL)relative
{
	return (BOOL) qt_QSqlQuery_seek((qt_QSqlQuery *)[self qt], (int)i, (int)relative);
}

- (BOOL) seek: (int)i 
{
	return (BOOL) qt_QSqlQuery_seek((qt_QSqlQuery *)[self qt], (int)i, 0);
}

- (BOOL) next
{
	return (BOOL) qt_QSqlQuery_next((qt_QSqlQuery *)[self qt]);
}

- (BOOL) prev
{
	return (BOOL) qt_QSqlQuery_prev((qt_QSqlQuery *)[self qt]);
}

- (BOOL) first
{
	return (BOOL) qt_QSqlQuery_first((qt_QSqlQuery *)[self qt]);
}

- (BOOL) last
{
	return (BOOL) qt_QSqlQuery_last((qt_QSqlQuery *)[self qt]);
}

- beforeSeek
{
	qt_QSqlQuery_beforeSeek((qt_QSqlQuery *)[self qt]);
	return self;
}

- afterSeek
{
	qt_QSqlQuery_afterSeek((qt_QSqlQuery *)[self qt]);
	return self;
}
- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


@end
