/***************************************************************************
                            QSqlRecord.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_QSqlRecord.h>
#include <qtobjc/QSqlRecord.h>
#include <qtobjc/QVariant.h>
#include <qtobjc/QSqlField.h>

@implementation  QSqlRecord

- (void *) qt
{
	return _qt;
}

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

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

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


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

- copyWithZone: (NSZone *) zone
{
	QSqlRecord * aCopy;
	aCopy = [[(QSqlRecord *)[[self class] allocWithZone: zone] setQt: qt_new_QSqlRecord1([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_QSqlRecord((qt_QSqlRecord *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

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

- (QVariant*) valueForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (QVariant*) [QtSupport objectForQtKey: qt_QSqlRecord_value1((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]) withClass: [QVariant class] allocatedInObjcWorld: YES];
}

- setValue: (int)i val: (QVariant *)val
{
	qt_QSqlRecord_setValue((qt_QSqlRecord *)[self qt], (int)i, (qt_QVariant *) [val qt]);
	return self;
}

- setValueForName: (NSString *)name val: (QVariant *)val
{
static qt_QString * _qstring_name = 0L;
	qt_QSqlRecord_setValue1((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name], (qt_QVariant *) [val qt]);
	return self;
}

- (BOOL) isGenerated: (int)i
{
	return (BOOL) qt_QSqlRecord_isGenerated((qt_QSqlRecord *)[self qt], (int)i);
}

- (BOOL) isGeneratedForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QSqlRecord_isGenerated1((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]);
}

- setGeneratedForName: (NSString *)name generated: (BOOL)generated
{
static qt_QString * _qstring_name = 0L;
	qt_QSqlRecord_setGenerated((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name], (int)generated);
	return self;
}

- setGenerated: (int)i generated: (BOOL)generated
{
	qt_QSqlRecord_setGenerated1((qt_QSqlRecord *)[self qt], (int)i, (int)generated);
	return self;
}

- setNull: (int)i
{
	qt_QSqlRecord_setNull((qt_QSqlRecord *)[self qt], (int)i);
	return self;
}

- setNullForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	qt_QSqlRecord_setNull1((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]);
	return self;
}

- (BOOL) isNull: (int)i
{
	return (BOOL) qt_QSqlRecord_isNull((qt_QSqlRecord *)[self qt], (int)i);
}

- (BOOL) isNullForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QSqlRecord_isNull1((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]);
}

- (int) positionForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (int) qt_QSqlRecord_position((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]);
}

- (NSString *) fieldName: (int)i
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QSqlRecord_fieldName((qt_QSqlRecord *)[self qt], (int)i);
	return [NSString fromQString: _qstring];
}

- (QSqlField*) field: (int)i
{
	return (QSqlField*) [QtSupport objectForQtKey: qt_QSqlRecord_field((qt_QSqlRecord *)[self qt], (int)i) withClass: [QSqlField class] allocatedInObjcWorld: YES];
}

- (QSqlField*) fieldForName: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (QSqlField*) [QtSupport objectForQtKey: qt_QSqlRecord_field1((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]) withClass: [QSqlField class] allocatedInObjcWorld: YES];
}

//- (QSqlField*) field: (int)i
//{
//	return (QSqlField*) [QtSupport objectForQtKey: qt_QSqlRecord_field2((qt_QSqlRecord *)[self qt], (int)i) withClass: [QSqlField class] allocatedInObjcWorld: YES];
//}

//- (QSqlField*) fieldForName: (NSString *)name
//{
//static qt_QString * _qstring_name = 0L;
//	return (QSqlField*) [QtSupport objectForQtKey: qt_QSqlRecord_field3((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]) withClass: [QSqlField class] allocatedInObjcWorld: YES];
//}

- append: (QSqlField*)field
{
	qt_QSqlRecord_append((qt_QSqlRecord *)[self qt], (qt_QSqlField*) [field qt]);
	return self;
}

- insert: (int)pos field: (QSqlField*)field
{
	qt_QSqlRecord_insert((qt_QSqlRecord *)[self qt], (int)pos, (qt_QSqlField*) [field qt]);
	return self;
}

- remove: (int)pos
{
	qt_QSqlRecord_remove((qt_QSqlRecord *)[self qt], (int)pos);
	return self;
}

- (BOOL) isEmpty
{
	return (BOOL) qt_QSqlRecord_isEmpty((qt_QSqlRecord *)[self qt]);
}

- (BOOL) contains: (NSString *)name
{
static qt_QString * _qstring_name = 0L;
	return (BOOL) qt_QSqlRecord_contains((qt_QSqlRecord *)[self qt], (qt_QString *) [name toQString: &_qstring_name]);
}

- clear
{
	qt_QSqlRecord_clear((qt_QSqlRecord *)[self qt]);
	return self;
}

- clearValues: (BOOL)nullify
{
	qt_QSqlRecord_clearValues((qt_QSqlRecord *)[self qt], (int)nullify);
	return self;
}

- clearValues
{
	qt_QSqlRecord_clearValues((qt_QSqlRecord *)[self qt], 0);
	return self;
}

- (unsigned int) count
{
	return (unsigned int) qt_QSqlRecord_count((qt_QSqlRecord *)[self qt]);
}

- (NSString *) toString: (NSString *)prefix seperator: (NSString*) string
{
static qt_QString * _qstring = 0L;
static qt_QString * _qstring_string = 0L;
static qt_QString * _qstring_prefix = 0L;
	_qstring = qt_QSqlRecord_toString((qt_QSqlRecord *)[self qt], (qt_QString *) [prefix toQString: &_qstring_prefix], (qt_QString *) [string toQString: &_qstring_string]);
	return [NSString fromQString: _qstring];
}

- (NSArray *) toStringList: (NSString *)prefix
{
static qt_QStringList * _qlist = 0L;
static qt_QString * _qstring_prefix = 0L;
	_qlist = qt_QSqlRecord_toStringList((qt_QSqlRecord *)[self qt], (qt_QString *) [prefix toQString: &_qstring_prefix]);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

@end
