Undefined
By: Guest | Date: Oct 28 2011 16:45 | Format: UnrealScript | Expires: never | Size: 6.83 KB | Hits: 1224
- /**
- * Database - Data provider class.
- * Base class for all data providers gathering data from loaded databases.
- */
- dependson(DB_DLLAPI);
- //=============================================================================
- // Structs & Enumerations
- //=============================================================================
- struct SBindInfo
- {
- var int BindType;
- var string BindParam;
- var int BindIdx;
- var string BindValue;
- };
- struct SDataItem
- {
- var array<string> Data;
- };
- struct SDataSet
- {
- var array<string> ColumnNames;
- var array<int> ColumnTypes;
- var array<int> ColumnDetails;
- var int DataCount;
- var array<SDataItem> Data;
- };
- enum ECommandType
- {
- ECT_SELECT,
- ECT_UPDATE,
- ECT_INSERT,
- ECT_DELETE,
- ECT_COMMAND_COUNT
- };
- //=============================================================================
- // Variables
- //=============================================================================
- var DB_DLLAPI mDLLAPI; // backreference to DB_Manager.mDLLAPI
- var int mDBId; // referenced database ID
- var string mStatement; // data provider statement
- var string mCommands[4];
- var private SDataSet mDataSet; // current dataset of this provider
- //=============================================================================
- // Functions
- //=============================================================================
- function InitCommands()
- {
- local int il;
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- for(il=0; il<ECT_COMMAND_COUNT; il++)
- mDLLAPI.SQL_prepareStatement(mCommands[il]);
- }
- function SetCommand(ECommandType aType, string aCommand)
- {
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- mCommands[aType] = aCommand;
- mDLLAPI.SQL_prepareStatement(aCommand);
- }
- //=============================================================================
- // Database handling
- //=============================================================================
- function fill(int aResultIdx, out SDataSet aDataSet)
- {
- local int il, lColumnCount;
- local string lColumnName;
- local int lColumnType;
- local int lColumnDetail;
- local SDataItem lNewDataItem;
- local int lNewIntVal, lNewDataCount;
- local float lNewFloatVal;
- local string lNewStrVal;
- aDataSet.ColumnNames.Length = 0;
- aDataSet.ColumnTypes.Length = 0;
- aDataSet.ColumnDetails.Length = 0;
- aDataSet.DataCount = 0;
- aDataSet.Data.Length = 0;
- if(aResultIdx >= 0)
- {
- lColumnCount = mDLLAPI.SQL_getColumnCount(aResultIdx);
- for(il=0; il<lColumnCount; ++il)
- {
- `DB_InitString(lColumnName,255);
- mDLLAPI.SQL_getColumnInfo(aResultIdx, il, lColumnName, lColumnType, lColumnDetail);
- aDataSet.ColumnNames[il] = lColumnName;
- aDataSet.ColumnTypes[il] = lColumnType;
- aDataSet.ColumnDetails[il] = lColumnDetail;
- }
- lNewDataCount = 0;
- while(mDLLAPI.SQL_nextResult(aResultIdx))
- {
- lNewDataCount++;
- lNewDataItem.Data.Length = 0;
- for(il=0; il<lColumnCount; ++il)
- {
- switch(aDataSet.ColumnTypes[il])
- {
- case 0:
- lNewDataItem.Data[il] = "";
- break;
- case 1:
- mDLLAPI.SQL_getIntVal(aResultIdx, aDataSet.ColumnNames[il], lNewIntVal);
- lNewDataItem.Data[il] = string(lNewIntVal);
- break;
- case 2:
- mDLLAPI.SQL_getFloatVal(aResultIdx, aDataSet.ColumnNames[il], lNewFloatVal);
- lNewDataItem.Data[il] = string(lNewFloatVal);
- break;
- case 3:
- `DB_InitString(lNewStrVal, aDataSet.ColumnDetails[il]);
- mDLLAPI.SQL_getStringVal(aResultIdx, aDataSet.ColumnNames[il], lNewStrVal);
- lNewDataItem.Data[il] = lNewStrVal;
- break;
- }
- }
- aDataSet.Data[aDataSet.Data.Length] = lNewDataItem;
- }
- aDataSet.DataCount = lNewDataCount;
- }
- }
- //=============================================================================
- // DataProvider control functions
- //=============================================================================
- function Select()
- {
- local int lResIdx;
- if (mCommands[ECT_SELECT] == "")
- return;
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- mDLLAPI.SQL_prepareStatement(mCommands[ECT_SELECT]);
- lResIdx = mDLLAPI.SQL_executeStatement();
- fill(lResIdx, mDataSet);
- }
- function Update()
- {
- if (mCommands[ECT_UPDATE] == "")
- return;
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- mDLLAPI.SQL_prepareStatement(mCommands[ECT_UPDATE]);
- mDLLAPI.SQL_executeStatement();
- Select();
- }
- function Insert()
- {
- if (mCommands[ECT_INSERT] == "")
- return;
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- mDLLAPI.SQL_prepareStatement(mCommands[ECT_INSERT]);
- mDLLAPI.SQL_executeStatement();
- Select();
- }
- function Delete()
- {
- if (mCommands[ECT_DELETE] == "")
- return;
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- mDLLAPI.SQL_prepareStatement(mCommands[ECT_DELETE]);
- mDLLAPI.SQL_executeStatement();
- Select();
- }
- function BindValues(ECommandType aCommand, array<SBindInfo> aBindingInfo)
- {
- local int il, lBindInfoCount;
- if (mCommands[aCommand] == "")
- return;
- if (!mDLLAPI.SQL_selectDatabase(mDBId))
- return;
- mDLLAPI.SQL_prepareStatement(mCommands[ECT_DELETE]);
- lBindInfoCount = aBindingInfo.Length;
- for(il=0; il<lBindInfoCount; il++)
- {
- switch(aBindingInfo[il].BindType)
- {
- case 0:
- break;
- case 1:
- if (aBindingInfo[il].BindParam != "" && aBindingInfo[il].BindIdx == -1)
- mDLLAPI.SQL_bindNamedValueInt(aBindingInfo[il].BindParam, int(aBindingInfo[il].BindValue));
- else if (aBindingInfo[il].BindIdx >= 0)
- mDLLAPI.SQL_bindValueInt(aBindingInfo[il].BindIdx, int(aBindingInfo[il].BindValue));
- break;
- case 2:
- if (aBindingInfo[il].BindParam != "" && aBindingInfo[il].BindIdx == -1)
- mDLLAPI.SQL_bindNamedValueFloat(aBindingInfo[il].BindParam, float(aBindingInfo[il].BindValue));
- else if (aBindingInfo[il].BindIdx >= 0)
- mDLLAPI.SQL_bindValueFloat(aBindingInfo[il].BindIdx, float(aBindingInfo[il].BindValue));
- break;
- case 3:
- if (aBindingInfo[il].BindParam != "" && aBindingInfo[il].BindIdx == -1)
- mDLLAPI.SQL_bindNamedValueString(aBindingInfo[il].BindParam, aBindingInfo[il].BindValue);
- else if (aBindingInfo[il].BindIdx >= 0)
- mDLLAPI.SQL_bindValueString(aBindingInfo[il].BindIdx, aBindingInfo[il].BindValue);
- break;
- }
- }
- }
- DefaultProperties
- {
- TickGroup=TG_DuringAsyncWork
- bHidden=TRUE
- Physics=PHYS_None
- bReplicateMovement=FALSE
- bStatic=FALSE
- bNoDelete=FALSE
- Name="Default__DB_DataProvider"
- }
Latest pastes
1 hours ago
11 hours ago
1 days ago
2 days ago
2 days ago