2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Initial Commit of CyanWorlds.com Engine Open Source Client/Plugin

This commit is contained in:
JWPlatt
2011-03-12 12:34:52 -05:00
commit a20a222fc2
3976 changed files with 1301356 additions and 0 deletions

View File

@ -0,0 +1,39 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlAllIncludes.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSQLLIB_PRIVATE_PNSQLALLINCLUDES_H
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlAllIncludes.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSQLLIB_PRIVATE_PNSQLALLINCLUDES_H
#include "pnSqlConn.h"
#include "pnSqlUtil.h"

View File

@ -0,0 +1,292 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlConn.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSQLLIB_PRIVATE_PNSQLCONN_H
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlConn.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSQLLIB_PRIVATE_PNSQLCONN_H
/*****************************************************************************
*
* Types
*
***/
struct SqlConn;
struct SqlStmt;
struct SqlTrans;
typedef void (* FSqlBindPrepare)(
SqlStmt * stmt,
ARRAY(byte) * bindData
);
/*****************************************************************************
*
* Init API
*
***/
SqlConn * SqlConnCreate (
const wchar connectStr[],
unsigned maxConnections,
unsigned transTimeoutMs
);
void SqlConnShutdown (SqlConn * conn);
void SqlConnDestroy (SqlConn * conn);
/*****************************************************************************
*
* Ad-hoc query API
*
* For queries that will be performed and therefore don't want to incur
* binding and preparing overhead.
*
***/
SqlStmt * SqlConnAllocStmt (
SqlConn * conn
);
void SqlConnFreeStmt (
SqlStmt * stmt
);
void SqlStmtSetAttr (
SqlStmt * stmt,
int attr,
void * valPtr,
int strLen
);
/*****************************************************************************
*
* "Optimized" query API
*
* The "prepare" function will only be called once for a statement, and it
* will retain its bindings and memory set by the prepare function until
* SqlConnDisconnect is called (i.e. until program shutdown).
*
*
*
***/
SqlStmt * SqlConnAllocStmt (
SqlConn * conn,
FSqlBindPrepare prepare,
byte ** bindData // [OUT]
);
/*****************************************************************************
*
* Error handling
*
***/
typedef void (* FSqlConnErrorHandler)(
int result,
const wchar function[],
const wchar command[],
const char diagnostics[], // double-null terminated
void * userParam
);
void SqlConnSetErrorHandler (
SqlStmt * stmt,
FSqlConnErrorHandler handler,
void * userParam
);
/*****************************************************************************
*
* Output binding
*
***/
// Reset all changes done by SqlConnBindCol*() functions
void SqlConnBindColReset (SqlStmt * stmt);
// Obtain multiple rows in a result set by rows or columns
void SqlConnBindColMode (
SqlStmt * stmt,
SQLUINTEGER * rowCount, // SQL_ATTR_ROWS_FETCHED_PTR
SQLUINTEGER structSize, // SQL_ATTR_ROW_BIND_TYPE
SQLUINTEGER arraySize, // SQL_ATTR_ROW_ARRAY_SIZE
SQLUSMALLINT * statusArray // SQL_ATTR_ROW_STATUS_PTR
);
// Bind parameters of various types
void SqlConnBindCol (
SqlStmt * stmt,
SQLINTEGER targetType,
SQLPOINTER targetValue,
SQLINTEGER bufferLength,
SQLINTEGER * indPtr
);
/*****************************************************************************
*
* Parameter binding
*
***/
// Reset all changes done by SqlConnBindParameter*() functions
void SqlConnBindParameterReset (SqlStmt * stmt);
// Set multiple rows in an output set by rows or columns
void SqlConnBindParameterMode (
SqlStmt * stmt,
SQLUINTEGER * processCount, // SQL_ATTR_PARAMS_PROCESSED_PTR
SQLUINTEGER structSize, // SQL_ATTR_PARAM_BIND_TYPE
SQLUINTEGER arraySize, // SQL_ATTR_PARAMSET_SIZE
SQLUSMALLINT * statusArray // SQL_ATTR_PARAM_STATUS_PTR
);
// Bind parameters of various types
void SqlConnBindParameter (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLINTEGER valueType,
SQLINTEGER parameterType,
SQLUINTEGER columnSize,
SQLINTEGER decimalDigits,
SQLPOINTER parameterValuePtr,
SQLINTEGER bufferLength,
SQLINTEGER * indPtr
);
void SqlConnBindParameterInt (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLINTEGER * parameterValuePtr,
SQLINTEGER * indPtr
);
void SqlConnBindParameterUInt (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLUINTEGER * parameterValuePtr,
SQLINTEGER * indPtr
);
void SqlConnBindParameterString (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLUINTEGER columnSize, // bytes, NOT chars
SQLWCHAR * parameterValuePtr,
SQLINTEGER * indPtr
);
void SqlConnBindParameterStringA (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLUINTEGER columnSize, // bytes, NOT chars
SQLCHAR * parameterValuePtr,
SQLINTEGER * indPtr
);
/****************************************************************************
*
* Execution
*
***/
int SqlConnExecDirect (
SqlStmt * stmt,
const wchar string[]
);
int SqlConnPrepare (
SqlStmt * stmt,
const wchar string[]
);
int SqlConnExecute (
SqlStmt * stmt
);
int SqlConnFetch (
SqlStmt * stmt
);
int SqlConnMoreResults (
SqlStmt * stmt
);
int SqlConnParamData (
SqlStmt * stmt,
SQLPOINTER * put
);
bool SqlConnPutData (
SqlStmt * stmt,
SQLPOINTER data,
SQLINTEGER bytes
);
int SqlConnGetData (
SqlStmt * stmt,
SQLINTEGER columnNumber,
SQLINTEGER targetType,
SQLPOINTER targetValue,
SQLINTEGER bufferLength,
SQLINTEGER * indPtr
);
void SqlConnCloseCursor (
SqlStmt * stmt
);
int SqlConnNumResultCols (
SqlStmt * stmt
);
int SqlConnDescribeCol (
SqlStmt * stmt,
SQLSMALLINT columnNumber,
SQLWCHAR * columnName,
SQLSMALLINT bufferLength,
SQLSMALLINT * nameLengthPtr,
SQLSMALLINT * dataTypePtr,
SQLUINTEGER * columnSizePtr,
SQLSMALLINT * decimalDigitsPtr,
SQLSMALLINT * nullablePtr
);
/*****************************************************************************
*
* Performance API
*
***/
enum {
kSqlConnPerfConnDesired,
kSqlConnPerfConnCurrent,
kSqlConnPerfConnPending,
kSqlConnPerfConnCheckDead,
kSqlConnPerfCacheHits,
kSqlConnPerfCacheMisses,
kSqlConnNumPerf
};
unsigned SqlConnGetPerf (unsigned id);

