mirror of
https://github.com/mangosfour/server.git
synced 2025-12-27 10:37:02 +00:00
Merge commit 'origin/master' into 310
This commit is contained in:
commit
55d6fbe3cb
46 changed files with 325 additions and 1369 deletions
|
|
@ -37,10 +37,8 @@ typedef DatabasePostgre DatabaseType;
|
|||
#define _OFFSET_ "LIMIT 1 OFFSET %d"
|
||||
#else
|
||||
#include "Database/QueryResultMysql.h"
|
||||
#include "Database/QueryResultSqlite.h"
|
||||
#include "Database/Database.h"
|
||||
#include "Database/DatabaseMysql.h"
|
||||
#include "Database/DatabaseSqlite.h"
|
||||
typedef DatabaseMysql DatabaseType;
|
||||
#define _LIKE_ "LIKE"
|
||||
#define _TABLE_SIM_ "`"
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef DO_POSTGRESQL
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
|
||||
DatabaseSqlite::DatabaseSqlite() : Database(), mSqlite(0)
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseSqlite::~DatabaseSqlite()
|
||||
{
|
||||
if (mSqlite)
|
||||
sqlite_close(mSqlite);
|
||||
}
|
||||
|
||||
bool DatabaseSqlite::Initialize(const char *infoString)
|
||||
{
|
||||
if(!Database::Initialize(infoString))
|
||||
return false;
|
||||
|
||||
char *errmsg;
|
||||
|
||||
mSqlite = sqlite_open(infoString, 0, &errmsg);
|
||||
|
||||
if (!mSqlite)
|
||||
{
|
||||
|
||||
if (errmsg)
|
||||
sqlite_freemem(errmsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QueryResult* DatabaseSqlite::Query(const char *sql)
|
||||
{
|
||||
char *errmsg;
|
||||
|
||||
if (!mSqlite)
|
||||
return 0;
|
||||
|
||||
char **tableData;
|
||||
int rowCount;
|
||||
int fieldCount;
|
||||
|
||||
sqlite_get_table(mSqlite, sql, &tableData, &rowCount, &fieldCount, &errmsg);
|
||||
|
||||
if (!rowCount)
|
||||
return 0;
|
||||
|
||||
if (!tableData)
|
||||
{
|
||||
|
||||
if (errmsg)
|
||||
sqlite_freemem(errmsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
QueryResultSqlite *queryResult = new QueryResultSqlite(tableData, rowCount, fieldCount);
|
||||
if(!queryResult)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
queryResult->NextRow();
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
bool DatabaseSqlite::Execute(const char *sql)
|
||||
{
|
||||
char *errmsg;
|
||||
|
||||
if (!mSqlite)
|
||||
return false;
|
||||
|
||||
if(sqlite_exec(mSqlite, sql, NULL, NULL, &errmsg) != SQLITE_OK)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef DO_POSTGRESQL
|
||||
|
||||
#ifndef _DATABASESQLITE_H
|
||||
#define _DATABASESQLITE_H
|
||||
|
||||
#include <sqlite/sqlite.h>
|
||||
|
||||
class DatabaseSqlite : public Database
|
||||
{
|
||||
public:
|
||||
DatabaseSqlite();
|
||||
~DatabaseSqlite();
|
||||
|
||||
bool Initialize(const char *infoString);
|
||||
|
||||
QueryResult* Query(const char *sql);
|
||||
bool Execute(const char *sql);
|
||||
|
||||
operator bool () const { return mSqlite != NULL; }
|
||||
|
||||
private:
|
||||
sqlite *mSqlite;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -38,8 +38,6 @@ libmangosdatabase_a_SOURCES = \
|
|||
DatabasePostgre.cpp \
|
||||
DatabaseMysql.h \
|
||||
DatabasePostgre.h \
|
||||
DatabaseSqlite.cpp \
|
||||
DatabaseSqlite.h \
|
||||
DBCEnums.h \
|
||||
Field.cpp \
|
||||
Field.h \
|
||||
|
|
@ -50,8 +48,6 @@ libmangosdatabase_a_SOURCES = \
|
|||
QueryResultMysql.h \
|
||||
QueryResultPostgre.cpp \
|
||||
QueryResultPostgre.h \
|
||||
QueryResultSqlite.cpp \
|
||||
QueryResultSqlite.h \
|
||||
SQLStorage.cpp \
|
||||
SQLStorage.h \
|
||||
SQLStorageImpl.h \
|
||||
|
|
|
|||
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef DO_POSTGRESQL
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
|
||||
QueryResultSqlite::QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount) :
|
||||
QueryResult(rowCount, fieldCount), mTableData(tableData), mTableIndex(0)
|
||||
{
|
||||
mCurrentRow = new Field[mFieldCount];
|
||||
|
||||
for (uint32 i = 0; i < mFieldCount; i++)
|
||||
{
|
||||
mFieldNames[i] = mTableData[i];
|
||||
mCurrentRow[i].SetType(Field::DB_TYPE_UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
QueryResultSqlite::~QueryResultSqlite()
|
||||
{
|
||||
EndQuery();
|
||||
}
|
||||
|
||||
bool QueryResultSqlite::NextRow()
|
||||
{
|
||||
int startIndex;
|
||||
uint32 i;
|
||||
|
||||
if (!mTableData)
|
||||
return false;
|
||||
|
||||
if (mTableIndex >= mRowCount)
|
||||
{
|
||||
EndQuery();
|
||||
return false;
|
||||
}
|
||||
|
||||
startIndex = (mTableIndex + 1) * mFieldCount;
|
||||
for (i = 0; i < mFieldCount; i++)
|
||||
{
|
||||
mCurrentRow[i].SetValue(mTableData[startIndex + i]);
|
||||
}
|
||||
|
||||
++mTableIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
void QueryResultSqlite::EndQuery()
|
||||
{
|
||||
if (mCurrentRow)
|
||||
{
|
||||
delete [] mCurrentRow;
|
||||
mCurrentRow = NULL;
|
||||
}
|
||||
if (mTableData)
|
||||
{
|
||||
sqlite_free_table(mTableData);
|
||||
mTableData = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
enum Field::DataTypes QueryResultSqlite::ConvertNativeType(const char* sqliteType) const
|
||||
{
|
||||
if (sqliteType)
|
||||
{
|
||||
switch (*sqliteType)
|
||||
{
|
||||
case 'S':
|
||||
return Field::DB_TYPE_STRING;
|
||||
case 'I':
|
||||
return Field::DB_TYPE_INTEGER;
|
||||
case 'F':
|
||||
return Field::DB_TYPE_FLOAT;
|
||||
default:
|
||||
return Field::DB_TYPE_UNKNOWN;
|
||||
};
|
||||
}
|
||||
return Field::DB_TYPE_UNKNOWN;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef DO_POSTGRESQL
|
||||
|
||||
#if !defined(QUERYRESULTSQLITE_H)
|
||||
#define QUERYRESULTSQLITE_H
|
||||
|
||||
#include <sqlite/sqlite.h>
|
||||
|
||||
class QueryResultSqlite : public QueryResult
|
||||
{
|
||||
public:
|
||||
QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount);
|
||||
|
||||
~QueryResultSqlite();
|
||||
|
||||
bool NextRow();
|
||||
|
||||
private:
|
||||
enum Field::DataTypes ConvertNativeType(const char* sqliteType) const;
|
||||
void EndQuery();
|
||||
|
||||
char **mTableData;
|
||||
uint32 mTableIndex;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "7692"
|
||||
#define REVISION_NR "7713"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue