You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
311 lines
7.2 KiB
311 lines
7.2 KiB
// -*- c++ -*-
|
|
|
|
/*
|
|
* Copyright (C) 2003, Ian Reinhart Geiser <geiseri@kde.org>
|
|
*
|
|
* 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.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public License
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#include <kjsembed/global.h>
|
|
#include <tqsqldatabase.h>
|
|
#include <tqsqlquery.h>
|
|
#include <tqsqlerror.h>
|
|
#include "sql_imp.h"
|
|
|
|
|
|
|
|
namespace KJSEmbed {
|
|
namespace Bindings {
|
|
|
|
SqlDatabase::SqlDatabase( TTQObject *parent, const char *name): BindingObject(parent, name)
|
|
{
|
|
connectionName = "defaultConnection";
|
|
setJSClassName( "SqlDatabase" );
|
|
}
|
|
SqlDatabase::~SqlDatabase()
|
|
{
|
|
TTQSqlDatabase::removeDatabase(connectionName);
|
|
}
|
|
bool SqlDatabase::addDatabase ( const TTQString &type, const TTQString &conn )
|
|
{
|
|
connectionName = conn;
|
|
TTQSqlDatabase *db = TTQSqlDatabase::addDatabase(type, connectionName);
|
|
if ( !db )
|
|
return false;
|
|
return true;
|
|
}
|
|
TTQStringList SqlDatabase::drivers ()
|
|
{
|
|
return TTQSqlDatabase::drivers();
|
|
}
|
|
bool SqlDatabase::open ( )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->open();
|
|
return false;
|
|
}
|
|
bool SqlDatabase::open ( const TTQString &user, const TTQString &password )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->open(user, password);
|
|
return false;
|
|
}
|
|
void SqlDatabase::close ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
{
|
|
db->close();
|
|
}
|
|
}
|
|
bool SqlDatabase::isOpen ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->isOpen();
|
|
return false;
|
|
}
|
|
bool SqlDatabase::isOpenError ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->isOpenError();
|
|
return true;
|
|
}
|
|
TTQStringList SqlDatabase::tables ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->tables();
|
|
return TTQStringList();
|
|
}
|
|
SqlQuery *SqlDatabase::exec (const TTQString &query )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
{
|
|
kdDebug() <<" exec query " << query << endl;
|
|
SqlQuery *qw = new SqlQuery(this, "query",db->exec( query ));
|
|
//JSFactory::instance()->addType( "SqlQuery" );
|
|
kdDebug() <<" size " << qw->size() << endl;
|
|
kdDebug() <<" valid " << qw->isValid() << endl;
|
|
return qw;
|
|
}
|
|
return 0L;
|
|
}
|
|
TTQString SqlDatabase::lastError () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
{
|
|
return db->lastError().text();
|
|
}
|
|
return "No Database Driver Loaded";
|
|
}
|
|
bool SqlDatabase::transaction ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->transaction();
|
|
return false;
|
|
}
|
|
bool SqlDatabase::commit ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->commit();
|
|
return false;
|
|
}
|
|
bool SqlDatabase::rollback ()
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->rollback();
|
|
return false;
|
|
}
|
|
void SqlDatabase::setDatabaseName (const TTQString &name )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
db->setDatabaseName(name);
|
|
}
|
|
void SqlDatabase::setUserName (const TTQString &name )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
db->setUserName(name);
|
|
}
|
|
void SqlDatabase::setPassword (const TTQString &password )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
db->setPassword(password);
|
|
}
|
|
void SqlDatabase::setHostName (const TTQString &host )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
db->setHostName(host);
|
|
}
|
|
void SqlDatabase::setPort ( int p )
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
db->setPort(p);
|
|
}
|
|
TTQString SqlDatabase::databaseName () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->databaseName();
|
|
return "";
|
|
}
|
|
TTQString SqlDatabase::userName () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->userName();
|
|
return "";
|
|
}
|
|
TTQString SqlDatabase::password () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->password();
|
|
return "";
|
|
}
|
|
TTQString SqlDatabase::hostName () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->hostName();
|
|
return "";
|
|
}
|
|
TTQString SqlDatabase::driverName () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->driverName();
|
|
return "";
|
|
}
|
|
int SqlDatabase::port () const
|
|
{
|
|
TTQSqlDatabase *db = TTQSqlDatabase::database(connectionName,false);
|
|
if ( db )
|
|
return db->port();
|
|
return 0;
|
|
}
|
|
|
|
SqlQuery::SqlQuery( TTQObject *parent, const char *name ): BindingObject(parent, name)
|
|
{
|
|
kdDebug() << "New null SQL Query" << endl;
|
|
m_query = TTQSqlQuery();
|
|
setJSClassName( "SqlQuery" );
|
|
}
|
|
SqlQuery::SqlQuery( TTQObject *parent, const char *name, const TTQSqlQuery &q ): BindingObject(parent, name)
|
|
{
|
|
kdDebug() << "New SQL Query with argument" << endl;
|
|
m_query = q;
|
|
}
|
|
SqlQuery::~SqlQuery()
|
|
{
|
|
kdDebug() << "SQL Query going away..." << endl;
|
|
}
|
|
|
|
/*SqlQuery::SqlQuery(const SqlQuery ©) : BindingObject(copy.parent(), copy.name())
|
|
{
|
|
m_query = copy.m_query;
|
|
}
|
|
*/
|
|
bool SqlQuery::isValid () const
|
|
{
|
|
if ( m_query.isValid())
|
|
kdDebug() << "Query is valid" << endl;
|
|
else
|
|
kdDebug() << "Query is not valid" << endl;
|
|
return m_query.isValid();
|
|
}
|
|
bool SqlQuery::isActive () const
|
|
{
|
|
return m_query.isActive();
|
|
}
|
|
bool SqlQuery::isNull ( int field )
|
|
{
|
|
return m_query.isNull(field);
|
|
}
|
|
int SqlQuery::at () const
|
|
{
|
|
return m_query.at();
|
|
}
|
|
TTQString SqlQuery::lastQuery () const
|
|
{
|
|
kdDebug() << "Last query error: " << m_query.lastQuery() << endl;
|
|
return m_query.lastQuery();
|
|
}
|
|
int SqlQuery::numRowsAffected () const
|
|
{
|
|
return m_query.numRowsAffected();
|
|
}
|
|
TTQString SqlQuery::lastError () const
|
|
{
|
|
return m_query.lastError().text();
|
|
}
|
|
bool SqlQuery::isSelect () const
|
|
{
|
|
return m_query.isSelect();
|
|
}
|
|
int SqlQuery::size () const
|
|
{
|
|
return m_query.size();
|
|
}
|
|
bool SqlQuery::exec ( const TTQString & query )
|
|
{
|
|
return m_query.exec( query );
|
|
}
|
|
TTQVariant SqlQuery::value ( int i )
|
|
{
|
|
return m_query.value(i);
|
|
}
|
|
bool SqlQuery::seek ( int i, bool relative )
|
|
{
|
|
return m_query.seek(i,relative);
|
|
}
|
|
bool SqlQuery::next ()
|
|
{
|
|
return m_query.next();
|
|
}
|
|
bool SqlQuery::prev ()
|
|
{
|
|
return m_query.prev();
|
|
}
|
|
bool SqlQuery::first ()
|
|
{
|
|
return m_query.first();
|
|
}
|
|
bool SqlQuery::last ()
|
|
{
|
|
return m_query.last();
|
|
}
|
|
|
|
} // namespace KJSEmbed::Bindings
|
|
} // namespace KJSEmbed
|
|
|
|
#ifndef QT_ONLY
|
|
#include "sql_imp.moc"
|
|
#endif
|