Archived

This forum has been archived. Please start a new discussion on GitHub.

problems with Freeze

I created the following database witch freeze:
>slice2freeze --dict IntStringMap,int,string IntStringMap
Then I wrote the following "Server.cpp"-file:
#include <Freeze/Freeze.h>
#include <Ice/Application.h>
#include <IntStringMap.h>
//#include <StringTextfileMap.h>
//#include <StringImagefileMap.h>
//#include <StringVideofileMap.h>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
//using namespace dataStreamTransfer;

int main(int argc,char* argv[]) {
//***********************************************************
Ice::CommunicatorPtr communicator =
Ice::initialize(argc,argv);

Freeze::ConnectionPtr connection =
Freeze::createConnection(communicator, "db");

IntStringMap mapString(connection, "string");
//***********************************************************

mapString.clear();

for (int count = 1; count <= 10; count++) {
time_t t = time(NULL);
char* timeString = ctime(&t);
string time = timeString;

time.resize(time.size()-1);

stringstream ss;
ss << count;
string text = "Dies ist das " + ss.str() + "."
+ " Beispiel.Und hier geht es weiter.";
mapString.insert(make_pair(count,text));

}


IntStringMap::iterator p;
for (p = mapString.begin(); p != mapString.end(); ++p) {
cout << p->first << " \t " << p->second << endl;
}

//***********************************************************
connection->close();
communicator->destroy();
//***********************************************************
return 0;
}
The I compiled it with:
>c++ -I. -I/usr/include -c Server.cpp IntStringMap.cpp
>c++ -o db-Server Server.o IntStringMap.o -L/usr/lib -lFreeze
And there were not compiler-errors. But if I try to run "db-Server":
>./db-Server
I get the error message:
terminate called after throwing an instance of 'Freeze::DatabaseException'
what(): MapDb.cpp:470: Freeze::DatabaseException:
string's key type is string, not int
Aborted

What does this mean?
What is my error?
How can I solve it?

Comments

  • Could you post the corresponding Slice definitions? Are you sure that the map indeed has a int as the key, not a string?

    Cheers,

    Michi.
  • Slice Definitions

    If I use the slice2freeze command und define a Key and Value default Slicetyp, so I thought, that I don't need a slice definition file.
  • benoit
    benoit Rennes, France
    It sounds like your db directory contains an old map which had a string key. Your test case worked fine for me:
    macbookpro$ ./db-Server 
    1        Dies ist das 1. Beispiel.Und hier geht es weiter.
    2        Dies ist das 2. Beispiel.Und hier geht es weiter.
    3        Dies ist das 3. Beispiel.Und hier geht es weiter.
    4        Dies ist das 4. Beispiel.Und hier geht es weiter.
    5        Dies ist das 5. Beispiel.Und hier geht es weiter.
    6        Dies ist das 6. Beispiel.Und hier geht es weiter.
    7        Dies ist das 7. Beispiel.Und hier geht es weiter.
    8        Dies ist das 8. Beispiel.Und hier geht es weiter.
    9        Dies ist das 9. Beispiel.Und hier geht es weiter.
    10       Dies ist das 10. Beispiel.Und hier geht es weiter.
    

    Did you try with an empty db directory?

    Cheers,
    Benoit.
  • empty db

    No. The db-Directory is not empty. I erase the directory and try it again.
  • It works now

    Thank you.
    Because my db-Directory wasn't empty, I got the error messages.
    I erased the content of the db-Directory and tried to run "db-Server" again.
    Now it works:)

    Thank you very much