some work in morm
- support for fetching rows from db - support for inserting/updating rows git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1081 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -32,8 +32,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include "dbconnector.h"
|
||||
#include "model.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
namespace morm
|
||||
@@ -45,6 +47,12 @@ DbConnector::DbConnector()
|
||||
expression_allocated = false;
|
||||
}
|
||||
|
||||
DbConnector::DbConnector(const DbConnector &)
|
||||
{
|
||||
db_expression = nullptr;
|
||||
expression_allocated = false;
|
||||
}
|
||||
|
||||
|
||||
DbConnector::~DbConnector()
|
||||
{
|
||||
@@ -100,13 +108,27 @@ bool DbConnector::query_insert(const PT::TextStream & stream)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
virtual void DbConnector::map_values_from_query(Model & model)
|
||||
size_t DbConnector::last_select_size()
|
||||
{
|
||||
model.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::set_current_row_at_beginning()
|
||||
{
|
||||
}
|
||||
|
||||
void DbConnector::advance_current_row()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//void DbConnector::map_values_from_query(Model & model)
|
||||
//{
|
||||
// model.clear();
|
||||
//}
|
||||
|
||||
|
||||
DbExpression * DbConnector::get_expression()
|
||||
{
|
||||
allocate_default_expression_if_needed();
|
||||
@@ -159,15 +181,12 @@ void DbConnector::generate_update_query(PT::TextStream & stream, Model & model)
|
||||
|
||||
stream << "update ";
|
||||
model.table_name(stream);
|
||||
stream << " set (";
|
||||
db_expression->set_work_mode(MORM_WORK_MODE_MODEL_FIELDS);
|
||||
stream << " set ";
|
||||
|
||||
db_expression->set_work_mode(MORM_WORK_MODE_MODEL_FIELDS_VALUES);
|
||||
db_expression->generate_from_model(stream, model);
|
||||
|
||||
stream << ") values (";
|
||||
db_expression->set_work_mode(MORM_WORK_MODE_MODEL_VALUES);
|
||||
db_expression->generate_from_model(stream, model);
|
||||
|
||||
stream << ") where ";
|
||||
stream << " where ";
|
||||
db_expression->set_work_mode(MORM_WORK_MODE_MODEL_FIELDS_VALUES);
|
||||
db_expression->set_output_type(MORM_OUTPUT_TYPE_DB_PRIMARY_KEY);
|
||||
db_expression->generate_from_model(stream, model);
|
||||
@@ -176,21 +195,17 @@ void DbConnector::generate_update_query(PT::TextStream & stream, Model & model)
|
||||
|
||||
|
||||
|
||||
void DbConnector::insert(PT::TextStream & stream, Model & model)
|
||||
bool DbConnector::insert(PT::TextStream & stream, Model & model)
|
||||
{
|
||||
generate_insert_query(stream, model);
|
||||
// do the real inserting
|
||||
// query(stream);
|
||||
// and get autogenerated columns
|
||||
return query_insert(stream);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::update(PT::TextStream & stream, Model & model)
|
||||
bool DbConnector::update(PT::TextStream & stream, Model & model)
|
||||
{
|
||||
generate_update_query(stream, model);
|
||||
// do the real updating
|
||||
// query(stream);
|
||||
// and get autogenerated columns
|
||||
return query_update(stream);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +229,235 @@ void DbConnector::allocate_default_expression_if_needed()
|
||||
}
|
||||
}
|
||||
|
||||
const char * DbConnector::get_field_string_value(const wchar_t * field_name)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DbConnector::clear_value(char & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned char & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(std::wstring & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(std::string & field_value)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(bool & field_value)
|
||||
{
|
||||
field_value = false;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(short & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned short & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(int & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned int & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(long long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(unsigned long long & field_value)
|
||||
{
|
||||
field_value = 0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(float & field_value)
|
||||
{
|
||||
field_value = 0.0f;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(double & field_value)
|
||||
{
|
||||
field_value = 0.0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(long double & field_value)
|
||||
{
|
||||
field_value = 0.0;
|
||||
}
|
||||
|
||||
void DbConnector::clear_value(PT::Date & field_value)
|
||||
{
|
||||
field_value.Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, char & field_value)
|
||||
{
|
||||
field_value = *value_str;
|
||||
value_str += 1;
|
||||
|
||||
if( *value_str != 0 )
|
||||
{
|
||||
// value has more than one charater, put some error?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, unsigned char & field_value)
|
||||
{
|
||||
field_value = *(const unsigned char*)value_str;
|
||||
value_str += 1;
|
||||
|
||||
if( *value_str != 0 )
|
||||
{
|
||||
// value has more than one charater, put some error?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, std::wstring & field_value)
|
||||
{
|
||||
// CHECKME
|
||||
// what about \0 in val_str?
|
||||
// it is escaped somehow?
|
||||
PT::UTF8ToWide(value_str, field_value);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, std::string & field_value)
|
||||
{
|
||||
field_value = value_str;
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, bool & field_value)
|
||||
{
|
||||
// IMPROVE ME
|
||||
// this 't' is locale dependent
|
||||
field_value = (value_str[0]=='t' || value_str[0]=='y' || value_str[0]=='1');
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, short & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = (short)PT::Toi(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, unsigned short & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = (unsigned short)PT::Toui(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, int & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = PT::Toi(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, unsigned int & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = PT::Toui(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, long & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = PT::Tol(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, unsigned long & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = PT::Toul(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, long long & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = PT::Toll(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, unsigned long long & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = PT::Toull(value_str, 10);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, float & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = strtof(value_str, 0);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, double & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = strtod(value_str, 0);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, long double & field_value)
|
||||
{
|
||||
// IMPROVE ME give some overflow checking
|
||||
field_value = strtold(value_str, 0);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, PT::Date & field_value)
|
||||
{
|
||||
// IMPROVE ME give some log if parsing failed
|
||||
bool res = field_value.Parse(value_str);
|
||||
}
|
||||
|
||||
|
||||
const char * DbConnector::query_last_sequence(const wchar_t * sequence_table_name)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user