Commit 0433b146 authored by msobczak's avatar msobczak

Added handling of colon-casts.

parent 79dc5ab1
......@@ -75,7 +75,18 @@ void postgresql_statement_backend::prepare(std::string const & query,
}
else if (*it == ':')
{
state = in_name;
// Check whether this is a cast operator (e.g. 23::float)
// and treat it as a special case, not as a named binding
const std::string::const_iterator next_it = it + 1;
if ((next_it != end) && (*next_it == ':'))
{
query_ += "::";
++it;
}
else
{
state = in_name;
}
}
else // regular character, stay in the same state
{
......@@ -107,6 +118,20 @@ void postgresql_statement_backend::prepare(std::string const & query,
query_ += ss.str();
query_ += *it;
state = normal;
// Check whether the named parameter is immediatelly
// followed by a cast operator (e.g. :name::float)
// and handle the additional colon immediately to avoid
// its misinterpretation later on.
if (*it == ':')
{
const std::string::const_iterator next_it = it + 1;
if ((next_it != end) && (*next_it == ':'))
{
query_ += ':';
++it;
}
}
}
break;
}
......
......@@ -394,6 +394,21 @@ void test8()
std::cout << "test 8 passed" << std::endl;
}
// test for double-colon cast in SQL expressions
void test9()
{
{
session sql(backEnd, connectString);
int a = 123;
int b = 0;
sql << "select :a::integer", use(a), into(b);
assert(b == a);
}
std::cout << "test 9 passed" << std::endl;
}
// DDL Creation objects for common tests
struct table_creator_one : public table_creator_base
{
......@@ -505,6 +520,7 @@ int main(int argc, char** argv)
test7();
test8();
test9();
std::cout << "\nOK, all tests passed.\n\n";
return EXIT_SUCCESS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment