147 lines
3.4 KiB
C++
147 lines
3.4 KiB
C++
/*
|
|
* This file is a part of morm
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2019, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfile_morm_modeldata
|
|
#define headerfile_morm_modeldata
|
|
|
|
#include "queryresult.h"
|
|
|
|
|
|
namespace morm
|
|
{
|
|
|
|
class ModelData
|
|
{
|
|
public:
|
|
|
|
ModelData()
|
|
{
|
|
morm_current_max_column = 1;
|
|
current_column = 1;
|
|
query_result = nullptr;
|
|
}
|
|
|
|
virtual ~ModelData()
|
|
{
|
|
}
|
|
|
|
bool has_autogenerated_select;
|
|
|
|
QueryResult * query_result;
|
|
// int table_index;
|
|
|
|
|
|
// can be moved to another struct?
|
|
// let ModelData be only for user stuff
|
|
PT::TextStream morm_finder_join_tables;
|
|
std::list<std::string> morm_foreign_keys;
|
|
int morm_current_max_column;
|
|
std::map<std::string, int> morm_table_join_map;
|
|
|
|
int current_column;
|
|
//std::vector<int> table_index;
|
|
|
|
|
|
|
|
virtual void prepare_to_new_select()
|
|
{
|
|
has_autogenerated_select = false;
|
|
query_result = nullptr;
|
|
|
|
// table_index = 1;
|
|
|
|
morm_current_max_column = 1;
|
|
morm_finder_join_tables.clear();
|
|
morm_table_join_map.clear();
|
|
morm_foreign_keys.clear();
|
|
}
|
|
|
|
|
|
virtual int add_join_table(const PT::TextStream & table_name)
|
|
{
|
|
std::string table_name_str;
|
|
table_name.to_string(table_name_str);
|
|
|
|
return add_join_table(table_name_str);
|
|
}
|
|
|
|
virtual int add_join_table(const std::string & table_name)
|
|
{
|
|
auto res = morm_table_join_map.insert(std::make_pair(table_name, 1));
|
|
|
|
if( !res.second )
|
|
{
|
|
res.first->second += 1;
|
|
}
|
|
|
|
return res.first->second;
|
|
}
|
|
|
|
// virtual int find_join_table_index(const std::string & table_name)
|
|
// {
|
|
// auto iter = morm_table_join_map.find(table_name);
|
|
//
|
|
// if( iter != morm_table_join_map.end() )
|
|
// {
|
|
// return iter->second;
|
|
// }
|
|
//
|
|
// return 0;
|
|
// }
|
|
|
|
// virtual int get_table_index(int column)
|
|
// {
|
|
// if( column < (int)table_index.size() )
|
|
// return table_index[column];
|
|
//
|
|
// return 0;
|
|
// }
|
|
|
|
|
|
/*
|
|
* may to add:
|
|
* std::set<std::wstring> skip_columns;
|
|
* and Finder can use this
|
|
* also update and insert from Model
|
|
* (but what about the same name of columns through the whole objects-tree?
|
|
* may we can save the name of the table too?)
|
|
*
|
|
*
|
|
*/
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|