dbTalk Databases Forums  

equal_list() using a bool vector

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss equal_list() using a bool vector in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark Merendino
 
Posts: n/a

Default equal_list() using a bool vector - 05-03-2005 , 04:19 PM






------_=_NextPart_001_01C55025.788635D9
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Im trying to use the equal_list() method and passing a vector to it.
such as in the example from the manual...
=20
////////////////////////
The vector form (not shown above) allows you to pass a boolean vector
which is a time saver if you use the some pattern more than once as it
avoids having to create the vector from the arguments each time. If a is
a boolean vector then a[0] will hold wether to include the first
variable a[1] the second etc... For example:=20

=09
vector<bool> a; =20
a[0] =3D false; a[1] =3D false; a[2] =3D true; a[3] =3D true; a[4] =3D
false; =20
query << "SELECT * FROM stock WHERE " << q.equal_list(" AND ",
a); =20

///////////
=20
(Note: Im passing "&a" because it wants to receive a pointer to a
vector. Think this is a typo in the example.)
=20
However im getting and unresolved external symbol. (...Note, "SSB" is my
class)
=20
"public: class SSB_cus_equal_list<enum mysqlpp::quote_type0> __thiscall
SSB::equal_list<enum mysqlpp::quote_type0>(char const *, char const *,
enum mysqlpp::quote_type0, class std::vector<bool,class
std::allocator<bool> > *) const"
=20
Does the definition of this method exist? I have tried to figure it out
but im not sure. Im a little weak in STL to say the least and my head
is spinning trying to follow this.
=20
Any help would be appreciated. Anyone using equal_list() this way with
out trouble?
=20
Thanks
=20

------_=_NextPart_001_01C55025.788635D9--

Reply With Quote
  #2  
Old   
Chris Frey
 
Posts: n/a

Default Re: equal_list() using a bool vector - 05-03-2005 , 05:21 PM






On Tue, May 03, 2005 at 05:17:10PM -0400, Mark Merendino wrote:
Quote:
The vector form (not shown above) allows you to pass a boolean vector
which is a time saver if you use the some pattern more than once as it
avoids having to create the vector from the arguments each time. If a is
a boolean vector then a[0] will hold wether to include the first
variable a[1] the second etc... For example:


vector<bool> a;
a[0] = false; a[1] = false; a[2] = true; a[3] = true; a[4] =
false;
query << "SELECT * FROM stock WHERE " << q.equal_list(" AND ",
a);

///////////

(Note: Im passing "&a" because it wants to receive a pointer to a
vector. Think this is a typo in the example.)
Yep. The declaration in custom.pl takes a pointer.

Quote:
However im getting and unresolved external symbol. (...Note, "SSB" is my
class)

"public: class SSB_cus_equal_list<enum mysqlpp::quote_type0> __thiscall
SSB::equal_list<enum mysqlpp::quote_type0>(char const *, char const *,
enum mysqlpp::quote_type0, class std::vector<bool,class
std::allocator<bool> > *) const"
And there's only a declaration, no definition.

I'm looking inside vallist.h, and there appears to be code that handles
vector<bool> arrays, but it also requires you to mess with manipulators.

There's a factory function called equal_list() that goes like this (untested):

query << "SELECT * FROM stock WHERE " <<
equal_list(seq1, seq2, " AND ", " = ", manip, a);

Sequence 1 contains the field names, sequence 2 contains the values.
It expects the sequences to have begin() and end() iterator semantics.

The manipulator is used in the stream before each value (for escaping
or quoting).

This would be wonderful if I could do something like this:

equal_list(q.field_list(), q.value_list(),
" AND ", " = ", some_magical_manipulator, a);

But I can't find any code to support this behaviour.

I'll see if I can cook up a patch, unless someone beats me to it. :-)

- Chris


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Warren Young
 
Posts: n/a

Default Re: equal_list() using a bool vector - 05-03-2005 , 06:29 PM



Mark Merendino wrote:

Quote:
Im trying to use the equal_list() method and passing a vector to it.
such as in the example from the manual...
I see you're still using the old manuals. I elided that stuff when
moving it over to the new structure, in the name of simplicity. It
seemed like a case of someone who was too close to the library
documenting internals when they should have kept quiet about it.

I suggest one of two things: a) we figure out how this feature is
supposed to work, and document it toward the end of the existing SSQLS
section of the user manual; or b) we keep it as it is: an internal
feature mentioned only in the reference manual.

Quote:
vector<bool> a;
a[0] = false; a[1] = false; a[2] = true; a[3] = true; a[4] =
false;
You're skating on thin ice with that technique. Subscripting a vector
doesn't expand it. Since you haven't reserve()d any space in the
vector, you're depending on the implementation to preallocate some for
you. It happens that you usually get 10 or so slots at the start with
the STL implementations I'm familiar with, but it's bad form to depend
on them being there.

