Hi all:

Today, I want to do a

            select count(*) from Users;

by using peer.

But I was stopped. After study, I find Peer get table name from the first
part of Column name. That means if I should pass   Users.UserName into peer,
peer will get the table name and send:

        select Users.Username from Users;

Now

1. if I pass    count(*)  to peer,  peer do not know which table to use
2. if I pass   Users.count(*)  to peer, peer will send
        select Users.count(*) from Users;
This is illugae to any database.

Of cause I can just select something from the table and count the returns,
but I think it is a waste of system resource, and will slow down the
performance. And if using max()   min ....   functions, we will again met
this problem.

----------------------------------------------------------------------------
-----------------------------------------------
Solution:    I changed BasePeer

function name:
 public static String createQueryString( Criteria criteria ) throws
Exception



        for (int i=0; i<select.size(); i++)
        {
            String columnName = select.get(i);
            selectClause.add(columnName);

            int braceplace = columnName.indexOf('(');
            if(braceplace == -1)



fromClause.add(columnName.substring(0,columnName.indexOf('.') ));
            }
            else
            {

fromClause.add(columnName.substring(braceplace+1,columnName.indexOf('.') ));
            }
        }

Now you can just pass:    count(Users.UserID)  into peer.  Peer will get the
table name and send

        select count(Users.Userid) from Users;


This works, and for min, max  it also works

----------------------------------------------------------------------------
--

This is my first time contribute a small change, will you take this
change???

Vote + 1


Regards

fanyun




------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to