Re: [Cppcms-users] cppdb::statement copy and assign
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2015-11-11 16:47:30
|
Actually you are mistaken. cppdb::statement, cppdb::session and cppdb::result keep the reference to underlying backed object representing them. See: http://cppcms.com/sql/cppdb/classcppdb_1_1statement.html#adc5ddc1e8df9248b74692990cffe40cf So copy is totally valid and you can use it this way without problems. Actually statement would also keep a track of the session and result of statement and session as well. So it is correct way to do things. Of course it is bad idea to start using copies of came cppdb::statement from two different locations simultaneously. So look for the problem in some other place. Artyom > Hi! > > I recently made a mistake by doing this: > > cppdb::statement create(){ > cppdb::session se("connect parameters"); > cppdb::statement st=se << "SELECT * FROM t"; > return st; > } > > void use(){ > cppdb::statement st=create(); > st.query(); > } > > Very weird errors happens to st.query(). > It took me quite some time to pin point the bug. After that, I re-read > the comments in cppdb/cppdb/frontend.h and I believe they confirm my > conclusion: > > The problem here, I believe, is that cppdb::statement object is already > destroyed before st.query() is executed. > > I am writing this note here in order to remind myself of avoiding such > practice. Hopefully no one else will make the same mistake as I did! > > Meanwhile, I suspect it will be better off > > (a) either to remove the cppdb::statement copy and assignment methods > from cppdb source altogether > (b) or to make cppdb::statement non-copyable > > I have a feeling that these two methods serve only as a trap. > Yes? No? > > Best Regards, > CN > > -- > http://www.fastmail.com - Access all of your messages and folders > wherever you are > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |