Skip to content

Commit

Permalink
Playing with setTextParam()
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaydionov committed Feb 12, 2013
1 parent 4c3cb62 commit 1469f84
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/backends/firebird/common.cpp
Expand Up @@ -10,7 +10,9 @@
#include <ibase.h> // FireBird
#include <cstddef>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <iostream>
#include <string>

namespace soci
Expand Down Expand Up @@ -82,6 +84,7 @@ void tmDecode(short type, void * src, std::tm * dst)
void setTextParam(char const * s, std::size_t size, char * buf_,
XSQLVAR * var)
{
std::cerr << "setTextParam: var->sqltype=" << var->sqltype << std::endl;
short sz = 0;
if (size < static_cast<std::size_t>(var->sqllen))
{
Expand All @@ -105,6 +108,39 @@ void setTextParam(char const * s, std::size_t size, char * buf_,
memset(buf_+sz, ' ', var->sqllen - sz);
}
}
else if ((var->sqltype & ~1) == SQL_INT64)
{
long long t;
std::stringstream input(s);
input >> t;
if (input.bad())
throw soci_error("Could not parse integer value.");
memcpy(buf_, &t, sizeof(t));
to_isc<long long>(buf_, var);
}
else if ((var->sqltype & ~1) == SQL_TIMESTAMP)
{
unsigned short year, month, day, hour, min, sec;
if (std::sscanf(s, "%hu-%hu-%huT%hu:%hu:%hu",
&year, &month, &day, &hour, &min, &sec) != 6)
{
if (std::sscanf(s, "%hu-%hu-%hu %hu:%hu:%hu",
&year, &month, &day, &hour, &min, &sec) != 6)
{
throw soci_error("Could not parse timestamp value.");
}
}
std::tm t;
memset(&t, 0, sizeof(t));
t.tm_year = year - 1900;
t.tm_mon = month - 1;
t.tm_mday = day;
t.tm_hour = hour;
t.tm_min = min;
t.tm_sec = sec;
memcpy(buf_, &t, sizeof(t));
tmEncode(var->sqltype, &t, buf_);
}
else
{
throw soci_error("Unexpected string type.");
Expand All @@ -113,6 +149,7 @@ void setTextParam(char const * s, std::size_t size, char * buf_,

std::string getTextParam(XSQLVAR const *var)
{
std::cerr << "getTextParam: var->sqltype=" << var->sqltype << std::endl;
short size;
std::size_t offset = 0;

Expand Down
4 changes: 4 additions & 0 deletions src/backends/firebird/standard-use-type.cpp
Expand Up @@ -77,6 +77,7 @@ void firebird_standard_use_type_backend::bind_by_name(

void firebird_standard_use_type_backend::pre_use(indicator const * ind)
{
indISCHolder_ = 0;
if (ind)
{
switch (*ind)
Expand All @@ -97,6 +98,9 @@ void firebird_standard_use_type_backend::exchangeData()
{
XSQLVAR *var = statement_.sqlda2p_->sqlvar+position_;

if (0 != indISCHolder_)
return;

switch (type_)
{
case x_char:
Expand Down
2 changes: 2 additions & 0 deletions src/backends/firebird/statement.cpp
Expand Up @@ -10,6 +10,7 @@
#include "error-firebird.h"
#include <cctype>
#include <sstream>
#include <iostream>

using namespace soci;
using namespace soci::details;
Expand Down Expand Up @@ -286,6 +287,7 @@ void firebird_statement_backend::rewriteQuery(
void firebird_statement_backend::prepare(std::string const & query,
statement_type /* eType */)
{
std::cerr << "prepare: query=" << query << std::endl;
// clear named parametes
names_.clear();

Expand Down

0 comments on commit 1469f84

Please sign in to comment.