The simplest safe code is:

vector<bool> a(5, false);
a[2] = true;
a[3] = true;

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Mark Merendino
 
Posts: n/a

Default RE: equal_list() using a bool vector - 05-05-2005 , 11:37 AM



=20
After researching this for a few days I believe I have added the correct
code needed to get equal_list() to accept a vector (Also value_list()
and field_list()). It wasn't that hard once I had an understanding of
how the other functions worked. I felt this was worth while because it
will make my life a lot easier for some of the things I want to do.
Anyway, here is the code I added to my custom.pl to get this feature
working. I suggest, assuming we agree it's the correct code, that it be
added to the library. I know it was suggested that this was ment to be
an internal function, but I think it is a very useful one.=20
=20
/////Code added after this function in custom.pl.......=20
//// template <class Manip>
//// inline NAME##_cus_equal_list<Manip> NAME::equal_list(cchar *d,
cchar *c, Manip m,=20
//// $cusparms22)
const {=20
//// return NAME##_cus_equal_list<Manip> (this, d, c, m, $cusparmsv);=20
//// }=20

template <class Manip>
inline NAME##_cus_value_list<Manip> NAME::value_list(cchar *d, Manip
m,
=09
std::vector<bool> *i) const {=20
return NAME##_cus_value_list<Manip> (this, d, m, i);=20
}=20

template <class Manip>
inline NAME##_cus_field_list<Manip> NAME::field_list(cchar *d, Manip
m,
=09
std::vector<bool> *i) const {=20
return NAME##_cus_field_list<Manip> (this, d, m, i);=20
}=20

template <class Manip>
inline NAME##_cus_equal_list<Manip> NAME::equal_list(cchar *d, cchar
*c, Manip m,
=09
std::vector<bool> *i) const {=20
return NAME##_cus_equal_list<Manip> (this, d, c, m, i);=20
}=20
///////////

An example of using it....

vector<bool> a(5, false); =20
a[stock_weight] =3D true;=20
a[stock_price] =3D true; =20
query << "SELECT * FROM stock WHERE " << q.equal_list(" AND ",
&a); =20

Produces the query....
=09
SELECT * FROM stock WHERE weight=3D0.95 AND price=3D0.97

-----Original Message-----
From: Warren Young [mailto:mysqlpp (AT) etr-usa (DOT) com]=20
Sent: Tuesday, May 03, 2005 7:29 PM
To: MySQL++ Mailing List
Subject: Re: equal_list() using a bool vector

Mark Merendino wrote:

Quote:
Im trying to use the equal_list() method and passing a vector to it.
such as in the example from the manual...
I see you're still using the old manuals. I elided that stuff when
moving it over to the new structure, in the name of simplicity. It
seemed like a case of someone who was too close to the library
documenting internals when they should have kept quiet about it.

I suggest one of two things: a) we figure out how this feature is
supposed to work, and document it toward the end of the existing SSQLS
section of the user manual; or b) we keep it as it is: an internal
feature mentioned only in the reference manual.

Quote:
vector<bool> a; =20
a[0] =3D false; a[1] =3D false; a[2] =3D true; a[3] =3D true; a[4] =
=3D
false; =20
You're skating on thin ice with that technique. Subscripting a vector
doesn't expand it. Since you haven't reserve()d any space in the
vector, you're depending on the implementation to preallocate some for
you. It happens that you usually get 10 or so slots at the start with
the STL implementations I'm familiar with, but it's bad form to depend
on them being there.

The simplest safe code is:

vector<bool> a(5, false);
a[2] =3D true;
a[3] =3D true;

--=20
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:
http://lists.mysql.com/plusplus?unsu... cnt (DOT) com


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: equal_list() using a bool vector - 05-10-2005 , 12:10 PM



Mark Merendino wrote:

Quote:
Anyway, here is the code I added to my custom.pl
Non-trivial patches need to be in unified diff format, please, if only
because that encodes exactly where in the file to apply your patch.

Quote:
I know it was suggested that this was ment to be
an internal function,
Either that, or a documented one. Therefore, please also supply a patch
to the user manual. Even if you think you cannot write, having
something I can go in and rewrite would be better than having to explain
this from scratch, as I don't fully understand it right now.

Also, can you explain what you found in the library that prevented your
example code from working in the first place? I.e., precisely what
problem this patch solves?

Quote:
An example of using it....

vector<bool> a(5, false);
a[stock_weight] = true;
a[stock_price] = true;
query << "SELECT * FROM stock WHERE " << q.equal_list(" AND ",
&a);
I assume that the SSQLS being used here is the standard one used in the
tutorial, and that 'q' is an instance of that SSQLS?

I don't like the named stock_* constants; they just obscure things.

This example, suitably clarified, should be part of your userman patch.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.