From fad5eca831088dc9da29e592933fd1ba88f228ef Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Mon, 16 Jun 2014 21:56:27 +0000 Subject: [PATCH] Bug with loading data of variation parent if there is no such variation git-svn-id: https://phys12svn.jlab.org/repos/trunk/ccdb@2008 c5ed4466-e916-0410-8347-b3263e9c103d --- src/Library/Providers/SQLiteDataProvider.cc | 11 +- src/Tests/test_NoMySqlUserAPI.cc | 19 +- src/Tests/test_NoMysqlUserAPI.cc | 190 -------------------- 3 files changed, 18 insertions(+), 202 deletions(-) delete mode 100644 src/Tests/test_NoMysqlUserAPI.cc diff --git a/src/Library/Providers/SQLiteDataProvider.cc b/src/Library/Providers/SQLiteDataProvider.cc index 496036c5..d8a630c5 100644 --- a/src/Library/Providers/SQLiteDataProvider.cc +++ b/src/Library/Providers/SQLiteDataProvider.cc @@ -1193,18 +1193,21 @@ Assignment* ccdb::SQLiteDataProvider::GetAssignmentShort(int run, const string& break; } } while(result==SQLITE_ROW ); - - if(assignment == NULL) return NULL; // finalize the statement to release resources sqlite3_finalize(mStatement); //If We have not found data for this variation, getting data for parent variation - if(selectedRows==0 && variation->GetParentDbId()!=0) + if((assignment == NULL && selectedRows==0) && variation->GetParentDbId()!=0) { - delete table; return GetAssignmentShort(run, path, time, variation->GetParent()->GetName()); } + + if(assignment == NULL) + { + delete table; + return NULL; + } assignment->SetTypeTable(table); assignment->BeOwner(table); diff --git a/src/Tests/test_NoMySqlUserAPI.cc b/src/Tests/test_NoMySqlUserAPI.cc index 41a7d0fb..c2aa1569 100644 --- a/src/Tests/test_NoMySqlUserAPI.cc +++ b/src/Tests/test_NoMySqlUserAPI.cc @@ -69,14 +69,7 @@ TEST_CASE("CCDB/UserAPI/SQLite","tests") REQUIRE_NOTHROW(result = calib->GetCalib(tabledValues, "test/test_vars/test_table")); REQUIRE(result); REQUIRE(tabledValues.size()>0); - - //test of getting data as map - //---------------------------------------------------- - map mappedValues; - REQUIRE_NOTHROW(result = calib->GetCalib(mappedValues, "test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(mappedValues.size()>0); - + //test of getting data without / in the beginning //---------------------------------------------------- vector > vectorOfMapsdValues; @@ -168,6 +161,16 @@ TEST_CASE("CCDB/UserAPI/SQLite_CalibrationGenerator","Use universal generator to REQUIRE(tabledValues.size()==2); REQUIRE(tabledValues[0].size()==3); REQUIRE(tabledValues[0][0]=="10"); + + //No such calibration exist in test variation, but constants should fallback to default varitaion + res = PathUtils::ParseContext("variation=test"); + sqliteCalib = gen->MakeCalibration(TESTS_SQLITE_STRING, 100, res.Variation, res.ConstantsTime); + REQUIRE_NOTHROW(result = sqliteCalib->GetCalib(tabledValues, "/test/test_vars/test_table")); + REQUIRE(result); + REQUIRE(tabledValues.size()>0); + REQUIRE(tabledValues.size()==2); + REQUIRE(tabledValues[0].size()==3); + REQUIRE(tabledValues[0][0]=="2.2"); } SECTION("Get Assignment test", "Test all elements of getting data through get assignment") diff --git a/src/Tests/test_NoMysqlUserAPI.cc b/src/Tests/test_NoMysqlUserAPI.cc deleted file mode 100644 index 41a7d0fb..00000000 --- a/src/Tests/test_NoMysqlUserAPI.cc +++ /dev/null @@ -1,190 +0,0 @@ -#pragma warning(disable:4800) -#include "Tests/catch.hpp" -#include "Tests/tests.h" - -#include "CCDB/Console.h" -#include "CCDB/SQLiteCalibration.h" -#include "CCDB/Providers/SQLiteDataProvider.h" -#include "CCDB/Model/Directory.h" -#include "CCDB/Model/Variation.h" -#include "CCDB/Model/Assignment.h" -#include "CCDB/Helpers/StringUtils.h" -#include "CCDB/Helpers/WorkUtils.h" -#include "CCDB/Helpers/Stopwatch.h" -#include "CCDB/Helpers/PathUtils.h" -#include "CCDB/Log.h" -#include "CCDB/CalibrationGenerator.h" - -using namespace std; -using namespace ccdb; - -//Next functions is for data printing -void test_UserAPI_PrintData(const vector > & data); -void test_UserAPI_PrintData(const vector > & data); -void test_UserAPI_PrintData(const vector > & data); -void test_UserAPI_PrintData(const vector & data); -void test_UserAPI_PrintData(const map & data); - - -/** ********************************************************************* - * @brief Test of CCDB USER API work - * - * @return true if test passed - */ -TEST_CASE("CCDB/UserAPI/SQLite","tests") -{ - bool result; - - DataProvider *prov = new SQLiteDataProvider(); - if(!prov->Connect(TESTS_SQLITE_STRING)) return; - - //U S I N G U S E R A P I D I R E C T L Y - //---------------------------------------------------- - - SQLiteCalibration *calib = new SQLiteCalibration(100); - result = false; - - REQUIRE_NOTHROW(result = calib->Connect(TESTS_SQLITE_STRING)); - REQUIRE(result); - REQUIRE(calib->GetConnectionString() == TESTS_SQLITE_STRING); - - - - //get data as table of strings - //---------------------------------------------------- - vector > tabledValues; - REQUIRE_NOTHROW(result = calib->GetCalib(tabledValues, "/test/test_vars/test_table")); - REQUIRE(tabledValues.size()>0); - REQUIRE(tabledValues.size()==2); - REQUIRE(tabledValues[0].size()==3); - - //test of disconnect and reconnect function - //---------------------------------------------------- - REQUIRE_NOTHROW(calib->Disconnect()); - REQUIRE_NOTHROW(calib->Reconnect()); - - //test of getting data without / in the beginning - //---------------------------------------------------- - tabledValues.clear(); - REQUIRE_NOTHROW(result = calib->GetCalib(tabledValues, "test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(tabledValues.size()>0); - - //test of getting data as map - //---------------------------------------------------- - map mappedValues; - REQUIRE_NOTHROW(result = calib->GetCalib(mappedValues, "test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(mappedValues.size()>0); - - //test of getting data without / in the beginning - //---------------------------------------------------- - vector > vectorOfMapsdValues; - REQUIRE_NOTHROW(result = calib->GetCalib(vectorOfMapsdValues, "test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(vectorOfMapsdValues.size()>0); - - vectorOfMapsdValues.clear(); - REQUIRE_NOTHROW(result = calib->GetCalib(vectorOfMapsdValues, "test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(vectorOfMapsdValues.size()>0); - - //test of get all namepaths - //---------------------------------------------------- - vector paths; - REQUIRE_NOTHROW(calib->GetListOfNamepaths(paths)); - REQUIRE(paths.size()>0); -} - - -TEST_CASE("CCDB/UserAPI/SQLite_CalibrationGenerator","Use universal generator to get calibrations") -{ - bool result; - CalibrationGenerator* gen = new CalibrationGenerator(); - Calibration* sqliteCalib = gen->MakeCalibration(TESTS_SQLITE_STRING, 100, "default"); - REQUIRE(static_cast(sqliteCalib)!=NULL); - REQUIRE(sqliteCalib->IsConnected()); - vector > tabledValues; - REQUIRE_NOTHROW(result = sqliteCalib->GetCalib(tabledValues, "/test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(tabledValues.size()>0); - REQUIRE(tabledValues.size()==2); - REQUIRE(tabledValues[0].size()==3); - - //ask for vector - vector > tabledDoubleValues; - REQUIRE_NOTHROW(result = sqliteCalib->GetCalib(tabledDoubleValues, "/test/test_vars/test_table2::test")); - REQUIRE(result); - REQUIRE(tabledDoubleValues.size()>0); - REQUIRE(tabledDoubleValues.size()==1); - REQUIRE(tabledDoubleValues[0].size()==3); - REQUIRE(tabledDoubleValues[0][0]==10); - REQUIRE(tabledDoubleValues[0][1]==20); - REQUIRE(tabledDoubleValues[0][2]==30); - - vector lineOfIntValues; - REQUIRE_NOTHROW(result = sqliteCalib->GetCalib(lineOfIntValues, "/test/test_vars/test_table2:0:test:2012-09-30 23-48-42")); - REQUIRE(result); - REQUIRE(lineOfIntValues.size()==3); - REQUIRE(lineOfIntValues[0]==10); - REQUIRE(lineOfIntValues[1]==20); - REQUIRE(lineOfIntValues[2]==30); - - //Get Type table through the Provider() - ConstantsTypeTable* table = sqliteCalib->GetProvider()->GetConstantsTypeTable("/test/test_vars/test_table2", true); - REQUIRE(table->GetColumns()[0]->GetType() == ConstantsTypeColumn::cIntColumn); - - - - //a->GetVa - - - - Calibration* sqliteCalib2 = gen->MakeCalibration(TESTS_SQLITE_STRING, 100, "default"); - REQUIRE(sqliteCalib == sqliteCalib2); - - REQUIRE(CalibrationGenerator::CheckOpenable(TESTS_SQLITE_STRING)); - REQUIRE_FALSE(CalibrationGenerator::CheckOpenable("abra_kadabra://protocol")); - - - //=== Default time === - SECTION("Default Time SQLite", "Test that test vars are opened with default date") - { - ContextParseResult res = PathUtils::ParseContext("variation=default calibtime=2012-08"); - Calibration* sqliteCalib = gen->MakeCalibration(TESTS_SQLITE_STRING, 100, res.Variation, res.ConstantsTime); - REQUIRE_NOTHROW(result = sqliteCalib->GetCalib(tabledValues, "/test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(tabledValues.size()>0); - REQUIRE(tabledValues.size()==2); - REQUIRE(tabledValues[0].size()==3); - REQUIRE(tabledValues[0][0]=="1.11"); - - //No such calibration exist in mc variation, but constants should fallback to default varitaion - res = PathUtils::ParseContext("variation=subtest calibtime=2012-11"); - sqliteCalib = gen->MakeCalibration(TESTS_SQLITE_STRING, 100, res.Variation, res.ConstantsTime); - REQUIRE_NOTHROW(result = sqliteCalib->GetCalib(tabledValues, "/test/test_vars/test_table")); - REQUIRE(result); - REQUIRE(tabledValues.size()>0); - REQUIRE(tabledValues.size()==2); - REQUIRE(tabledValues[0].size()==3); - REQUIRE(tabledValues[0][0]=="10"); - } - - SECTION("Get Assignment test", "Test all elements of getting data through get assignment") - { - Assignment *a; - REQUIRE_NOTHROW(a = sqliteCalib->GetAssignment("/test/test_vars/test_table2:0:test")); - REQUIRE(result); - REQUIRE(a->GetValueType(0) == ConstantsTypeColumn::cIntColumn); - REQUIRE(a->GetValueType("c3") == ConstantsTypeColumn::cIntColumn); - REQUIRE(a->GetValue(1) == "20"); - REQUIRE(a->GetValue(0, 1) == "20"); - REQUIRE(a->GetValue("c1") == "10"); - REQUIRE(a->GetValue(0, "c3") == "30"); - REQUIRE(a->GetValueInt(1) == 20); - REQUIRE(a->GetValueInt(0, 1) == 20); - REQUIRE(a->GetValueInt("c1") == 10); - REQUIRE(a->GetValueInt(0, "c3") == 30); - REQUIRE(a->GetValueDouble(2) > 29); - } -}