diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp index 692d80d..18328ce 100644 --- a/SuperScriptMaterializer/database.cpp +++ b/SuperScriptMaterializer/database.cpp @@ -41,36 +41,32 @@ namespace SSMaterializer { // open mDb int result; result = sqlite3_open(file, &mDb); - if (result != SQLITE_OK) goto fail; + if (result != SQLITE_OK) goto open_fail; // disable synchronous result = sqlite3_exec(mDb, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); if (result != SQLITE_OK) goto fail; - // do some custom Init - if (!Init()) goto fail; - - //start job - sqlite3_exec(mDb, "begin;", NULL, NULL, NULL); - return; fail: + sqlite3_close(mDb); + open_fail: mDb = NULL; } SSMaterializerDatabase::~SSMaterializerDatabase() { if (mDb == NULL) return; + int result; //free all cached stmts and commit job for (auto it = mStmtCache.begin(); it != mStmtCache.end(); it++) { - if (*it != NULL) - sqlite3_finalize(*it); + if (*it != NULL) { + 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 sqlite3_close(mDb); mDb = NULL; @@ -87,34 +83,58 @@ namespace SSMaterializer { return stmt; } - BOOL SSMaterializerDatabase::Init() { - return TRUE; - } - - BOOL SSMaterializerDatabase::Finalize() { - return TRUE; - } - #pragma endregion #pragma region sub-database constructor, deconstructor and help functions DocumentDatabase::DocumentDatabase(const char* file, CKParameterManager* 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() { - ; + 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) : 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() { - ; + 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) { @@ -149,9 +169,6 @@ namespace SSMaterializer { if (result != SQLITE_OK) { return FALSE; } BOOL DocumentDatabase::Init() { - // execute parent first - if (!SSMaterializerDatabase::Init()) return FALSE; - int result; //Init table @@ -185,9 +202,6 @@ if (result != SQLITE_OK) { return FALSE; } } BOOL DocumentDatabase::Finalize() { - // execute parent first - if (!SSMaterializerDatabase::Finalize()) return FALSE; - //create index for quick select in SuperScriptDecorator int result; @@ -211,9 +225,6 @@ if (result != SQLITE_OK) { return FALSE; } } BOOL EnvironmentDatabase::Init() { - // execute parent first - if (!SSMaterializerDatabase::Init()) return FALSE; - int result; //init table @@ -231,9 +242,6 @@ if (result != SQLITE_OK) { return FALSE; } } BOOL EnvironmentDatabase::Finalize() { - // execute parent first - if (!SSMaterializerDatabase::Finalize()) return FALSE; - return TRUE; } diff --git a/SuperScriptMaterializer/database.hpp b/SuperScriptMaterializer/database.hpp index 8edc670..131d92f 100644 --- a/SuperScriptMaterializer/database.hpp +++ b/SuperScriptMaterializer/database.hpp @@ -311,8 +311,6 @@ namespace SSMaterializer { protected: sqlite3_stmt* CreateStmt(const char* stmt); - virtual BOOL Init(); - virtual BOOL Finalize(); sqlite3* mDb; std::vector mStmtCache; @@ -350,8 +348,8 @@ namespace SSMaterializer { BOOL is_obj_duplicated(DataStruct::EXPAND_CK_ID parents); protected: - BOOL Init() override; - BOOL Finalize() override; + BOOL Init(); + BOOL Finalize(); std::set mUniqueAttr; std::set mUniqueObj; @@ -370,8 +368,8 @@ namespace SSMaterializer { void write_variable(DataStruct::dbenv_variable& data); protected: - BOOL Init() override; - BOOL Finalize() override; + BOOL Init(); + BOOL Finalize(); }; } diff --git a/SuperScriptMaterializer/doc_export.cpp b/SuperScriptMaterializer/doc_export.cpp index 7833bce..17167bd 100644 --- a/SuperScriptMaterializer/doc_export.cpp +++ b/SuperScriptMaterializer/doc_export.cpp @@ -504,6 +504,7 @@ namespace SSMaterializer { // write row data switch (coltype) { case CKARRAYTYPE_INT: + { for (int row = 0; row < rows; ++row) { mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.row = row; @@ -514,8 +515,10 @@ namespace SSMaterializer { mDb->write_array_cell(mDb->mDbHelper.array_cell); } - break; + } + break; case CKARRAYTYPE_FLOAT: + { for (int row = 0; row < rows; ++row) { mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.row = row; @@ -526,8 +529,10 @@ namespace SSMaterializer { mDb->write_array_cell(mDb->mDbHelper.array_cell); } - break; + } + break; case CKARRAYTYPE_STRING: + { for (int row = 0; row < rows; ++row) { mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.row = row; @@ -540,43 +545,66 @@ namespace SSMaterializer { mDb->write_array_cell(mDb->mDbHelper.array_cell); } - break; + } + break; 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: + { + // 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) { mDb->mDbHelper.array_cell.column = col; mDb->mDbHelper.array_cell.row = row; mDb->mDbHelper.array_cell.parent = parents; - CKParameter* p = (CKParameter*)cache->GetElementObject(row, col); - if (p == NULL) continue; // fail to get obj - int count = p->GetStringValue(NULL, FALSE); - mDb->mDbHelper.array_cell.showcase.resize(count); - p->GetStringValue((char*)mDb->mDbHelper.array_cell.showcase.data(), FALSE); - mDb->mDbHelper.array_cell.inner_param = p->GetID(); + // check get status + obj = cache->GetElementObject(row, col); + if (obj == NULL) { + // fail to get obj + mDb->mDbHelper.array_cell.showcase = "(null)"; + 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); - - // 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; 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.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) { @@ -694,7 +722,8 @@ namespace SSMaterializer { static std::string str_2dcurve_entry; 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 str_2dcurve += '{'; // object start diff --git a/SuperScriptMaterializer/doc_export.hpp b/SuperScriptMaterializer/doc_export.hpp index b60ff92..8964570 100644 --- a/SuperScriptMaterializer/doc_export.hpp +++ b/SuperScriptMaterializer/doc_export.hpp @@ -28,7 +28,7 @@ namespace SSMaterializer { 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 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, 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);