List:MySQL++« Previous MessageNext Message »
From:Mark Merendino Date:May 5 2005 4:37pm
Subject:RE: equal_list() using a bool vector
View as plain text  
 
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. 
 
/////Code added after this function in custom.pl....... 
//// template <class Manip>
//// inline NAME##_cus_equal_list<Manip> NAME::equal_list(cchar *d,
cchar *c, Manip m, 
////							 $cusparms22)
const { 
////  return NAME##_cus_equal_list<Manip> (this, d, c, m, $cusparmsv); 
////  } 

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

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

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

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);  

Produces the query....
	
	SELECT * FROM stock WHERE weight=0.95 AND price=0.97

-----Original Message-----
From: Warren Young [mailto:mysqlpp@stripped] 
Sent: Tuesday, May 03, 2005 7:29 PM
To: MySQL++ Mailing List
Subject: Re: equal_list() using a bool vector

Mark Merendino wrote:

> 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.

> 	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?unsub=1

Thread
equal_list() using a bool vectorMark Merendino3 May
  • Re: equal_list() using a bool vectorChris Frey4 May
  • Re: equal_list() using a bool vectorWarren Young4 May
RE: equal_list() using a bool vectorMark Merendino5 May
  • Re: equal_list() using a bool vectorWarren Young10 May
    • [PATCH] Re: equal_list() using a bool vectorChris Frey10 May
      • Re: [PATCH] Re: equal_list() using a bool vectorWarren Young10 May
        • Re: [PATCH] Re: equal_list() using a bool vectorChris Frey10 May
          • Re: [PATCH] Re: equal_list() using a bool vectorWarren Young11 May
RE: [PATCH] Re: equal_list() using a bool vectorMark Merendino11 May
  • Re: [PATCH] Re: equal_list() using a bool vectorChris Frey11 May
    • Re: [PATCH] Re: equal_list() using a bool vectorWarren Young11 May