-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial import of the TMP based SQL access take from one of our proje…
…cts. It builds and all the existing tests are passing.
- Loading branch information
Andras Mantia
committed
Jun 24, 2013
0 parents
commit 50f30ab
Showing
78 changed files
with
7,031 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Makefile* | ||
build* | ||
*.o | ||
moc_*.* | ||
*.moc | ||
ui_*.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
project(sqlatelib) | ||
set(SQLATE_LIBRARY_VERSION 0) | ||
set(SQLATE_LIBRARY_SO_VERSION 1) | ||
|
||
cmake_minimum_required(VERSION 2.8) | ||
set(CMAKE_AUTOMOC true) | ||
option(SQL_ENABLE_NETWORK_WATCHER "Enable the watcher threads for SQL queries over the network. The default is disabled." FALSE) | ||
|
||
if (SQL_ENABLE_NETWORK_WATCHER) | ||
add_definitions(-DSQL_ENABLE_NETWORK_WATCHER) | ||
endif () | ||
|
||
if (ANDROID) | ||
find_host_package(Qt4 REQUIRED) | ||
include(Android) | ||
else (ANDROID) | ||
find_package(Qt4 REQUIRED) | ||
endif() | ||
|
||
find_package(Boost 1.40 REQUIRED) | ||
add_definitions( -DBOOST_MPL_LIMIT_VECTOR_SIZE=50 -DBOOST_MPL_CFG_NO_PREPROCESSED_HEADERS ) | ||
add_definitions( -DQT_STRICT_ITERATORS ) | ||
add_definitions( -DQT_NO_CAST_FROM_ASCII ) | ||
add_definitions( -DQT_NO_CAST_TO_ASCII ) | ||
add_definitions( -DQT_NO_CAST_FROM_BYTEARRAY ) | ||
add_definitions( -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) | ||
|
||
enable_testing() | ||
|
||
if(APPLE) | ||
set(BIN_INSTALL_DIR ".") | ||
# No LIB_INSTALL_DIR on APPLE, we use BundleUtilities instead. | ||
# No PLUGIN_INSTALL_DIR on APPLE, we use BundleUtilities instead. | ||
# If the install directory is the default then set to a child dir | ||
# of the the binary install. Otherwise we assume the user has specified | ||
# a CMAKE_INSTALL_PREFIX define | ||
# FIXME: there must be a better way of detecting the default vs user set | ||
if(CMAKE_INSTALL_PREFIX MATCHES "/usr/local") | ||
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/bin") | ||
endif() | ||
elseif(WIN32) | ||
set(BIN_INSTALL_DIR ".") | ||
set(LIB_INSTALL_DIR ".") | ||
set(PLUGIN_INSTALL_DIR "plugins") | ||
elseif(NOT ANDROID) | ||
set(BIN_INSTALL_DIR "bin") | ||
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)") | ||
set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}") | ||
set(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/plugins") | ||
endif() | ||
|
||
include_directories( ${CMAKE_SOURCE_DIR} | ||
${CMAKE_BINARY_DIR} | ||
${QT_INCLUDES}) | ||
|
||
set(SQLATE_SRCS | ||
kdthreadrunner.cpp | ||
SqlCondition.cpp | ||
SqlQuery.cpp | ||
SqlQueryBuilderBase.cpp | ||
SqlConditionalQueryBuilderBase.cpp | ||
SqlDeleteQueryBuilder.cpp | ||
SqlSelectQueryBuilder.cpp | ||
SqlInsertQueryBuilder.cpp | ||
SqlUpdateQueryBuilder.cpp | ||
SqlCreateTable.cpp | ||
SqlSchema.cpp | ||
SqlTransaction.cpp | ||
SqlMonitor.cpp | ||
SqlQueryManager.cpp | ||
SqlQueryWatcher.cpp | ||
SqlUtils.cpp | ||
PostgresSchema.cpp | ||
SchemaUpdater.cpp | ||
SqlQueryCache.cpp | ||
) | ||
|
||
qt4_add_resources(sql_resources SqlResources.qrc ) | ||
|
||
add_library(sqlate SHARED ${SQLATE_SRCS} ${sql_resources}) | ||
|
||
if (NOT ANDROID) | ||
set_target_properties(sqlate PROPERTIES | ||
VERSION ${SQLATE_LIBRARY_VERSION} | ||
SOVERSION ${SQLATE_LIBRARY_SO_VERSION} | ||
) | ||
endif() | ||
|
||
set_target_properties(sqlate PROPERTIES | ||
DEFINE_SYMBOL SQLATE_BUILD_SQLATE_LIB | ||
) | ||
|
||
target_link_libraries(sqlate ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSQL_LIBRARY}) | ||
|
||
if(NOT APPLE AND NOT ANDROID) | ||
install(TARGETS sqlate RUNTIME DESTINATION ${BIN_INSTALL_DIR} LIBRARY DESTINATION ${LIB_INSTALL_DIR}) | ||
endif() | ||
|
||
add_executable(sqlschema2dot sqlschema2dot.cpp) | ||
target_link_libraries(sqlschema2dot ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSQL_LIBRARY} sqlate) | ||
|
||
add_custom_target(schema-graph | ||
${CMAKE_CURRENT_BINARY_DIR}/sqlschema2dot > sqlschema.dot && | ||
dot -Tpng sqlschema.dot > sqlschema.png | ||
) | ||
|
||
add_subdirectory(tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
* Author: Volker Krause <[email protected]> | ||
*/ | ||
|
||
#include "PostgresSchema.h" | ||
|
||
namespace Sql { | ||
|
||
DEFINE_SCHEMA( POSTGRES_SCHEMA ) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected] | ||
* Author: Volker Krause <[email protected]> | ||
*/ | ||
|
||
#ifndef POSTGRESSCHEMA_H | ||
#define POSTGRESSCHEMA_H | ||
|
||
#include "SqlSchema_p.h" | ||
#include "sqlate_export.h" | ||
|
||
#include <QDateTime> | ||
|
||
/** | ||
* Schema definition for the PostgreSQL system tables to the extend we need to access them | ||
* @note Do not use this in combination with the create table query builder! | ||
*/ | ||
namespace Sql { | ||
|
||
TABLE( PgUser, SQLATE_EXPORT ) { | ||
SQL_NAME( "pg_user" ); | ||
COLUMN( usename, QString, Null ); | ||
COLUMN( usesysid, int, Null ); | ||
COLUMN( usecreatedb, bool, Null ); | ||
COLUMN( usesuper, bool, Null ); | ||
COLUMN( usecatupd, bool, Null ); | ||
COLUMN( userepl, bool, Null ); | ||
COLUMN( passwd, QString, Null ); | ||
COLUMN( valuntil, QDateTime, Null ); | ||
typedef boost::mpl::vector<usenameType, usesysidType, usecreatedbType, usesuperType, usecatupdType, usereplType, passwdType, valuntilType> columns; | ||
}; | ||
|
||
TABLE( PgGroup, SQLATE_EXPORT ) { | ||
SQL_NAME( "pg_group" ); | ||
COLUMN( groname, QString, Null ); | ||
COLUMN( grosysid, int, Null ); | ||
typedef boost::mpl::vector<gronameType, grosysidType> columns; | ||
}; | ||
|
||
TABLE( PgAuthMembers, SQLATE_EXPORT ) { | ||
SQL_NAME( "pg_auth_members" ); | ||
COLUMN( roleid, int, NotNull ); | ||
COLUMN( member, int, NotNull ); | ||
COLUMN( grantor, int, NotNull ); | ||
COLUMN( admin_option, bool, NotNull ); | ||
typedef boost::mpl::vector<roleidType, memberType, grantorType, admin_optionType> columns; | ||
}; | ||
|
||
#define POSTGRES_SCHEMA (PgUser)(PgGroup)(PgAuthMembers) | ||
|
||
DECLARE_SCHEMA( PostgresSchema, POSTGRES_SCHEMA ); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "SchemaUpdater.h" | ||
|
||
#include "sql.h" | ||
#include "SqlQuery.h" | ||
#include "SqlUtils.h" | ||
|
||
#include <QDebug> | ||
|
||
using namespace Sql; | ||
|
||
SchemaUpdaterBase::SchemaUpdaterBase (int targetVersion, const QString & pluginName /* = QString()*/ , QWidget* parentWidget /*= 0*/, QObject *parent /*= 0*/) : | ||
QObject( parent ), | ||
m_parentWidget(parentWidget), | ||
m_currentVersion(-1), | ||
m_targetVersion(targetVersion), | ||
m_pluginName(pluginName) | ||
{ | ||
} | ||
|
||
QVector<SchemaUpdaterBase::UpdateInfo> SchemaUpdaterBase::pendingUpdates(const QDir & dir) const | ||
{ | ||
QVector<UpdateInfo> updates; | ||
updates.reserve(m_targetVersion - m_currentVersion); | ||
|
||
for ( int i = m_currentVersion + 1; i <= m_targetVersion; ++i ) { | ||
UpdateInfo info; | ||
info.version = i; | ||
const QString fileName = QString::fromLatin1("%1.sql").arg(i); | ||
if (dir.exists(fileName)) { | ||
info.updateFile = dir.absoluteFilePath(fileName); | ||
updates.push_back(info); | ||
} | ||
} | ||
return updates; | ||
} | ||
|
||
void SchemaUpdaterBase::execUpdate ( const QString& updateFile ) | ||
{ | ||
QFile file(updateFile); | ||
if (file.open(QFile::ReadOnly | QIODevice::Text)) { | ||
QTextStream stream(&file); | ||
foreach ( QString statement, SqlUtils::splitQueries(stream.readAll()) ) { | ||
SqlUtils::stripComments(statement); | ||
if (statement.isEmpty()) | ||
continue; | ||
|
||
SqlQuery query; | ||
query.exec(statement); | ||
} | ||
} else { | ||
// coming from a QRC file, always readable... | ||
qFatal("unable to open %s", qPrintable(updateFile)); | ||
} | ||
} | ||
|
||
#include "moc_SchemaUpdater.cpp" |
Oops, something went wrong.