Hello All,
Given recent discussions and my needs for enum support, I experimented a bit
and found that postgresql enums works perfectly as text. Essentially they are
predefined values of text.
PFA a test program to demonstrate that. Here is the sql session and the
program run. The select was run after the program was run in another terminal.
----------------------
test=# create type enum1 as enum('enumval1','enumval2');
CREATE TYPE
test=# create table enumtable(name varchar(20), state enum1);
CREATE TABLE
test=# select * from enumtable;
name | state
-----------+----------
stringval | enumval1
(1 row)
----------------------
----------------------
shrid...@bheem /mnt1/shridhar/development/test/soci$ bjam &&
bin/gcc-4.4.2/release/enum
...found 31 targets...
...updating 2 targets...
gcc.compile.c++ bin/gcc-4.4.2/release/enum.o
gcc.link bin/gcc-4.4.2/release/enum
...updated 2 targets...
enum1:'enumval1' enum2:'enumval1'
Error:ERROR: invalid input value for enum enum1: "nosuchval"
----------------------
This was run on 64 bit archlinux, with postgresql 8.4.2
--
Shridhar
#include <iostream>
#include <string>
#include <soci.h>
#include <soci-postgresql.h>
#include <cassert>
#undef NDEBUG
int main()
{
using namespace soci;
try
{
std::string name="stringval",enum1="enumval1",enum2;
session sql(postgresql,"dbname=test");
sql << "insert into enumtable(name,state) values(:name,:enum1)"
,use(name),use(enum1);
sql << "select state from enumtable",into(enum2);
assert(enum1==enum2);
std::cout << "enum1:'" << enum1 << "' enum2:'" << enum2 << "'" << std::endl;
//got to fail
enum1 = "nosuchval";
sql << "insert into enumtable(name,state) values(:name,:enum1)"
,use(name),use(enum1);
}
catch(std::exception & e)
{
std::cerr << "Error:" << e.what() << std::endl;
}
return 0;
}
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users