rowcount

Efficiently getting number of rows returned of SELECT query with WHERE clause using PDO

旧巷老猫 提交于 2019-12-06 09:53:39
问题 There are numerous discussions on SO regarding how to get the number of rows returned when running a SELECT query using PDO. While most (including the PHP manual) suggest using two queries, with the first running COUNT() , I haven't seen one that suggested how to easily do this using prepared statements with WHERE clauses. How do I most-efficiently (both in processing and number of lines of code) run a COUNT() using the same WHERE clause? The prepared query already has the columns specified.

SET NOCOUNT OFF or RETURN @@ROWCOUNT?

为君一笑 提交于 2019-12-05 13:25:09
问题 I am creating a stored procedure in Sql Server 2008 database. I want to return the number of rows affected. Which is a better option SET NOCOUNT OFF or RETURN @@ROWCOUNT? ALTER PROCEDURE [dbo].[MembersActivateAccount] @MemberId uniqueidentifier AS BEGIN -- Should I use this? SET NOCOUNT OFF; UPDATE [dbo].Members SET accountActive = 1 WHERE id = @MemberId; --Or should I SET NOCOUNT ON and use the following line instead? --return @@ROWCOUNT; END I know that both work, but which is a better

How to get row count of ObjectDataSource

天涯浪子 提交于 2019-12-05 03:06:30
Hello you all How can i get row count of ObjectDataSouce ? I use ObjectDataSource and DataList . I want show some thing to the user for example in a label when there are certain row returned by ObjectDataSource . One of situation is when there is no record . Thank you . I was looking for the same answer... Another solution I ended up using is the following: This is found on a .vb file behind an .aspx page. It handles the "selected" event of the datasource. Protected Sub ObjectDataSource1_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs)

Get the Azure table Row count

佐手、 提交于 2019-12-05 00:11:59
问题 I am new to Azure table storage. I want to get the total row count in a table. Currently Iam doing something like this:- public List<T> ReadAll(string partitionKey) { List<T> entities = new List<T>(); TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey.ToLower())); entities = Table.ExecuteQuery(query).ToList(); return entities; } This currently reads through all the table entries. This works ok when it comes

How to get matched Rows from MySQLdb.cursors.Cursor python2.6

元气小坏坏 提交于 2019-12-04 17:17:17
I'm working with python2.6 and MySQLdb. I have a table with this data +----+--------+ | id | status | +----+--------+ | 1 | A | | 2 | B | | 3 | B | +----+--------+ I want to do an mysql update like this example: UPDATE my_table SET status = "A" where id in (1,2,3,10001); Query OK, 2 rows affected (0.03 sec) Rows matched: 3 Changed: 2 Warnings: 0 And I need to know if all the ids in the update exits in the database. My idea to get this information was to compare the number of items I tried to update vs the number of matched rows. In the example the numbers are 4 vs 3. The problem is that i don

Number of rows inserted into SQLite db is negative

主宰稳场 提交于 2019-12-04 06:29:48
问题 I'm trying to insert new records into SQLite database from Python code. con = sqlite.connect(connectionString) cur = con.cursor() countOfNewItems = 0 for ... try: con.execute("insert or ignore into items ...") countOfNewItems += cur.rowcount except: cur.close() con.close() print "Error when inserting item '%s' to database." % item exit(1) cur.close() con.commit() con.close() print "%d new items have been inserted." % countOfNewItems My code reports negative number of inserted records (-5141).

SET NOCOUNT OFF or RETURN @@ROWCOUNT?

时间秒杀一切 提交于 2019-12-04 00:32:20
I am creating a stored procedure in Sql Server 2008 database. I want to return the number of rows affected. Which is a better option SET NOCOUNT OFF or RETURN @@ROWCOUNT? ALTER PROCEDURE [dbo].[MembersActivateAccount] @MemberId uniqueidentifier AS BEGIN -- Should I use this? SET NOCOUNT OFF; UPDATE [dbo].Members SET accountActive = 1 WHERE id = @MemberId; --Or should I SET NOCOUNT ON and use the following line instead? --return @@ROWCOUNT; END I know that both work, but which is a better choice and why? After some trying I am coming to a conclusion that SET NOCOUNT is OFF by default inside

Get the Azure table Row count

纵然是瞬间 提交于 2019-12-03 15:55:25
I am new to Azure table storage. I want to get the total row count in a table. Currently Iam doing something like this:- public List<T> ReadAll(string partitionKey) { List<T> entities = new List<T>(); TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey.ToLower())); entities = Table.ExecuteQuery(query).ToList(); return entities; } This currently reads through all the table entries. This works ok when it comes to less records. But I am concerned when the records would increase and this method would be tedious. Is

How do I get row count using the NHibernate QueryOver api?

前提是你 提交于 2019-12-02 21:10:16
I'm using the QueryOver api that is part of NHibernate 3.x. I would like to get a row count, but the method I'm using returns all objects and then gets the count of the collection. Is there a way to just return an integer/long value of the number of rows? I'm currently using: _session.QueryOver<MyObject>().Future().Count() Jim Geurts After a bit of playing around with the api, this will do it: _session.QueryOver<MyObject>() .Select(Projections.RowCount()) .FutureValue<int>() .Value If you don't want to return it as a future, you can just get the SingleOrDefault<int>() instead. Another method

Number of rows inserted into SQLite db is negative

元气小坏坏 提交于 2019-12-02 10:09:01
I'm trying to insert new records into SQLite database from Python code. con = sqlite.connect(connectionString) cur = con.cursor() countOfNewItems = 0 for ... try: con.execute("insert or ignore into items ...") countOfNewItems += cur.rowcount except: cur.close() con.close() print "Error when inserting item '%s' to database." % item exit(1) cur.close() con.commit() con.close() print "%d new items have been inserted." % countOfNewItems My code reports negative number of inserted records (-5141). Because my database was empty, I could find out how many records were inserted via command line select