fix data array export error

This commit is contained in:
yyc12345 2022-08-07 23:42:02 +08:00
parent 5f715de4a9
commit 0b39fd6480
4 changed files with 111 additions and 76 deletions

View File

@ -41,36 +41,32 @@ namespace SSMaterializer {
// open mDb // open mDb
int result; int result;
result = sqlite3_open(file, &mDb); result = sqlite3_open(file, &mDb);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto open_fail;
// disable synchronous // disable synchronous
result = sqlite3_exec(mDb, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); result = sqlite3_exec(mDb, "PRAGMA synchronous = OFF;", NULL, NULL, NULL);
if (result != SQLITE_OK) goto fail; if (result != SQLITE_OK) goto fail;
// do some custom Init
if (!Init()) goto fail;
//start job
sqlite3_exec(mDb, "begin;", NULL, NULL, NULL);
return; return;
fail: fail:
sqlite3_close(mDb);
open_fail:
mDb = NULL; mDb = NULL;
} }
SSMaterializerDatabase::~SSMaterializerDatabase() { SSMaterializerDatabase::~SSMaterializerDatabase() {
if (mDb == NULL) return; if (mDb == NULL) return;
int result;
//free all cached stmts and commit job //free all cached stmts and commit job
for (auto it = mStmtCache.begin(); it != mStmtCache.end(); it++) { for (auto it = mStmtCache.begin(); it != mStmtCache.end(); it++) {
if (*it != NULL) if (*it != NULL) {
sqlite3_finalize(*it); result = sqlite3_finalize(*it);
if (result != SQLITE_OK) goto fail;
}
} }
sqlite3_exec(mDb, "commit;", NULL, NULL, NULL);
// do some custom job
Finalize();
fail:
//release res //release res
sqlite3_close(mDb); sqlite3_close(mDb);
mDb = NULL; mDb = NULL;
@ -87,34 +83,58 @@ namespace SSMaterializer {
return stmt; return stmt;
} }
BOOL SSMaterializerDatabase::Init() {
return TRUE;
}
BOOL SSMaterializerDatabase::Finalize() {
return TRUE;
}
#pragma endregion #pragma endregion
#pragma region sub-database constructor, deconstructor and help functions #pragma region sub-database constructor, deconstructor and help functions
DocumentDatabase::DocumentDatabase(const char* file, CKParameterManager* paramManager) : DocumentDatabase::DocumentDatabase(const char* file, CKParameterManager* paramManager) :
SSMaterializerDatabase(file), mUniqueAttr(), mUniqueObj(), mDbHelper(paramManager) { SSMaterializerDatabase(file), mUniqueAttr(), mUniqueObj(), mDbHelper(paramManager) {
; if (!Init()) goto fail;
//start job
int result = sqlite3_exec(mDb, "begin;", NULL, NULL, NULL);
if (result != SQLITE_OK) goto fail;
fail:
sqlite3_close(mDb);
mDb = NULL;
} }
DocumentDatabase::~DocumentDatabase() { DocumentDatabase::~DocumentDatabase() {
; if (!Finalize()) goto fail;
//commit job
int result = sqlite3_exec(mDb, "commit;", NULL, NULL, NULL);
if (result != SQLITE_OK) goto fail;
fail:
sqlite3_close(mDb);
mDb = NULL;
} }
EnvironmentDatabase::EnvironmentDatabase(const char* file) : EnvironmentDatabase::EnvironmentDatabase(const char* file) :
SSMaterializerDatabase(file), mDbHelper() { SSMaterializerDatabase(file), mDbHelper() {
; if (!Init()) goto fail;
//start job
int result = sqlite3_exec(mDb, "begin;", NULL, NULL, NULL);
if (result != SQLITE_OK) goto fail;
fail:
sqlite3_close(mDb);
mDb = NULL;
} }
EnvironmentDatabase::~EnvironmentDatabase() { EnvironmentDatabase::~EnvironmentDatabase() {
; if (!Finalize()) goto fail;
//commit job
int result = sqlite3_exec(mDb, "commit;", NULL, NULL, NULL);
if (result != SQLITE_OK) goto fail;
fail:
sqlite3_close(mDb);
mDb = NULL;
} }
BOOL DocumentDatabase::is_attr_duplicated(DataStruct::EXPAND_CK_ID parents) { BOOL DocumentDatabase::is_attr_duplicated(DataStruct::EXPAND_CK_ID parents) {
@ -149,9 +169,6 @@ namespace SSMaterializer {
if (result != SQLITE_OK) { return FALSE; } if (result != SQLITE_OK) { return FALSE; }
BOOL DocumentDatabase::Init() { BOOL DocumentDatabase::Init() {
// execute parent first
if (!SSMaterializerDatabase::Init()) return FALSE;
int result; int result;
//Init table //Init table
@ -185,9 +202,6 @@ if (result != SQLITE_OK) { return FALSE; }
} }
BOOL DocumentDatabase::Finalize() { BOOL DocumentDatabase::Finalize() {
// execute parent first
if (!SSMaterializerDatabase::Finalize()) return FALSE;
//create index for quick select in SuperScriptDecorator //create index for quick select in SuperScriptDecorator
int result; int result;
@ -211,9 +225,6 @@ if (result != SQLITE_OK) { return FALSE; }
} }
BOOL EnvironmentDatabase::Init() { BOOL EnvironmentDatabase::Init() {
// execute parent first
if (!SSMaterializerDatabase::Init()) return FALSE;
int result; int result;
//init table //init table
@ -231,9 +242,6 @@ if (result != SQLITE_OK) { return FALSE; }
} }
BOOL EnvironmentDatabase::Finalize() { BOOL EnvironmentDatabase::Finalize() {
// execute parent first
if (!SSMaterializerDatabase::Finalize()) return FALSE;
return TRUE; return TRUE;
} }

View File

@ -311,8 +311,6 @@ namespace SSMaterializer {
protected: protected:
sqlite3_stmt* CreateStmt(const char* stmt); sqlite3_stmt* CreateStmt(const char* stmt);
virtual BOOL Init();
virtual BOOL Finalize();
sqlite3* mDb; sqlite3* mDb;
std::vector<sqlite3_stmt*> mStmtCache; std::vector<sqlite3_stmt*> mStmtCache;
@ -350,8 +348,8 @@ namespace SSMaterializer {
BOOL is_obj_duplicated(DataStruct::EXPAND_CK_ID parents); BOOL is_obj_duplicated(DataStruct::EXPAND_CK_ID parents);
protected: protected:
BOOL Init() override; BOOL Init();
BOOL Finalize() override; BOOL Finalize();
std::set<DataStruct::EXPAND_CK_ID> mUniqueAttr; std::set<DataStruct::EXPAND_CK_ID> mUniqueAttr;
std::set<DataStruct::EXPAND_CK_ID> mUniqueObj; std::set<DataStruct::EXPAND_CK_ID> mUniqueObj;
@ -370,8 +368,8 @@ namespace SSMaterializer {
void write_variable(DataStruct::dbenv_variable& data); void write_variable(DataStruct::dbenv_variable& data);
protected: protected:
BOOL Init() override; BOOL Init();
BOOL Finalize() override; BOOL Finalize();
}; };
} }

View File

@ -504,6 +504,7 @@ namespace SSMaterializer {
// write row data // write row data
switch (coltype) { switch (coltype) {
case CKARRAYTYPE_INT: case CKARRAYTYPE_INT:
{
for (int row = 0; row < rows; ++row) { for (int row = 0; row < rows; ++row) {
mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.column = col;
mDb->mDbHelper.array_cell.row = row; mDb->mDbHelper.array_cell.row = row;
@ -514,8 +515,10 @@ namespace SSMaterializer {
mDb->write_array_cell(mDb->mDbHelper.array_cell); mDb->write_array_cell(mDb->mDbHelper.array_cell);
} }
break; }
break;
case CKARRAYTYPE_FLOAT: case CKARRAYTYPE_FLOAT:
{
for (int row = 0; row < rows; ++row) { for (int row = 0; row < rows; ++row) {
mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.column = col;
mDb->mDbHelper.array_cell.row = row; mDb->mDbHelper.array_cell.row = row;
@ -526,8 +529,10 @@ namespace SSMaterializer {
mDb->write_array_cell(mDb->mDbHelper.array_cell); mDb->write_array_cell(mDb->mDbHelper.array_cell);
} }
break; }
break;
case CKARRAYTYPE_STRING: case CKARRAYTYPE_STRING:
{
for (int row = 0; row < rows; ++row) { for (int row = 0; row < rows; ++row) {
mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.column = col;
mDb->mDbHelper.array_cell.row = row; mDb->mDbHelper.array_cell.row = row;
@ -540,43 +545,66 @@ namespace SSMaterializer {
mDb->write_array_cell(mDb->mDbHelper.array_cell); mDb->write_array_cell(mDb->mDbHelper.array_cell);
} }
break; }
break;
case CKARRAYTYPE_OBJECT: case CKARRAYTYPE_OBJECT:
for (int row = 0; row < rows; ++row) {
mDb->mDbHelper.array_cell.column = col;
mDb->mDbHelper.array_cell.row = row;
mDb->mDbHelper.array_cell.parent = parents;
CKObject* obj = cache->GetElementObject(row, col);
if (obj == NULL) continue; // fail to get obj
CopyCKString(mDb->mDbHelper.array_cell.showcase, obj->GetName());
mDb->mDbHelper.array_cell.inner_param = obj->GetID();
mDb->write_array_cell(mDb->mDbHelper.array_cell);
// dig more data for it
DigObjectData(obj, mDb, obj->GetID());
}
break;
case CKARRAYTYPE_PARAMETER: case CKARRAYTYPE_PARAMETER:
{
// due to Virtools shit document.
// although column has indicate current column is object or parameter.
// but it can not ensure value is CKParameter when column type is parameter.
// for example, Parameter - Array will return a CKDataArray, not CKParameter.
// so we put these 2 type together and check it in runtime to
// use different output.
CKObject* obj = NULL;
CKParameter* p = NULL;
CK_CLASSID objcls;
int param_size = 0;
for (int row = 0; row < rows; ++row) { for (int row = 0; row < rows; ++row) {
mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.column = col;
mDb->mDbHelper.array_cell.row = row; mDb->mDbHelper.array_cell.row = row;
mDb->mDbHelper.array_cell.parent = parents; mDb->mDbHelper.array_cell.parent = parents;
CKParameter* p = (CKParameter*)cache->GetElementObject(row, col); // check get status
if (p == NULL) continue; // fail to get obj obj = cache->GetElementObject(row, col);
int count = p->GetStringValue(NULL, FALSE); if (obj == NULL) {
mDb->mDbHelper.array_cell.showcase.resize(count); // fail to get obj
p->GetStringValue((char*)mDb->mDbHelper.array_cell.showcase.data(), FALSE); mDb->mDbHelper.array_cell.showcase = "(null)";
mDb->mDbHelper.array_cell.inner_param = p->GetID(); mDb->mDbHelper.array_cell.inner_param = -1;
} else {
// split normal obj and param obj
// use class id
objcls = obj->GetClassID();
if (objcls == CKCID_PARAMETER || objcls == CKCID_PARAMETERLOCAL || objcls == CKCID_PARAMETEROUT) {
// CKParameter
p = (CKParameter*)obj;
param_size = p->GetStringValue(NULL, FALSE);
mDb->mDbHelper.array_cell.showcase.resize(param_size);
p->GetStringValue((char*)mDb->mDbHelper.array_cell.showcase.data(), FALSE);
mDb->mDbHelper.array_cell.inner_param = p->GetID();
// dig more data for it.
DigParameterData(p, mDb, p->GetID());
} else {
// normal CKObject
Utils::StdstringPrintf(mDb->mDbHelper.array_cell.showcase, "%s(%s)",
obj->GetName() ? obj->GetName() : "!!UNKNOW!!",
obj->GetClassNameA() ? obj->GetClassNameA() : "!!UNKNOW!!");
mDb->mDbHelper.array_cell.inner_param = obj->GetID();
// dig more data for it
DigObjectData(obj, mDb, obj->GetID());
}
}
mDb->write_array_cell(mDb->mDbHelper.array_cell); mDb->write_array_cell(mDb->mDbHelper.array_cell);
// dig more data for it.
DigParameterData(p, mDb, p->GetID());
} }
break; }
break;
} }
} }
@ -592,9 +620,9 @@ namespace SSMaterializer {
if (mDb->is_obj_duplicated(parents)) return; if (mDb->is_obj_duplicated(parents)) return;
DataDictWritter("obj.id", (long)o->GetID(), mDb, parents); DataDictWritter("obj.id", (long)o->GetID(), mDb, parents);
DataDictWritter("obj.name", o->GetName() ? o->GetName() : "", mDb, parents); DataDictWritter("obj.name", o->GetName() ? o->GetName() : "!!UNKNOW!!", mDb, parents);
DataDictWritter("obj.classid", (long)o->GetClassID(), mDb, parents); DataDictWritter("obj.classid", (long)o->GetClassID(), mDb, parents);
DataDictWritter("obj.type", o->GetClassNameA(), mDb, parents); DataDictWritter("obj.type", o->GetClassNameA() ? o->GetClassNameA() : "!!UNKNOW!!", mDb, parents);
} }
void DigParameterData(CKParameter* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) { void DigParameterData(CKParameter* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents) {
@ -694,7 +722,8 @@ namespace SSMaterializer {
static std::string str_2dcurve_entry; static std::string str_2dcurve_entry;
str_2dcurve = "["; str_2dcurve = "[";
for (int i = 0, cc = c->GetControlPointCount(); i < cc; ++i) { int cpcount = c->GetControlPointCount();
for (int i = 0; i < cpcount; ++i) {
if (i != 0) str_2dcurve += ','; // extra splitter if (i != 0) str_2dcurve += ','; // extra splitter
str_2dcurve += '{'; // object start str_2dcurve += '{'; // object start

View File

@ -28,7 +28,7 @@ namespace SSMaterializer {
void Proc_ArrayColumnRow(CKDataArray* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void Proc_ArrayColumnRow(CKDataArray* cache, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DigObjectData(CKObject* o, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DigObjectData(CKObject* o, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DigParameterData(CKParameter* pl, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DigParameterData(CKParameter* p, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DataDictWritter(const char* field, long data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DataDictWritter(const char* field, long data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DataDictWritter(const char* field, float data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DataDictWritter(const char* field, float data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);
void DataDictWritter(const char* field, const char* data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents); void DataDictWritter(const char* field, const char* data, Database::DocumentDatabase* mDb, DataStruct::EXPAND_CK_ID parents);