I think this won't slow down the function in any way - it will just add
more flexibility for the queries without touching the original arguments
order. I didn't found any other way to do this.

Here are the queries:
Original:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define INSERT "insert into %s \
( pw_name, pw_domain, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir,
pw_shell \
, pw_clear_passwd ) values ( \"%s\", \"%s\", \
\"%s\", %d, 0, \"%s\", \"%s\", \"%s\" ,\"%s\" )"
My:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define INSERT "insert into users \
(`account_id`, `user`, `gid`, `pass`, `clearpass`, `mail`, `quota`) \
select `account_id`, '%2$s', `gid`, '%4$s', '%9$s', '1', '%8$s' from
accounts where domain_name = '%3$s'"

Original:
#ifdef MANY_DOMAINS
#define DELETE_USER "delete from %s where pw_name = \"%s\" \
and pw_domain = \"%s\" "
My:
#ifdef MANY_DOMAINS
#define DELETE_USER "delete from `%s` where `user` = \"%s\" \
and `account_id` = (select `account_id` from `accounts` where
`domain_name` = \"%s\") "

Original:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define USER_SELECT "select pw_name, pw_passwd, pw_uid, pw_gid, \
pw_gecos, pw_dir, pw_shell , pw_clear_passwd \
from %s where pw_name = \"%s\" and pw_domain = \"%s\" "
My:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define USER_SELECT "select user as pw_name, pass as pw_passwd, '0' as
pw_uid, '0' as pw_gid,\
gecos as pw_gecos, concat('/home/vpopmail/', '%3$s', '/', '%2$s') as
pw_dir, quota as pw_shell,\
clearpass as pw_clear_passwd from `%1$s` where user = '%2$s' and
account_id = (select account_id from accounts where domain_name='%3$s')"

Original:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define GETALL "select pw_name, \
pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell, \
pw_clear_passwd from %s where pw_domain = \"%s\""
My:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define GETALL "select user as pw_name, pass as pw_passwd, \
'0' as pw_uid, '0' as pw_gid, gecos as pw_gecos,
concat('/home/vpopmail/', '%2$s', '/', user) as pw_dir, \
quota as pw_shell, clearpass as pw_clear_passwd from `%1$s` \
where account_id = (select account_id from accounts where domain_name =
'%2$s')"

Original:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define SETPW "update %s set pw_passwd = \"%s\", \
pw_uid = %d, pw_gid = %d, pw_gecos = \"%s\", pw_dir = \"%s\", \
pw_shell = \"%s\" \
, pw_clear_passwd = \"%s\" \
where pw_name = \"%s\" \
and pw_domain = \"%s\" "
My:
#ifdef MANY_DOMAINS
#ifdef CLEAR_PASS
#define SETPW "update `%1$s` set pass = '%2$s', \
gecos = '%5$s', quota = '%7$s', \
clearpass = '%8$s' \
where user = '%9$s' \
and account_id = (select account_id from accounts where domain_name =
'%10$s')"

And the tables structure:
mysql> desc users;
+------------+-----------------+------+-----+---------+----------------+
| Field      | Type            | Null | Key | Default | Extra          |
+------------+-----------------+------+-----+---------+----------------+
| account_id | int(11)         |      |     | 0       |                |
| uid        | int(4) unsigned |      | PRI | NULL    | auto_increment |
| gid        | int(4) unsigned |      |     | 0       |                |
| user       | varchar(128)    |      |     |         |                |
| gecos      | varchar(128)    | YES  |     | NULL    |                |
| pass       | varchar(128)    |      |     |         |                |
| clearpass  | varchar(64)     |      |     |         |                |
| admin      | int(1) unsigned |      |     | 0       |                |
| ftp        | int(1) unsigned |      |     | 0       |                |
| mail       | int(1) unsigned |      |     | 0       |                |
| quota      | varchar(20)     |      |     | NOQUOTA |                |
+------------+-----------------+------+-----+---------+----------------+
11 rows in set (0.00 sec)

mysql> desc accounts;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra         
|
+-------------+------------------+------+-----+---------+----------------+
| account_id  | int(10) unsigned |      | PRI | NULL    | auto_increment
|
| domain_name | varchar(255)     |      |     |         |               
|
| gid         | int(4) unsigned  |      |     | 0       |               
|
| site_root   | varchar(255)     |      |     | 0       |               
|
+-------------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

I've changed MYSQL_DEFAULT_TABLE to 'users'.

Regards,
Stoyan

On Sat, 2005-07-09 at 03:01, Tom Collins wrote:
> OK, I see what you're talking about.  It isn't part of the C99 standard 
> and I haven't seen it in other code before.
> 
> I am very hesitant to include your patch in the main vpopmail 
> distribution though.  I tried to make a very simple, reliable function 
> for creating SQL queries, and I think the %2$s notation adds 
> unnecessary complexity.
> 
> Can you let me know the exact place in the code you needed to use it?  
> Could we re-work the queries in some way to allow for a single order 
> that works for both variations without a special format string?
> 
> On Jul 8, 2005, at 1:43 PM, Stoyan Marinov wrote:
> >  Tom,
> >
> >  You can find more info about this on the printf man page (3). Shortly 
> > - you can reuse some of the variables passed or reorder them. %2$s 
> > means the second string variable.
> >
> >  Stoyan
> >
> >  On Fri, 2005-07-08 at 23:39, Tom Collins wrote:On Jul 8, 2005, at 
> > 9:49 AM, Stoyan Marinov wrote:
> >> > I needed to customize the vpopmail table structure for my needs and
> >> > because of this I needed a different order of the arguments in the
> >> > MySQL
> >> > queries. I tried to use the %2$s in a query and noticed I can't do
> >> > that.
> >> > That's why I've made this little patch to make possible use this 
> >> style
> >> > for arguments.
> >>
> >> I'm not familiar with using %2$s in a printf -- what does it mean?  
> >> Can
> >> you not accomplish the same thing with another style?
> >>
> >> --
> >> Tom Collins  -  [EMAIL PROTECTED]
> >> QmailAdmin: http://qmailadmin.sf.net/  Vpopmail: 
> >> http://vpopmail.sf.net/
> >> You don't need a laptop to troubleshoot high-speed Internet:
> >> sniffter.com
> >
> >
> --
> Tom Collins  -  [EMAIL PROTECTED]
> QmailAdmin: http://qmailadmin.sf.net/  Vpopmail: http://vpopmail.sf.net/
> You don't need a laptop to troubleshoot high-speed Internet: 
> sniffter.com

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to