View File

@ -0,0 +1,180 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlUtil.cpp
*
***/
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Exports
*
***/
//===========================================================================
void SqlConnBindParameterInputGuid (
SqlStmt * stmt,
Uuid * uuid,
SQLINTEGER * uuidLen
) {
SqlConnBindParameter(
stmt,
SQL_PARAM_INPUT,
SQL_C_BINARY,
SQL_BINARY,
sizeof(Uuid),
0,
uuid,
sizeof(Uuid),
uuidLen
);
}
//===========================================================================
void SqlConnBindParameterOutputGuid (
SqlStmt * stmt,
Uuid * uuid,
SQLINTEGER * uuidLen
) {
SqlConnBindParameter(
stmt,
SQL_PARAM_OUTPUT,
SQL_C_BINARY,
SQL_BINARY,
sizeof(Uuid),
0,
uuid,
sizeof(Uuid),
uuidLen
);
}
//===========================================================================
void SqlConnBindParameterBigInt (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLBIGINT * parameterValuePtr,
SQLINTEGER * indPtr
) {
SqlConnBindParameter(
stmt,
inputOutputType,
SQL_C_SBIGINT,
SQL_BIGINT,
sizeof(qword),
0,
parameterValuePtr,
0,
indPtr
);
}
//===========================================================================
bool SqlConnGetBlobData (
SqlStmt * stmt,
unsigned colIndex,
ARRAY(byte) * buffer,
unsigned * bytesAdded
) {
// Since a number of routines use this function, set the chunk size to be
// fairly large to avoid the necessity of reallocing the block, and further
// to prevent memory fragmentation by allocating variously sized blocks.
// In for a penny, in for a pound...
const unsigned CHUNK_SIZE = 32 * 1024;
SQLINTEGER length = CHUNK_SIZE - 1;
unsigned bytes = buffer->Bytes();
*bytesAdded = 0 - bytes;
for (;;) {
// Allocate memory that is evenly aligned to CHUNK_SIZE, which
// reduces memory fragmentation by allocating on 32K multiples.
// Use SetCount() instead of New() to ensure that this is true
// even if the buffer already contains data.
buffer->SetCount(
MathNextMultiplePow2(
buffer->Bytes() + length,
CHUNK_SIZE
)
);
// Read column data
int result = SqlConnGetData(
stmt,
colIndex,
SQL_C_BINARY,
buffer->Ptr() + bytes,
buffer->Bytes() - bytes,
&length
);
// Handle SQL_NO_TOTAL and SQL_NULL_DATA values
if (length < 0) {
buffer->ZeroCount();
*bytesAdded = 0;
return result == SQL_SUCCESS;
}
// Keep getting data until we have the entire buffer
if (result == SQL_SUCCESS_WITH_INFO) {
// length contains the number of remaining bytes
bytes = buffer->Bytes();
continue;
}
// Is the buffer complete?
if (result == SQL_SUCCESS) {
buffer->SetCountFewer(length + bytes);
*bytesAdded += buffer->Bytes();
return true;
}
// An error occurred
break;
}
buffer->ZeroCount();
*bytesAdded = 0;
return false;
}
//===========================================================================
int SqlConnPutBlobData (
SqlStmt * stmt,
unsigned bytes,
const byte data[]
) {
int result;
SQLPOINTER putPtr;
while (SQL_NEED_DATA == (result = SqlConnParamData(stmt, &putPtr))) {
if (!SqlConnPutData(stmt, const_cast<byte *>(data), bytes))
return SQL_ERROR;
}
return result;
}

View File

@ -0,0 +1,70 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
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 3 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, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlUtil.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSQLLIB_PRIVATE_PNSQLUTIL_H
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnSqlLib/Private/pnSqlUtil.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSQLLIB_PRIVATE_PNSQLUTIL_H
/*****************************************************************************
*
* SqlUtil API
*
***/
void SqlConnBindParameterInputGuid (
SqlStmt * stmt,
Uuid * uuid,
SQLINTEGER * uuidLen
);
void SqlConnBindParameterOutputGuid (
SqlStmt * stmt,
Uuid * uuid,
SQLINTEGER * uuidLen
);
void SqlConnBindParameterBigInt (
SqlStmt * stmt,
SQLINTEGER inputOutputType,
SQLBIGINT * parameterValuePtr,
SQLINTEGER * indPtr
);
bool SqlConnGetBlobData (
SqlStmt * stmt,
unsigned colIndex,
ARRAY(byte) * buffer,
unsigned * bytesAdded
);
int SqlConnPutBlobData (
SqlStmt * stmt,
unsigned bytes,
const byte data[]
);