/***************************************************************************
                            QSqlQuery.cpp -  description
                             -------------------
    begin                : Wed Nov 21 17:05:56 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 17:05:56 2001, using kalyptus 0.9.
 ***************************************************************************/

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

#define _BOOL_H_
#include <qsqlquery.h>
#include <qstring.h>
#include <qcstring.h>

#include <qtjava/QtSupport.h>
#include <qtjava/QSqlQuery.h>

class QSqlQueryJBridge : public QSqlQuery
{
public:
	QSqlQueryJBridge(QSqlResult* r) : QSqlQuery(r) {}
	QSqlQueryJBridge(const QString& query, QSqlDatabase* db) : QSqlQuery(query, db) {}
	QSqlQueryJBridge(const QSqlQuery& other) : QSqlQuery(other) {}
	~QSqlQueryJBridge() {QtSupport::qtKeyDeleted(this);}
	void protected_beforeSeek() {
		QSqlQuery::beforeSeek();
		return;
	}
	void protected_afterSeek() {
		QSqlQuery::afterSeek();
		return;
	}
};


JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_newQSqlQuery__Lorg_kde_qt_QSqlResult_2(JNIEnv *env, jobject obj, jobject r)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QSqlQueryJBridge((QSqlResult*) QtSupport::getQt(env, r)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_newQSqlQuery__Ljava_lang_String_2Lorg_kde_qt_QSqlDatabase_2(JNIEnv *env, jobject obj, jstring query, jobject db)
{
static QString * _qstring_query = 0;
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QSqlQueryJBridge((QString&) * (QString *) QtSupport::toQString(env, query, &_qstring_query), (QSqlDatabase*) QtSupport::getQt(env, db)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_newQSqlQuery__(JNIEnv *env, jobject obj)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QSqlQueryJBridge(QString::null, 0));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_newQSqlQuery__Lorg_kde_qt_QSqlQueryInterface_2(JNIEnv *env, jobject obj, jobject other)
{
	if (QtSupport::getQt(env, obj) == 0) {
		QtSupport::setQt(env, obj, new QSqlQueryJBridge((QSqlQuery&) *(QSqlQuery *) QtSupport::getQt(env, other)));
		QtSupport::setObjectForQtKey(env, obj, QtSupport::getQt(env, obj));
	}
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_finalize(JNIEnv *env, jobject obj)
{
	if (QtSupport::allocatedInJavaWorld(env, obj)) {
		delete (QSqlQuery*)QtSupport::getQt(env, obj);
		QtSupport::setQt(env, obj, 0);
	}
	return;
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_isValid(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->isValid();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_isActive(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->isActive();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_isNull(JNIEnv *env, jobject obj, jint field)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->isNull((int) field);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSqlQuery_at(JNIEnv *env, jobject obj)
{
	return (jint) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->at();
}

JNIEXPORT jstring JNICALL
Java_org_kde_qt_QSqlQuery_lastQuery(JNIEnv *env, jobject obj)
{
	QString  _qstring;
	_qstring = ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->lastQuery();
	return QtSupport::fromQString(env, &_qstring);
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSqlQuery_numRowsAffected(JNIEnv *env, jobject obj)
{
	return (jint) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->numRowsAffected();
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSqlQuery_lastError(JNIEnv *env, jobject obj)
{
	QSqlError  _qsql;
	_qsql = ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->lastError();
	return (jobject) QtSupport::objectForQtKey(env, (void *)new QSqlError(_qsql), "org.kde.qt.QSqlError", TRUE);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_isSelect(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->isSelect();
}

JNIEXPORT jint JNICALL
Java_org_kde_qt_QSqlQuery_size(JNIEnv *env, jobject obj)
{
	return (jint) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->size();
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSqlQuery_driver(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->driver(), "org.kde.qt.QSqlDriver");
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSqlQuery_result(JNIEnv *env, jobject obj)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->result(), "org.kde.qt.QSqlResult");
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_exec(JNIEnv *env, jobject obj, jstring query)
{
static QString * _qstring_query = 0;
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->exec((QString&) * (QString *) QtSupport::toQString(env, query, &_qstring_query));
}

JNIEXPORT jobject JNICALL
Java_org_kde_qt_QSqlQuery_value(JNIEnv *env, jobject obj, jint i)
{
	return (jobject) QtSupport::objectForQtKey(env, (void *)new  QVariant (((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->value((int) i)), "org.kde.qt.QVariant", TRUE);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_seek__IZ(JNIEnv *env, jobject obj, jint i, jboolean relative)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->seek((int) i, (bool) relative);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_seek__I(JNIEnv *env, jobject obj, jint i)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->seek((int) i, FALSE);
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_next(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->next();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_prev(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->prev();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_first(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->first();
}

JNIEXPORT jboolean JNICALL
Java_org_kde_qt_QSqlQuery_last(JNIEnv *env, jobject obj)
{
	return (jboolean) ((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->last();
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_beforeSeek(JNIEnv *env, jobject obj)
{
	((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->protected_beforeSeek();
	return;
}

JNIEXPORT void JNICALL
Java_org_kde_qt_QSqlQuery_afterSeek(JNIEnv *env, jobject obj)
{
	((QSqlQueryJBridge*) QtSupport::getQt(env, obj))->protected_afterSeek();
	return;
}

