cppcms-users Mailing List for CppCMS C++ Web Framework (Page 25)
Brought to you by:
artyom-beilis
You can subscribe to this list here.
2009 |
Jan
|
Feb
(22) |
Mar
|
Apr
(3) |
May
|
Jun
(4) |
Jul
|
Aug
|
Sep
|
Oct
(15) |
Nov
(16) |
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(4) |
Feb
|
Mar
(8) |
Apr
(8) |
May
(8) |
Jun
(36) |
Jul
(63) |
Aug
(126) |
Sep
(47) |
Oct
(66) |
Nov
(46) |
Dec
(42) |
2011 |
Jan
(87) |
Feb
(24) |
Mar
(54) |
Apr
(21) |
May
(22) |
Jun
(18) |
Jul
(22) |
Aug
(101) |
Sep
(57) |
Oct
(33) |
Nov
(34) |
Dec
(66) |
2012 |
Jan
(64) |
Feb
(76) |
Mar
(73) |
Apr
(105) |
May
(93) |
Jun
(83) |
Jul
(84) |
Aug
(88) |
Sep
(57) |
Oct
(59) |
Nov
(35) |
Dec
(49) |
2013 |
Jan
(67) |
Feb
(17) |
Mar
(49) |
Apr
(64) |
May
(87) |
Jun
(64) |
Jul
(93) |
Aug
(23) |
Sep
(15) |
Oct
(16) |
Nov
(62) |
Dec
(73) |
2014 |
Jan
(5) |
Feb
(23) |
Mar
(21) |
Apr
(11) |
May
(1) |
Jun
(19) |
Jul
(27) |
Aug
(16) |
Sep
(5) |
Oct
(37) |
Nov
(12) |
Dec
(9) |
2015 |
Jan
(7) |
Feb
(7) |
Mar
(44) |
Apr
(28) |
May
(5) |
Jun
(12) |
Jul
(8) |
Aug
|
Sep
(39) |
Oct
(34) |
Nov
(30) |
Dec
(34) |
2016 |
Jan
(66) |
Feb
(23) |
Mar
(33) |
Apr
(15) |
May
(11) |
Jun
(15) |
Jul
(26) |
Aug
(4) |
Sep
(1) |
Oct
(30) |
Nov
(10) |
Dec
|
2017 |
Jan
(52) |
Feb
(9) |
Mar
(24) |
Apr
(16) |
May
(9) |
Jun
(12) |
Jul
(33) |
Aug
(8) |
Sep
|
Oct
(1) |
Nov
(2) |
Dec
(6) |
2018 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
(14) |
Jun
(1) |
Jul
(9) |
Aug
(1) |
Sep
(13) |
Oct
(8) |
Nov
(2) |
Dec
(2) |
2019 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2020 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(9) |
Jul
(6) |
Aug
(25) |
Sep
(10) |
Oct
(10) |
Nov
(6) |
Dec
|
2021 |
Jan
|
Feb
|
Mar
(7) |
Apr
(1) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
(9) |
Oct
(1) |
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: kpeo <sla...@ya...> - 2015-11-23 10:47:13
|
Hi Artyom, I think, Javascript (Node.js and Meteor using it) - one of the most important web-technologies novadays in addition to already added imlementations. Thank you! Regards, kpeo 16.11.2015, 09:13, "Artyom Beilis" <art...@ya...>: > I'm working on implementation of session sharing between CppCMS and 3rd part web technologies. So it would be easier to migrate from current platform by implementing most performance critical parts in CppCMS > > (I'm trying to clear most critical tasks for CppCMS 1.2 so it can be released). > > In general it works this way: > > Some of CppCMS session API was exposed as pure C API to simplify module writing: > > http://sourceforge.net/p/cppcms/code/HEAD/tree/framework/trunk/cppcms/capi/session.h > > Modules were implemented for 3rd part technologies that allow to load modify and save CppCMS session. > ( http://sourceforge.net/p/cppcms/code/HEAD/tree/framework/trunk/contrib/integration/session/ ) > Currently I had written support for PHP, Java, Python (+django) and Asp.Net on its way. > > For example PHP code: > > include_once('cppcms.php'); > > $pool=CppCMS_SessionPool::from_config('cppcms-config.js'); > $session=$pool->session(); > $session->load(); > $x=0; > if($session->is_set('x')) { > $x=$session['x']; > } > > $x=intval($x)+1; > $session['x']=$x; > $session->save(); > > echo "x=$x\n"; > > Now what are most important web-technologies you think need to be there out of the box? > I'm thinking of Ruby on Rails but I have no experience with Ruby at all. > > Artyom Beilis > , > > ------------------------------------------------------------------------------ > Presto, an open source distributed SQL query engine for big data, initially > developed by Facebook, enables you to easily query your data on Hadoop in a > more interactive manner. Teradata is also now providing full enterprise > support for Presto. Download a free open source copy now. > http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140 > , > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users |
From: kpeo <sla...@ya...> - 2015-11-23 10:29:45
|
Hi! We can use cache only if context exists. But in application constructor - context is not exists yet. So what we should to do, if we caching database requests and we need to load some data in application constructor? (well, cache designed for responses mostly, but it can be used internally as well - instead of external solutions). So, here we have several ways: 1. Load data on the first web-request, that assign context. Here we need some central point for all requests, where we trigger some bool variable on the first request and never load data again (one "if" costs approximately nothing for modern CPU). We have virtual void main(std::string url) in application - but it "hooked" control for all requests and don't dispatch them to attached subapps. We can call some central function in each attached subapp, to load the data for the first time - but this looks ugly by future design. 2. Disable cache in constructor, load the data, enable cache. Better then previous, but we have no function to disable cache internally. so we can: - verify has_cache() or internal variable in each call to cache. ugly by design. - return the own dummy cache realisation class, instead of cppcms cache. we can't - cache_interface is boost::nocopyable. - wrap the cppcms cache into own functions, classes, templates to use cppcms or dummy methods - possible solution. 3. Don't caching database requests at all. Most databases have own caching mechanisms, but we better know the logic of our application and also can use own small storage solutions (well, may be they should use own cache too). 4. Let the users disable/enable cache not by configuration only, but dynamically or return "false" in cache methods if context is not assigned yet - not raise the exception. I can prepare the patch for that. But is it correct by cppcms design? And may be there are some other solutions of this problem? Thanks! Regards, kpeo |
From: Artyom B. <art...@ya...> - 2015-11-16 13:24:44
|
Hello all, I published a post about latest developments: http://blog.cppcms.com/post/117 Artyom |
From: Artyom B. <art...@ya...> - 2015-11-16 06:12:35
|
I'm working on implementation of session sharing between CppCMS and 3rd part web technologies. So it would be easier to migrate from current platform by implementing most performance critical parts in CppCMS (I'm trying to clear most critical tasks for CppCMS 1.2 so it can be released). In general it works this way: Some of CppCMS session API was exposed as pure C API to simplify module writing: http://sourceforge.net/p/cppcms/code/HEAD/tree/framework/trunk/cppcms/capi/session.h Modules were implemented for 3rd part technologies that allow to load modify and save CppCMS session.( http://sourceforge.net/p/cppcms/code/HEAD/tree/framework/trunk/contrib/integration/session/ )Currently I had written support for PHP, Java, Python (+django) and Asp.Net on its way. For example PHP code: include_once('cppcms.php'); $pool=CppCMS_SessionPool::from_config('cppcms-config.js');$session=$pool->session();$session->load();$x=0;if($session->is_set('x')) { $x=$session['x'];} $x=intval($x)+1;$session['x']=$x;$session->save(); echo "x=$x\n"; Now what are most important web-technologies you think need to be there out of the box?I'm thinking of Ruby on Rails but I have no experience with Ruby at all. Artyom Beilis |
From: Paolo B. <pao...@gm...> - 2015-11-13 09:56:35
|
Check out "RAII," (google for it) it is an important idiom in C++ In general, in C++ you can think you have a eager garbage collector. If you did your code well, and it is easy if you know the RAII idiom, all the resources are released when the variable goes out of scope. On Fri, Nov 13, 2015 at 9:42 AM, mawan sugiyanto <ma...@gm...> wrote: > Thankyou Marcel > > I was curious on looping statement increasing the memory. But, with you > explanation, it is clearly now. > Thanks for enlightenment. > > > Regards. > > > > On Fri, Nov 13, 2015 at 3:03 PM, Marcel Hellwig <ke...@co...> wrote: >> >> On 13.11.2015 04:18, mawan sugiyanto wrote: >> > void users::loadimage(std::string sid){ >> > int width, height; >> stack, stack >> > Image image("../profile_images/default.png"); >> stack >> > Geometry gtx(200,200); >> stack >> > Blob b; >> stack >> >> Everything is allocated on the stack, as long as you don't allocate it >> via new (or {c,a}malloc) >> > is image variable allocated on stack or in new memory? >> it is called heap, not new memory. >> > and i can not delete image variable like unset variable? >> All your variables will be deleted, when the programm flow "reaches" >> that last } . >> Your only way to force to unset a variable is to begin a new scope >> >> > void foo() { >> > int f; >> > { >> > int g = 3; >> > f = g; >> > } >> > return f; >> > } >> >> g is only valid in the scope it was declared in. You cannot reach it, >> outside of the scope. >> >> Greetings >> >> >> >> ------------------------------------------------------------------------------ >> >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: mawan s. <ma...@gm...> - 2015-11-13 08:43:04
|
Thankyou Marcel I was curious on looping statement increasing the memory. But, with you explanation, it is clearly now. Thanks for enlightenment. Regards. On Fri, Nov 13, 2015 at 3:03 PM, Marcel Hellwig <ke...@co...> wrote: > On 13.11.2015 04:18, mawan sugiyanto wrote: > > void users::loadimage(std::string sid){ > > int width, height; > stack, stack > > Image image("../profile_images/default.png"); > stack > > Geometry gtx(200,200); > stack > > Blob b; > stack > > Everything is allocated on the stack, as long as you don't allocate it > via new (or {c,a}malloc) > > is image variable allocated on stack or in new memory? > it is called heap, not new memory. > > and i can not delete image variable like unset variable? > All your variables will be deleted, when the programm flow "reaches" > that last } . > Your only way to force to unset a variable is to begin a new scope > > > void foo() { > > int f; > > { > > int g = 3; > > f = g; > > } > > return f; > > } > > g is only valid in the scope it was declared in. You cannot reach it, > outside of the scope. > > Greetings > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Marcel H. <ke...@co...> - 2015-11-13 08:03:55
|
On 13.11.2015 04:18, mawan sugiyanto wrote: > void users::loadimage(std::string sid){ > int width, height; stack, stack > Image image("../profile_images/default.png"); stack > Geometry gtx(200,200); stack > Blob b; stack Everything is allocated on the stack, as long as you don't allocate it via new (or {c,a}malloc) > is image variable allocated on stack or in new memory? it is called heap, not new memory. > and i can not delete image variable like unset variable? All your variables will be deleted, when the programm flow "reaches" that last } . Your only way to force to unset a variable is to begin a new scope > void foo() { > int f; > { > int g = 3; > f = g; > } > return f; > } g is only valid in the scope it was declared in. You cannot reach it, outside of the scope. Greetings |
From: mawan s. <ma...@gm...> - 2015-11-13 03:19:45
|
Thankyou Marcel sorry for ask. for example i have a function void users::loadimage(std::string sid){ int width, height; Image image("../profile_images/default.png"); Geometry gtx(200,200); try { image = Image("../profile_images/profile_" + sid + ".jpg"); }catch( std::exception &ex){ BOOSTER_INFO("xone") << "file to load user profile image "; } Blob b; width = image.size().width(); height = image.size().height(); //crop image if (width < height){ image.resize("200x"); }else{ image.resize("x200"); } image.crop(gtx); image.write(&b,"png"); } is image variable allocated on stack or in new memory? and i can not delete image variable like unset variable? On Fri, Nov 13, 2015 at 12:09 AM, Marcel Hellwig <ke...@co...> wrote: > Hi Mawan, > > On 12.11.2015 13:42, mawan sugiyanto wrote: > > is there any garbage collection? > > you are the garbage collector! You on your own. > This is C++, not Java or C#. When you don't need an object, delete it, > or even better, use scopes for your advantage. > > The keywords (for you to google) are "reference vs pointer", "raw > pointer vs smart pointer" and "C++ tutorial" > > Greetings > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: mawan s. <ma...@gm...> - 2015-11-13 00:22:43
|
thankyou , i will try it. On Thu, Nov 12, 2015 at 7:59 PM, Paolo Bolzoni < pao...@gm...> wrote: > Try to execute you application via valgrind, it detects most of the leaks. > > On Thu, Nov 12, 2015 at 1:42 PM, mawan sugiyanto <ma...@gm...> > wrote: > > I monitor memory usage of cppcms application. it is always increase > during > > the time process. > > > > is there any method to decrease memory usage? > > > > is there any garbage collection? > > > > > > Thanks > > > > > ------------------------------------------------------------------------------ > > > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Marcel H. <ke...@co...> - 2015-11-12 17:09:30
|
Hi Mawan, On 12.11.2015 13:42, mawan sugiyanto wrote: > is there any garbage collection? you are the garbage collector! You on your own. This is C++, not Java or C#. When you don't need an object, delete it, or even better, use scopes for your advantage. The keywords (for you to google) are "reference vs pointer", "raw pointer vs smart pointer" and "C++ tutorial" Greetings |
From: Paolo B. <pao...@gm...> - 2015-11-12 12:59:34
|
Try to execute you application via valgrind, it detects most of the leaks. On Thu, Nov 12, 2015 at 1:42 PM, mawan sugiyanto <ma...@gm...> wrote: > I monitor memory usage of cppcms application. it is always increase during > the time process. > > is there any method to decrease memory usage? > > is there any garbage collection? > > > Thanks > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: mawan s. <ma...@gm...> - 2015-11-12 12:43:10
|
I monitor memory usage of cppcms application. it is always increase during the time process. is there any method to decrease memory usage? is there any garbage collection? Thanks |
From: CN <cn...@fa...> - 2015-11-12 11:44:56
|
Laugh out loud! Thank you so much for your enlightenment! cppdb is rock sound. Best Regards, CN On Thu, Nov 12, 2015, at 06:49 PM, Artyom Beilis wrote: > See when you bind a string value it should remain valid until exec is > called. > > http://cppcms.com/sql/cppdb/classcppdb_1_1statement.html#a7b96bac916e748aa2a5cff49d3f615c8 > > Because cppdb does not copy strings to prevent needless data copy so > what happens that set_values and where_values are get destroyed when > you leave create function and their references are not valid. > > > Artyom > > ----- Original Message ----- > > > From: CN <cn...@fa...> > > To: cpp...@li... > > Cc: > > Sent: Thursday, November 12, 2015 11:53 AM > > Subject: Re: [Cppcms-users] cppdb::statement copy and assign > > > > Because the SQL is dynamically generated, I called > > cppdb::session::create_prepared_uncached_statement() instead of > > cppdb::session::create_statement(). > > > > The old version that gave me trouble follows: > > > > void db_conn_init(cppdb::session &db_session) > > { > > db_session << "SET NAMES 'UTF8'" << > > cppdb::exec; > > db_session << "SET TIME ZONE 'UTC'" << > > cppdb::exec; > > } > > > > cppdb::statement create(cppdb::session &se,std::string const &table) > > { > > cppcms::json::array keys,values; > > //Feed elements to keys and values here. > > std::vector<std::string> set_values; > > std::string > > column_list=utils::make_column_list(values,set_values); > > std::vector<std::string> where_values; > > std::string sql="UPDATE "+table+" SET > > "+column_list+utils::make_where(keys,where_values); > > //"sql" now becomes "UPDATE t SET c2=? WHERE c1=? AND > > c2=?" > > cppdb::statement st=se.create_prepared_uncached_statement(sql); > > size_t set_values_size=set_values.size(); > > for(size_t i=0;i < set_values_size;++i){ > > if(set_values[i].empty()) > > st.bind_null(i+1); > > else > > st.bind(i+1,set_values[i]); > > } > > for(size_t i=0,n=where_values.size();i < n;++i){ > > if(where_values[i].empty()) > > st.bind_null(set_values_size+i+1); > > else > > st.bind(set_values_size+i+1,where_values[i]); > > } > > return st; > > } > > > > Please note that > > cppdb::statement create(cppdb::session &se,std::string const &table) > > is a function. It is not a member function of a class. > > > > void my_class::use() > > { > > cppdb::session > > > > se("postgresql:@pool_size=5;dbname=db2;user=user2;password=xxx",db_conn_init); > > std::string table="t"; > > cppdb::statement st=create(se,"t"); > > cppdb::transaction tx(se); > > st.exec(); //Weird error occurs here. > > //Do more SQL here like this: > > //se << "INSERT INTO ..."; > > tx.commit(); > > } > > > > I do not have trouble with this new version: > > > > void my_class::use() > > { > > cppdb::session > > > > se("postgresql:@pool_size=5;dbname=db2;user=user2;password=xxx",db_conn_init); > > std::string table="t"; > > cppcms::json::array keys,values; > > //Feed elements to keys and values here. > > std::vector<std::string> set_values; > > std::string > > column_list=utils::make_column_list(values,set_values); > > std::vector<std::string> where_values; > > std::string sql="UPDATE "+table+" SET > > "+column_list+utils::make_where(keys,where_values); > > //"sql" now becomes "UPDATE t SET c2=? WHERE c1=? AND > > c2=?" > > cppdb::statement st=se.create_prepared_uncached_statement(sql); > > size_t set_values_size=set_values.size(); > > for(size_t i=0;i < set_values_size;++i){ > > if(set_values[i].empty()) > > st.bind_null(i+1); > > else > > st.bind(i+1,set_values[i]); > > } > > for(size_t i=0,n=where_values.size();i < n;++i){ > > if(where_values[i].empty()) > > st.bind_null(set_values_size+i+1); > > else > > st.bind(set_values_size+i+1,where_values[i]); > > } > > > > cppdb::transaction tx(se); > > st.exec(); > > //Do more SQL here like this: > > //se << "INSERT INTO ..."; > > tx.commit(); > > } > > > > Best Regards, > > CN > > > > On Thu, Nov 12, 2015, at 04:22 PM, CN wrote: > >> Thank you for the reply! > >> > >> Having received your message, I went back and study frontend.* and > >> backend.* of cppdb source code trying to understand more about it. > >> According to my findings so far, instances of cppdb::statement in > >> backend indeed are reference counted, meaning to me that these objects > >> will not be destroyed as long as they are still referenced. > >> > >> But I can only go that deep into cppdb source. Because my original > >> troublesome code actually uses uncached statement but I do not fully > >> understand cppdb's statement cache mechanism, I begin to suspect this > >> part of cppdb. > >> > >> I know this is not professional attitude, but the simplified version of > >> my troublesome code follows: > >> > >> cppdb::statement create(cppdb::session &se) > >> { > >> cppdb::statement st=se.create_prepared_uncached_statement( > >> "UPDATE t SET c2=? WHERE c1=? AND c2=?") > >> << 'xx' << 2; > >> return st; > >> } > >> > >> void use() > >> { > >> cppdb::session se("connection params"); > >> cppdb::statement st=create(se); > >> cppdb::transaction tx(se); > >> st.exec(); //Weird error occurs here. > >> //Do more SQL here like this: > >> //se << "INSERT INTO ..."; > >> tx.commit(); > >> } > >> > >> Note that the data type of t.c2 is INTEGER. > >> > >> And the PostgreSQL error log follows: > >> > >> 2015-10-31 14:20:42 CST ERROR: invalid input syntax for integer: > >> "cppdb_psqlstmt_17" > >> 2015-10-31 14:20:42 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > >> c2=$3 > >> 2015-10-31 19:46:26 CST ERROR: invalid input syntax for integer: > > "" > >> 2015-10-31 19:46:26 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > >> c2=$3 > >> 2015-10-31 22:42:24 CST ERROR: invalid input syntax for integer: > > "" > >> 2015-10-31 22:42:24 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > >> c2=$3 > >> 2015-10-31 22:55:28 CST ERROR: invalid input syntax for integer: > > "!" > >> 2015-10-31 22:55:28 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > >> c2=$3 > >> > >> As one might notice: How could I bind "cppdb_psqlstmt_17" to > >> cppdb::statement's parameters? > >> PostgreSQL complained weird arguments passed to c2 when the same > >> cppdb::statement::exec() was called repeatedly. > >> > >> Any idea? Please! > >> > >> Best Regards, > >> CN > >> > >> > >> On Thu, Nov 12, 2015, at 12:47 AM, Artyom Beilis wrote: > >> > 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 - The professional email service |
From: Artyom B. <art...@ya...> - 2015-11-12 10:50:06
|
See when you bind a string value it should remain valid until exec is called. http://cppcms.com/sql/cppdb/classcppdb_1_1statement.html#a7b96bac916e748aa2a5cff49d3f615c8 Because cppdb does not copy strings to prevent needless data copy so what happens that set_values and where_values are get destroyed when you leave create function and their references are not valid. Artyom ----- Original Message ----- > From: CN <cn...@fa...> > To: cpp...@li... > Cc: > Sent: Thursday, November 12, 2015 11:53 AM > Subject: Re: [Cppcms-users] cppdb::statement copy and assign > > Because the SQL is dynamically generated, I called > cppdb::session::create_prepared_uncached_statement() instead of > cppdb::session::create_statement(). > > The old version that gave me trouble follows: > > void db_conn_init(cppdb::session &db_session) > { > db_session << "SET NAMES 'UTF8'" << > cppdb::exec; > db_session << "SET TIME ZONE 'UTC'" << > cppdb::exec; > } > > cppdb::statement create(cppdb::session &se,std::string const &table) > { > cppcms::json::array keys,values; > //Feed elements to keys and values here. > std::vector<std::string> set_values; > std::string > column_list=utils::make_column_list(values,set_values); > std::vector<std::string> where_values; > std::string sql="UPDATE "+table+" SET > "+column_list+utils::make_where(keys,where_values); > //"sql" now becomes "UPDATE t SET c2=? WHERE c1=? AND > c2=?" > cppdb::statement st=se.create_prepared_uncached_statement(sql); > size_t set_values_size=set_values.size(); > for(size_t i=0;i < set_values_size;++i){ > if(set_values[i].empty()) > st.bind_null(i+1); > else > st.bind(i+1,set_values[i]); > } > for(size_t i=0,n=where_values.size();i < n;++i){ > if(where_values[i].empty()) > st.bind_null(set_values_size+i+1); > else > st.bind(set_values_size+i+1,where_values[i]); > } > return st; > } > > Please note that > cppdb::statement create(cppdb::session &se,std::string const &table) > is a function. It is not a member function of a class. > > void my_class::use() > { > cppdb::session > > se("postgresql:@pool_size=5;dbname=db2;user=user2;password=xxx",db_conn_init); > std::string table="t"; > cppdb::statement st=create(se,"t"); > cppdb::transaction tx(se); > st.exec(); //Weird error occurs here. > //Do more SQL here like this: > //se << "INSERT INTO ..."; > tx.commit(); > } > > I do not have trouble with this new version: > > void my_class::use() > { > cppdb::session > > se("postgresql:@pool_size=5;dbname=db2;user=user2;password=xxx",db_conn_init); > std::string table="t"; > cppcms::json::array keys,values; > //Feed elements to keys and values here. > std::vector<std::string> set_values; > std::string > column_list=utils::make_column_list(values,set_values); > std::vector<std::string> where_values; > std::string sql="UPDATE "+table+" SET > "+column_list+utils::make_where(keys,where_values); > //"sql" now becomes "UPDATE t SET c2=? WHERE c1=? AND > c2=?" > cppdb::statement st=se.create_prepared_uncached_statement(sql); > size_t set_values_size=set_values.size(); > for(size_t i=0;i < set_values_size;++i){ > if(set_values[i].empty()) > st.bind_null(i+1); > else > st.bind(i+1,set_values[i]); > } > for(size_t i=0,n=where_values.size();i < n;++i){ > if(where_values[i].empty()) > st.bind_null(set_values_size+i+1); > else > st.bind(set_values_size+i+1,where_values[i]); > } > > cppdb::transaction tx(se); > st.exec(); > //Do more SQL here like this: > //se << "INSERT INTO ..."; > tx.commit(); > } > > Best Regards, > CN > > On Thu, Nov 12, 2015, at 04:22 PM, CN wrote: >> Thank you for the reply! >> >> Having received your message, I went back and study frontend.* and >> backend.* of cppdb source code trying to understand more about it. >> According to my findings so far, instances of cppdb::statement in >> backend indeed are reference counted, meaning to me that these objects >> will not be destroyed as long as they are still referenced. >> >> But I can only go that deep into cppdb source. Because my original >> troublesome code actually uses uncached statement but I do not fully >> understand cppdb's statement cache mechanism, I begin to suspect this >> part of cppdb. >> >> I know this is not professional attitude, but the simplified version of >> my troublesome code follows: >> >> cppdb::statement create(cppdb::session &se) >> { >> cppdb::statement st=se.create_prepared_uncached_statement( >> "UPDATE t SET c2=? WHERE c1=? AND c2=?") >> << 'xx' << 2; >> return st; >> } >> >> void use() >> { >> cppdb::session se("connection params"); >> cppdb::statement st=create(se); >> cppdb::transaction tx(se); >> st.exec(); //Weird error occurs here. >> //Do more SQL here like this: >> //se << "INSERT INTO ..."; >> tx.commit(); >> } >> >> Note that the data type of t.c2 is INTEGER. >> >> And the PostgreSQL error log follows: >> >> 2015-10-31 14:20:42 CST ERROR: invalid input syntax for integer: >> "cppdb_psqlstmt_17" >> 2015-10-31 14:20:42 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND >> c2=$3 >> 2015-10-31 19:46:26 CST ERROR: invalid input syntax for integer: > "" >> 2015-10-31 19:46:26 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND >> c2=$3 >> 2015-10-31 22:42:24 CST ERROR: invalid input syntax for integer: > "" >> 2015-10-31 22:42:24 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND >> c2=$3 >> 2015-10-31 22:55:28 CST ERROR: invalid input syntax for integer: > "!" >> 2015-10-31 22:55:28 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND >> c2=$3 >> >> As one might notice: How could I bind "cppdb_psqlstmt_17" to >> cppdb::statement's parameters? >> PostgreSQL complained weird arguments passed to c2 when the same >> cppdb::statement::exec() was called repeatedly. >> >> Any idea? Please! >> >> Best Regards, >> CN >> >> >> On Thu, Nov 12, 2015, at 12:47 AM, Artyom Beilis wrote: >> > 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 >> > > >> > >> > > ------------------------------------------------------------------------------ >> > _______________________________________________ >> > Cppcms-users mailing list >> > Cpp...@li... >> > https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> -- >> http://www.fastmail.com - Access your email from home and the web >> >> >> > ------------------------------------------------------------------------------ >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > -- > 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 > |
From: CN <cn...@fa...> - 2015-11-12 09:53:16
|
Because the SQL is dynamically generated, I called cppdb::session::create_prepared_uncached_statement() instead of cppdb::session::create_statement(). The old version that gave me trouble follows: void db_conn_init(cppdb::session &db_session) { db_session << "SET NAMES 'UTF8'" << cppdb::exec; db_session << "SET TIME ZONE 'UTC'" << cppdb::exec; } cppdb::statement create(cppdb::session &se,std::string const &table) { cppcms::json::array keys,values; //Feed elements to keys and values here. std::vector<std::string> set_values; std::string column_list=utils::make_column_list(values,set_values); std::vector<std::string> where_values; std::string sql="UPDATE "+table+" SET "+column_list+utils::make_where(keys,where_values); //"sql" now becomes "UPDATE t SET c2=? WHERE c1=? AND c2=?" cppdb::statement st=se.create_prepared_uncached_statement(sql); size_t set_values_size=set_values.size(); for(size_t i=0;i < set_values_size;++i){ if(set_values[i].empty()) st.bind_null(i+1); else st.bind(i+1,set_values[i]); } for(size_t i=0,n=where_values.size();i < n;++i){ if(where_values[i].empty()) st.bind_null(set_values_size+i+1); else st.bind(set_values_size+i+1,where_values[i]); } return st; } Please note that cppdb::statement create(cppdb::session &se,std::string const &table) is a function. It is not a member function of a class. void my_class::use() { cppdb::session se("postgresql:@pool_size=5;dbname=db2;user=user2;password=xxx",db_conn_init); std::string table="t"; cppdb::statement st=create(se,"t"); cppdb::transaction tx(se); st.exec(); //Weird error occurs here. //Do more SQL here like this: //se << "INSERT INTO ..."; tx.commit(); } I do not have trouble with this new version: void my_class::use() { cppdb::session se("postgresql:@pool_size=5;dbname=db2;user=user2;password=xxx",db_conn_init); std::string table="t"; cppcms::json::array keys,values; //Feed elements to keys and values here. std::vector<std::string> set_values; std::string column_list=utils::make_column_list(values,set_values); std::vector<std::string> where_values; std::string sql="UPDATE "+table+" SET "+column_list+utils::make_where(keys,where_values); //"sql" now becomes "UPDATE t SET c2=? WHERE c1=? AND c2=?" cppdb::statement st=se.create_prepared_uncached_statement(sql); size_t set_values_size=set_values.size(); for(size_t i=0;i < set_values_size;++i){ if(set_values[i].empty()) st.bind_null(i+1); else st.bind(i+1,set_values[i]); } for(size_t i=0,n=where_values.size();i < n;++i){ if(where_values[i].empty()) st.bind_null(set_values_size+i+1); else st.bind(set_values_size+i+1,where_values[i]); } cppdb::transaction tx(se); st.exec(); //Do more SQL here like this: //se << "INSERT INTO ..."; tx.commit(); } Best Regards, CN On Thu, Nov 12, 2015, at 04:22 PM, CN wrote: > Thank you for the reply! > > Having received your message, I went back and study frontend.* and > backend.* of cppdb source code trying to understand more about it. > According to my findings so far, instances of cppdb::statement in > backend indeed are reference counted, meaning to me that these objects > will not be destroyed as long as they are still referenced. > > But I can only go that deep into cppdb source. Because my original > troublesome code actually uses uncached statement but I do not fully > understand cppdb's statement cache mechanism, I begin to suspect this > part of cppdb. > > I know this is not professional attitude, but the simplified version of > my troublesome code follows: > > cppdb::statement create(cppdb::session &se) > { > cppdb::statement st=se.create_prepared_uncached_statement( > "UPDATE t SET c2=? WHERE c1=? AND c2=?") > << 'xx' << 2; > return st; > } > > void use() > { > cppdb::session se("connection params"); > cppdb::statement st=create(se); > cppdb::transaction tx(se); > st.exec(); //Weird error occurs here. > //Do more SQL here like this: > //se << "INSERT INTO ..."; > tx.commit(); > } > > Note that the data type of t.c2 is INTEGER. > > And the PostgreSQL error log follows: > > 2015-10-31 14:20:42 CST ERROR: invalid input syntax for integer: > "cppdb_psqlstmt_17" > 2015-10-31 14:20:42 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > 2015-10-31 19:46:26 CST ERROR: invalid input syntax for integer: "" > 2015-10-31 19:46:26 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > 2015-10-31 22:42:24 CST ERROR: invalid input syntax for integer: "" > 2015-10-31 22:42:24 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > 2015-10-31 22:55:28 CST ERROR: invalid input syntax for integer: "!" > 2015-10-31 22:55:28 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > > As one might notice: How could I bind "cppdb_psqlstmt_17" to > cppdb::statement's parameters? > PostgreSQL complained weird arguments passed to c2 when the same > cppdb::statement::exec() was called repeatedly. > > Any idea? Please! > > Best Regards, > CN > > > On Thu, Nov 12, 2015, at 12:47 AM, Artyom Beilis wrote: > > 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 > > > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > -- > http://www.fastmail.com - Access your email from home and the web > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users -- http://www.fastmail.com - Access all of your messages and folders wherever you are |
From: Artyom B. <art...@ya...> - 2015-11-12 08:45:19
|
Can you show the full code (- you can hide passwords in connection strings)? First of all it looks like you bind two parameters when 3 are required. i.e. cppdb::statement st=se.create_prepared_uncached_statement("UPDATE t SET c2=? WHERE c1=? AND c2=?") << 'xx' << 2; And what is 'xx'? It isn't even C++. Also you probably what to call se.create_statement() create_prepared_uncached_statement is for execution of a prepared statement many times but not letting it into cache (for example for insert on many rows one time) create_statement - creates ordinary unprepared statement (it still uses binding) good for one time calls of custom statement or rare statements create_prepared_statement - creates prepared statement and caches it for future reuse (default) statements that are eused frequently. Artyom Beilis ----- Original Message ----- > From: CN <cn...@fa...> > To: cpp...@li... > Cc: > Sent: Thursday, November 12, 2015 10:22 AM > Subject: Re: [Cppcms-users] cppdb::statement copy and assign > >T hank you for the reply! > > Having received your message, I went back and study frontend.* and > backend.* of cppdb source code trying to understand more about it. > According to my findings so far, instances of cppdb::statement in > backend indeed are reference counted, meaning to me that these objects > will not be destroyed as long as they are still referenced. > > But I can only go that deep into cppdb source. Because my original > troublesome code actually uses uncached statement but I do not fully > understand cppdb's statement cache mechanism, I begin to suspect this > part of cppdb. > > I know this is not professional attitude, but the simplified version of > my troublesome code follows: > > cppdb::statement create(cppdb::session &se) > { > cppdb::statement st=se.create_prepared_uncached_statement( > "UPDATE t SET c2=? WHERE c1=? AND c2=?") > << 'xx' << 2; > return st; > } > > void use() > { > cppdb::session se("connection params"); > cppdb::statement st=create(se); > cppdb::transaction tx(se); > st.exec(); //Weird error occurs here. > //Do more SQL here like this: > //se << "INSERT INTO ..."; > tx.commit(); > } > > Note that the data type of t.c2 is INTEGER. > > And the PostgreSQL error log follows: > > 2015-10-31 14:20:42 CST ERROR: invalid input syntax for integer: > "cppdb_psqlstmt_17" > 2015-10-31 14:20:42 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > 2015-10-31 19:46:26 CST ERROR: invalid input syntax for integer: "" > 2015-10-31 19:46:26 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > 2015-10-31 22:42:24 CST ERROR: invalid input syntax for integer: "" > 2015-10-31 22:42:24 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > 2015-10-31 22:55:28 CST ERROR: invalid input syntax for integer: "!" > 2015-10-31 22:55:28 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND > c2=$3 > > As one might notice: How could I bind "cppdb_psqlstmt_17" to > cppdb::statement's parameters? > PostgreSQL complained weird arguments passed to c2 when the same > cppdb::statement::exec() was called repeatedly. > > Any idea? Please! > > Best Regards, > CN > > > On Thu, Nov 12, 2015, at 12:47 AM, Artyom Beilis wrote: >> 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 >> > >> >> > ------------------------------------------------------------------------------ >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users > > -- > http://www.fastmail.com - Access your email from home and the web > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: CN <cn...@fa...> - 2015-11-12 08:22:25
|
Thank you for the reply! Having received your message, I went back and study frontend.* and backend.* of cppdb source code trying to understand more about it. According to my findings so far, instances of cppdb::statement in backend indeed are reference counted, meaning to me that these objects will not be destroyed as long as they are still referenced. But I can only go that deep into cppdb source. Because my original troublesome code actually uses uncached statement but I do not fully understand cppdb's statement cache mechanism, I begin to suspect this part of cppdb. I know this is not professional attitude, but the simplified version of my troublesome code follows: cppdb::statement create(cppdb::session &se) { cppdb::statement st=se.create_prepared_uncached_statement( "UPDATE t SET c2=? WHERE c1=? AND c2=?") << 'xx' << 2; return st; } void use() { cppdb::session se("connection params"); cppdb::statement st=create(se); cppdb::transaction tx(se); st.exec(); //Weird error occurs here. //Do more SQL here like this: //se << "INSERT INTO ..."; tx.commit(); } Note that the data type of t.c2 is INTEGER. And the PostgreSQL error log follows: 2015-10-31 14:20:42 CST ERROR: invalid input syntax for integer: "cppdb_psqlstmt_17" 2015-10-31 14:20:42 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND c2=$3 2015-10-31 19:46:26 CST ERROR: invalid input syntax for integer: "" 2015-10-31 19:46:26 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND c2=$3 2015-10-31 22:42:24 CST ERROR: invalid input syntax for integer: "" 2015-10-31 22:42:24 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND c2=$3 2015-10-31 22:55:28 CST ERROR: invalid input syntax for integer: "!" 2015-10-31 22:55:28 CST STATEMENT: UPDATE t SET c2=$1 WHERE c1=$2 AND c2=$3 As one might notice: How could I bind "cppdb_psqlstmt_17" to cppdb::statement's parameters? PostgreSQL complained weird arguments passed to c2 when the same cppdb::statement::exec() was called repeatedly. Any idea? Please! Best Regards, CN On Thu, Nov 12, 2015, at 12:47 AM, Artyom Beilis wrote: > 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 > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users -- http://www.fastmail.com - Access your email from home and the web |
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 > |
From: CN <cn...@fa...> - 2015-11-11 14:40:43
|
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 |
From: mawan s. <ma...@gm...> - 2015-11-02 16:19:51
|
Yes, i use class for easy and manageable. And I pooled on the List. Like MVC approach iniJava orPHP. So, what is the best way, shoud i covert to structure? Or save it in cache? Or there are any function to execute that procedure? On Nov 2, 2015 10:28 PM, "Artyom Beilis" <art...@ya...> wrote: > Did you define our content variables as class member. > > See cppcms::application class are reusable. They are stored in pool and > used and created on demand. > > It is not created and destroyed per request, rather reused so I assume > your menus are accumulated. > > > Artyom Beilis > > ------------------------------ > *From:* mawan sugiyanto <ma...@gm...> > *To:* cpp...@li... > *Sent:* Monday, November 2, 2015 1:37 PM > *Subject:* Re: [Cppcms-users] load parameters and data initialization > > It is similar pages variable in blog example. Please advice for best way > load dynamic variables. > > Thanks . > > > > On Mon, Nov 2, 2015 at 6:26 PM, mawan sugiyanto <ma...@gm...> wrote: > > Dear All > > I want to create template menus. I create menu variable ( array),ini > master content variable. I initialize menu data at application::init() > > > void root_master::init() > { > > ///PREPARE MAIN MENU > prepare_menu(); > > > I build menu from database, and store in content variable. Why variable is > not reset after new request? In my case , in another request , there are > accumulation menu item. > > request 1 = menu_a, menu_b > request 2 = menu_a, menu_b, menu_a, menu_b > > should i use clear procedur to reset variable like database session > variable? > > Thankyou > > > Mawan > [newbie] > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Artyom B. <art...@ya...> - 2015-11-02 15:26:47
|
Did you define our content variables as class member. See cppcms::application class are reusable. They are stored in pool andused and created on demand. It is not created and destroyed per request, rather reused so I assume your menus are accumulated. Artyom Beilis From: mawan sugiyanto <ma...@gm...> To: cpp...@li... Sent: Monday, November 2, 2015 1:37 PM Subject: Re: [Cppcms-users] load parameters and data initialization It is similar pages variable in blog example. Please advice for best way load dynamic variables. Thanks . On Mon, Nov 2, 2015 at 6:26 PM, mawan sugiyanto <ma...@gm...> wrote: Dear All I want to create template menus. I create menu variable ( array),ini master content variable. I initialize menu data at application::init() void root_master::init() { ///PREPARE MAIN MENU prepare_menu(); I build menu from database, and store in content variable. Why variable is not reset after new request? In my case , in another request , there are accumulation menu item. request 1 = menu_a, menu_brequest 2 = menu_a, menu_b, menu_a, menu_b should i use clear procedur to reset variable like database session variable? Thankyou Mawan [newbie] ------------------------------------------------------------------------------ _______________________________________________ Cppcms-users mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppcms-users |
From: mawan s. <ma...@gm...> - 2015-11-02 11:38:09
|
It is similar pages variable in blog example. Please advice for best way load dynamic variables. Thanks . On Mon, Nov 2, 2015 at 6:26 PM, mawan sugiyanto <ma...@gm...> wrote: > Dear All > > I want to create template menus. I create menu variable ( array),ini > master content variable. I initialize menu data at application::init() > > > void root_master::init() > { > > ///PREPARE MAIN MENU > prepare_menu(); > > > I build menu from database, and store in content variable. Why variable is > not reset after new request? In my case , in another request , there are > accumulation menu item. > > request 1 = menu_a, menu_b > request 2 = menu_a, menu_b, menu_a, menu_b > > should i use clear procedur to reset variable like database session > variable? > > Thankyou > > > Mawan > [newbie] > |
From: mawan s. <ma...@gm...> - 2015-11-02 11:27:08
|
Dear All I want to create template menus. I create menu variable ( array),ini master content variable. I initialize menu data at application::init() void root_master::init() { ///PREPARE MAIN MENU prepare_menu(); I build menu from database, and store in content variable. Why variable is not reset after new request? In my case , in another request , there are accumulation menu item. request 1 = menu_a, menu_b request 2 = menu_a, menu_b, menu_a, menu_b should i use clear procedur to reset variable like database session variable? Thankyou Mawan [newbie] |
From: mawan s. <ma...@gm...> - 2015-10-27 02:18:09
|
:( i think this is a good step by step http://www.programmershare.com/1248484/ On Mon, Oct 26, 2015 at 6:45 PM, Marcel Hellwig <ke...@co...> wrote: > http://lmgtfy.com/?q=cppcms+compile+windows > > Greetings > > On 26.10.2015 10:41, mawan sugiyanto wrote: > > Dear All > > > > Are there any tutorial to compile cppcms and cppdb on Windows? > > > > Thanks > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > > > > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: mawan s. <ma...@gm...> - 2015-10-26 13:33:16
|
Thankyu Marcel for link, i 'll try it. On Oct 26, 2015 6:46 PM, "Marcel Hellwig" <ke...@co...> wrote: > http://lmgtfy.com/?q=cppcms+compile+windows > > Greetings > > On 26.10.2015 10:41, mawan sugiyanto wrote: > > Dear All > > > > Are there any tutorial to compile cppcms and cppdb on Windows? > > > > Thanks > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > > > > > _______________________________________________ > > Cppcms-users mailing list > > Cpp...@li... > > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |