faustf

SQL total row

4 posts in this topic

hi guy   i want  a  total row  of  one  table , i try  to use  this  command  but not  go   

_Connetti_DB_Mysql() ; apro db 
        $rsCustomers_MY = $objConnMY.Execute("SELECT COUNT (id_address) FROM ps_address") ; trovo il totale in ps address
        With $rsCustomers_MY
            While Not .EOF
                ConsoleWrite(.Fields("id_address").Value & @LF)
                ;$ps_Country_code_array[$b] = (.Fields("id_address").Value)
                $b += 1
                .MoveNext
            WEnd
            .Close
        EndWith

        _Close_DB_MYSQL() ;  chiudo db

some one can help me?   thankz 

 

Share this post


Link to post
Share on other sites



The name of the column you want is undefined since there is no column alias to "COUNT (id_address)", so when you ask the value of the field id_address the ODBC driver doesn't know what you want.

You can do either give the column an alias name using the optional AS clause:

_Connetti_DB_Mysql() ; apro db 
        $rsCustomers_MY = $objConnMY.Execute("SELECT COUNT(*) as cnt FROM ps_address") ; trovo il totale in ps address
        With $rsCustomers_MY
            While Not .EOF
                ConsoleWrite(.Fields("cnt").Value & @LF)
                ;$ps_Country_code_array[$b] = (.Fields("cnt").Value)
                $b += 1
                .MoveNext
            WEnd
            .Close
        EndWith

        _Close_DB_MYSQL() ;  chiudo db

or address the field by index:

_Connetti_DB_Mysql() ; apro db 
        $rsCustomers_MY = $objConnMY.Execute("SELECT COUNT(*) FROM ps_address") ; trovo il totale in ps address
        With $rsCustomers_MY
            While Not .EOF
                ConsoleWrite(.Fields(1).Value & @LF)
                ;$ps_Country_code_array[$b] = (.Fields(1).Value)
                $b += 1
                .MoveNext
            WEnd
            .Close
        EndWith

        _Close_DB_MYSQL() ;  chiudo db

BTW are you sure you want to close the connection right after obtaining the total number of rows?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

yes  i    think is much better if  after  select  or  work , with db  you  close it , or  not?? 

Share this post


Link to post
Share on other sites

In the general use case, you init the engine, open one or more connection(s), perform the work and only close the connection(s) just before terminating.

Needlessly opening a new connection or reopening a connection previously closed is a waste of cycles, since the engine needs to re-parse the whole database schema everytime. It doesn't show much with DBs which contain just a couple tables and little around (few triggers, etc.) but it's very noticeable with DBs having hundreds or thousands of tables and a very complex schema.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now