1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

update qqt sql query class

This commit is contained in:
tianduanrui 2018-01-05 22:52:36 +08:00
parent e1b183001d
commit 6caf31e2b8
5 changed files with 215 additions and 15 deletions

View File

@ -36,8 +36,7 @@ SUBDIRS += examples/exquisite
##-----------------------------------------------------------------
#SUBDIRS += test/gumbo_query_test
#SUBDIRS += test/svgtest
#
SUBDIRS += test/customqvariant
#SUBDIRS += test/customqvariant
#SUBDIRS += test/framelesshelperwidget
#SUBDIRS += test/treeviewtest
#SUBDIRS += test/qqtdicttest

View File

@ -59,12 +59,27 @@ defineReplace(deploy_app_on_linux) {
return ($$command)
}
defineReplace(deploy_app_for_android) {
#need QQT_BUILD_PWD
command =
command += $$MK_DIR $${APP_DEPLOY_PWD} $$CMD_SEP
command += $$RM $${APP_DEPLOY_PWD}/libQQt.so* &&
command += $$COPY_DIR $${QQT_BUILD_PWD}/libQQt.so $${APP_DEPLOY_PWD} &&
command += $$RM $${APP_DEPLOY_PWD}/$${TARGET} &&
command += $$COPY $${DESTDIR}/$${TARGET} $${APP_DEPLOY_PWD}/$${TARGET}
#message($$command)
return ($$command)
}
CONFIG += deploy_app
contains(CONFIG, deploy_app) {
contains(QKIT_PRIVATE, WIN32||WIN64) {
QMAKE_POST_LINK += $$deploy_app_on_win()
} else: contains(QKIT_PRIVATE, macOS) {
QMAKE_POST_LINK += $$deploy_app_on_mac()
} else: contains(QKIT_PRIVATE, ANDROID||ANDROIDX86) {
QMAKE_POST_LINK += $$deploy_app_on_android()
} else {
QMAKE_POST_LINK += $$deploy_app_on_linux()
}

View File

@ -12,10 +12,8 @@
#if you succeed with LibQQt, please thumb up.
#2017年11月10日18:53:56
#-------------------------------------------------
SOURCES = \
$$PWD/sql/qqtsqlquery.cpp
HEADERS = \
$$PWD/sql/qqtsqlquery.h
SOURCES =
HEADERS =
#root dir
HEADERS += $$PWD/qqt.h \
@ -48,8 +46,14 @@ HEADERS += \
$$PWD/core/qqtobjectfactory.h
#sql
SOURCES += $$PWD/sql/qqtsql.cpp
HEADERS += $$PWD/sql/qqtsql.h
SOURCES += \
$$PWD/sql/qqtsql.cpp
HEADERS += \
$$PWD/sql/qqtsql.h
SOURCES += \
$$PWD/sql/qqtsqlquery.cpp
HEADERS += \
$$PWD/sql/qqtsqlquery.h
#gui
SOURCES += \

View File

@ -1,6 +1,152 @@
#include "qqtsqlquery.h"
QQtSqlQuery::QQtSqlQuery(QObject *parent) : QObject(parent)
{
QQtSqlQuery::QQtSqlQuery ( QSqlResult* r ) : QSqlQuery ( r ) {}
QQtSqlQuery::QQtSqlQuery ( const QString& query, QSqlDatabase db ) : QSqlQuery ( query, db ) {}
QQtSqlQuery::QQtSqlQuery ( QSqlDatabase db ) : QSqlQuery ( db ) {}
QQtSqlQuery::QQtSqlQuery ( const QQtSqlQuery& other ) : QSqlQuery ( other ) {}
QQtSqlQuery& QQtSqlQuery::operator= ( const QQtSqlQuery& other )
{
const QSqlQuery& refOther = other;
QSqlQuery& refThis = *this;
refThis = refOther;
return *this;
}
bool QQtSqlQuery::insert ( const QString& table, const QStringList& names, const QStringList& values )
{
int length = names.count();
int count = values.count();
if ( length != count )
{
return false;
}
QString sql = QString ( "insert into " ) + table + QString ( "(" );
//pline() << names;
//pline() << values;
int i;
for ( i = 0; i < length; i++ )
{
sql = sql + names.value ( i );
if ( i < length - 1 )
{
sql += QString ( "," );
}
else
{
sql = sql + QString ( ")" );
}
}
sql = sql + QString ( "values (" );
for ( i = 0; i < count; i++ )
{
sql = sql + QString ( "'" ) + values.value ( i ) + QString ( "'" );
if ( i < count - 1 )
{
sql = sql + QString ( "," );
}
else
sql = sql + QString ( ")" );
}
return exec ( sql );
}
bool QQtSqlQuery::update ( const QString& table, const QStringList& names, const QStringList& values,
const QString& expression )
{
if ( names.size() != values.size() )
{
return false;
}
/*UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值*/
QString sql = QString ( "update " ) + table + QString ( " set " );
for ( int i = 0; i < names.size(); i++ )
{
sql = sql + names.value ( i );
sql = sql + QString ( " = '" );
sql = sql + values.value ( i );
sql = sql + QString ( "'" );
if ( i != names.size() - 1 )
{
sql = sql + QString ( " ," );
}
}
sql = sql + QString ( " where " ) + expression;
return exec ( sql );
}
bool QQtSqlQuery::del ( const QString& table, const QString& srcDatacloum, const QString& strData )
{
/*DELETE FROM 表名称 WHERE 列名称 = 值*/
QString sql = QString ( "delete from " ) + table + QString ( " where " )
+ srcDatacloum + QString ( "='" ) + strData + QString ( "'" );
return exec ( sql );
}
void QQtSqlQuery::getValues ( const QString& table, QStringList& values, const int index )
{
QString sql = QString ( "select * from " ) + table;
exec ( sql );
while ( next() )
{
values << value ( index ).toString();
}
}
void QQtSqlQuery::getValues ( const QString& table, QStringList& values, const QString& srcDatacloum,
const QString& strData, const int index )
{
QString sql = QString ( "select * from " ) + table + QString ( " where " ) + srcDatacloum + QString ( "='" ) + strData +
QString ( "'" );
exec ( sql );
while ( next() )
{
values << value ( index ).toString();
}
}
void QQtSqlQuery::getValues ( const QString& table, QStringList& values, const QString filter, const int ilimit,
const int ioffset, const int index )
{
QString sql = QString ( "select * from " ) + table + QString ( filter ) + QString ( " limit " ) + ilimit +
QString ( " offset " ) + ioffset;
exec ( sql );
while ( next() )
{
values << value ( index ).toString();
}
}
int QQtSqlQuery::getSize ( QString& table )
{
QString sql = QString ( "select count(*) from " ) + table;
exec ( sql );
if ( next() )
return value ( 0 ).toInt();
}

View File

@ -1,24 +1,60 @@
#ifndef QQTSQLQUERY_H
#define QQTSQLQUERY_H
#include <QObject>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <qqtsql.h>
#include <qqtcore.h>
class QQtSqlQuery : public QObject
class QQtSqlQuery : public QSqlQuery
{
Q_OBJECT
public:
explicit QQtSqlQuery(QObject *parent = nullptr);
explicit QQtSqlQuery ( QSqlResult* r );
explicit QQtSqlQuery ( const QString& query = QString(), QSqlDatabase db = QSqlDatabase() );
explicit QQtSqlQuery ( QSqlDatabase db );
QQtSqlQuery ( const QQtSqlQuery& other );
QQtSqlQuery& operator= ( const QQtSqlQuery& other );
virtual ~QQtSqlQuery() {}
/*
* insert into <table> (<names>) values (<values>)
*/
bool insert ( const QString& table, const QStringList& names, const QStringList& values );
/*
* update <table> set <name1>='<value1>',<name2>='<value2>' where <expression>
*/
bool update ( const QString& table, const QStringList& names, const QStringList& values, const QString& expression );
/*
* delete from <table> where <column>='<expression>'
*/
bool del ( const QString& table, const QString& srcDatacloum, const QString& strData );
/*
* select * from <table>
* column id
*/
void getValues ( const QString& table, QStringList& values, const int index );
/*
* select * from <table> where <column> = '<expression>'
* column id
*/
void getValues ( const QString& table, QStringList& values, const QString& srcDatacloum, const QString& strData,
const int index );
/*
* select * from <table> <filter> limit <size1> offset <size2>
* column id
*/
void getValues ( const QString& table, QStringList& values, const QString filter, const int ilimit,
const int ioffset, const int index );
/*
* select count(*) from <table>
*/
int getSize ( QString& table );
signals:
public slots:
private:
};
#endif // QQTSQLQUERY_H