zussel / matador

Take your appclication by the horns
http://zussel.github.io/matador
GNU General Public License v3.0
63 stars 22 forks source link

mysql8 Commands out of sync; you can't run this command now #116

Closed suisou closed 4 years ago

suisou commented 4 years ago

struct s_comconf { identifier id; std::string DEV_NAME; int SPEED; int FLOW_CTRL; int DATABITS; int STOPBITS; int PARITY;

template < class SERIALIZER >
void serialize(SERIALIZER& serializer) {
    serializer.serialize("id", id);
    serializer.serialize("DEV_NAME", DEV_NAME);
    serializer.serialize("SPEED", SPEED);
    serializer.serialize("FLOW_CTRL", FLOW_CTRL);
    serializer.serialize("DATABITS", DATABITS);
    serializer.serialize("STOPBITS", STOPBITS);
    serializer.serialize("PARITY", PARITY);
}

};

// prepare the persistence layer
persistence p(MYSQL_LINK);
p.attach<s_comconf>(COM_CONF_TABLENAME);
p.enable_log();
// create tables
p.create();

// create a database session
session s(p); 

// insert george
// returns an matador::object_ptr<person>
auto conf = s.insert(new s_comconf());
// flush changes
s.flush();

// modify george
conf.modify()->DEV_NAME = "/dev/ttyS1";
conf.modify()->SPEED = 115200;
conf.modify()->FLOW_CTRL = 0;
conf.modify()->DATABITS = 8;
conf.modify()->STOPBITS = 0;
conf.modify()->PARITY = 78;// 'N'
s.flush();

connection conn(MYSQL_LINK); query q(COM_CONF_TABLENAME);

_**auto res = q.select().execute(conn);**_

the error showed from last row.

suisou commented 4 years ago

I add " conn.reconnect(); " after "connection conn(MYSQL_LINK);" last row run passed!

zussel commented 4 years ago

That's an interresting constalation. I'll take a look into it.

zussel commented 4 years ago

After creating a connection, you have to explicitly call connect() to open the database connection. So, the call to reconnect() does the job too.

Btw: When working with a session you can call s.select<s_comconf>() to retrieve the objects. Returned ist an object of type object_view<s_comconf> which can be iterated in STL way. When starting your app with an available database schema you can call persistence::load() to load all objects into the object_store. (I plan provide a sync_schema() for persistence)

suisou commented 4 years ago

thanks,I use it as the demo code on http://zussel.github.io/matador/. Please modify it with the new version. OR , the fresh will be confused with it again.

zussel commented 4 years ago

Ok, thanks! I fixed the demo code.