The POCO C++ Libraries Blog

PocoData, Servlets and Vaporware

Filed under: News by alex at 04:39

‘Guilty as charged’ is the verdict. I owe an apology to the audience for selling vapourware. I got stuck with Data, RecordSet, ODBC connector & co, so the servlet engine got pushed on the back burner for the ump-th time. But I’m getting ready to give it a shot and push it out the door (just don’t hold me accountable for saying this 😉

Anyway, back to PocoData, what I was trying to achieve is to be able to do something like this:

Statement stmt = (session << "SELECT * FROM aTable", now);//note no 'into()' provided

for(RecordSet::Iterator it = stmt.recordSet().begin(); it != stmt.recordSet().end(); ++it)
int i1 = AnyCast<int>((*it)["fld1"]));
float f2 = AnyCast<float>((*it)["fld2"]));
Now, all this is nice and well, but I still must know the type I'm extracting, so not much is achieved. If I could do this:

int i = (*it)["fld"].toInt();

or this
int i = toInt((*it)["fld"]);

That would be something, right? Provided I'm not concerned with performance, of course.
On how to do the above, the jury is still out. And I'm blogging about it hoping to hear some comments and ideas (code is in SVN).

  1. I am currently thinking about adding a new class named “Flexo”, which basically will be Any on steroids. You will be able to store scalar values of all standard types in it, as well as convert to any other type, as long as it’s somehow feasible.
    Also part of it will be some kind of associative array functionality based on an internal hash table, so you will be basically able to do things like this:

    Flexo f;
    f = 100;
    f = “42”;
    int i = f.toInt();
    f[0] = “foo”;
    f[1] = “bar”;
    f[“abc”] = “def”;
    std::string s = f[0].asString();
    s = f[“abc”];
    s = f.toString(); // will serialize using JSON notation
    std::typeinfo info = f.type();

    Comment by guenter on December 7, 2006, 09:47

  2. Ah, great. I like it. And, just out of curiosity, where does name “Flexo” come from?

    Comment by alex on December 7, 2006, 13:41

  3. You know, there once was a TV show called Futurama. It had two robot characters in it: Bender and Flexo…

    Comment by guenter on December 7, 2006, 14:30

  4. Hm – now I’m not sure whether you are pulling my leg or working too much 😉

    Comment by alex on December 7, 2006, 17:17

  5. The rational explanation would be FLEXible Object 😉

    Comment by guenter on December 7, 2006, 18:05

  6. Is the name open for discussion? If so, then I vote for DynamicAny (recently proposed by Peter). I mean, with Futurama and all, Flexo does not sound like a Poco class ;-).

    Comment by alex on December 7, 2006, 18:50

  7. You want to be able to support queries like “select * from any_table” where the data types are unknown at run time. I think most libraries and tools convert every column to string. Then you have to make a decision what to do with data types like Oracle’s RAW, CLOBS and BLOBS.
    OTL for example has a function to covert number, dates and floats into string but the function will throw if you try to retrieve a blob which sucks because if you are creating a general purpose query tool you cannot know if a user may decide to do a “select * from table_with_some_blobs”


    Comment by Paschal on December 7, 2006, 21:58

  8. The original idea behind my request was, as Guenter well explained in his example, to do all the possible conversions between PocoData supported types (all PODs, std::string and Poco::Data::BLOB) that make sense. In the particular case you’re mentioning, Poco::Data::BLOB can easily be turned into std::string using char* BLOB::rawContent() member function.
    But nothing is infinite and the whole thing can be as general as possible, i.e. if you decide to convert an integer larger than 127 into char, to throw is better than to overflow.

    Comment by alex on December 8, 2006, 00:51

  9. I am waiting for servlets. That’s one thing that keeps me thinking seriously of using Java. I may not be able to help you with C++ code but I will give the library some real life tests and provide you with useful feedback.


    Comment by Paschal on December 8, 2006, 04:34

  10. I know you are, Paschal. My apologies above go to you and other folks I’ve kept in fog by promising and then not delivering as promised. Also, please be aware that it has nothing to do with Applied Informatics – this is entirely my own fault – I try to do more than physically possible.

    Comment by alex on December 8, 2006, 04:50

  11. Regarding the name: I actually thought about DynAny. It just sounds a bit too CORBA-esque for my taste…

    Comment by guenter on December 8, 2006, 17:34

  12. I’d be fine with DynAny as far as length is concerned. But, the pronounciation (“die nanny”) is horrible. So, I’m still for DynamicAny.

    Comment by alex on December 8, 2006, 18:29

RSS RSS feed for comments on this post. TrackBack URI

Leave a comment