1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
This commit is contained in:
tianduanrui 2018-01-05 23:36:36 +08:00
commit 34b9c81219
5 changed files with 672 additions and 437 deletions

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

@ -46,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

@ -29,7 +29,9 @@ extern "C" {
QQTSHARED_EXPORT QSqlDatabase newDatabaseConn();
/*已经将数据库打开,不必重复打开*/
QQTSHARED_EXPORT void setDatabaseName(QSqlDatabase& db, QString dbName);
//=setDatabaseName
QQTSHARED_EXPORT void useDatabase(QSqlDatabase& db, QString dbName);
QQTSHARED_EXPORT void openDatabase(QSqlDatabase& db);

152
src/sql/qqtsqlquery.cpp Normal file
View File

@ -0,0 +1,152 @@
#include "qqtsqlquery.h"
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();
}

60
src/sql/qqtsqlquery.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef QQTSQLQUERY_H
#define QQTSQLQUERY_H
#include <QSqlQuery>
#include <QSqlDatabase>
#include <qqtsql.h>
#include <qqtcore.h>
class QQtSqlQuery : public QSqlQuery
{
public:
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