|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
@@Rowcount in CFQuery in CF8
Code:
<cfquery name="qryTest" datasource="DBTest"> INSERT INTO T_0097878_W (ID,feed_client_id,Account_ID,Contact_ID, Client_Identifier,Data_Partner_ID,Marker) SELECT id, feed_client_id, Account_ID, Contact_ID, Client_Identifier, Data_Partner_ID, Marker FROM T_0097878_R ; SELECT ISNULL(@@ROWCOUNT,0) as rCnt; </cfquery> <cfdump var="#qryTest#"> rCnt is not defined within qryTest. Doing a basic update statement and getting the @@ROWCOUNT makes qryTest undefined. i dont see anything in CF8 docs that would allow me to get the rowcount, nor see anything that would have changed from 6.1 to 8 http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_17.html |
|
#2
|
|||
|
|||
|
In CF8 you can get the inserted key from the result structure:
result_name.IDENTITYCOL SQL Server only. The ID of an inserted row. result_name.ROWID Oracle only. The ID of an inserted row. This is not the primary key of the row, although you can retrieve rows based on this ID. result_name.SYB_IDENTITY Sybase only. The ID of an inserted row. result_name.SERIAL_COL Informix only. The ID of an inserted row. result_name.GENERATED_KEY MySQL only. The ID of an inserted row. MySQL 3 does not support this feature.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
i know that, but i am not trying to get the id of the inserted row.
i want to know how many was inserted (@@ROWCOUNT) this also has affected getting the # of rows affected if i do a basic UPDATE statement the result structure does not seem to give me this information |
|
#4
|
|||
|
|||
|
Ah sorry, I had misread. I don't believe the JDBC drivers allow you to do multiple statements like that without changing the connection strings, which essentially means setting up your own driver and connection.
|
|
#5
|
|||
|
|||
|
Quote:
gay....worked in 6.1 guess ill have to do a workaround |
|
#6
|
|||
|
|||
|
I believe it was a general change to the way all the JDBC drivers were used, due to the rise of SQL injection attacks. It's actaully pretty dangerous to allow this since it becomes so much easier for hackers to sneak extra statements in via URL or FORM variables that are used in the SQL.
|
|
#7
|
|||
|
|||
|
|
|
#8
|
|||||
|
|||||
|
Quote:
i am not sure how he states: Quote:
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_17.html doesn't mention anything of a rows affected attribute in that result struct. there is the recordcount value, which i believe he was tying to use to mimic what I need. i've tried that, with no luck. recordcount=0 even though it may have selected 316 rows. Code:
struct CACHED false EXECUTIONTIME 78 RECORDCOUNT 0 SQL SET NOCOUNT ON INSERT INTO T_0097878_W (ID) SELECT id FROM T_0097878_R SET NOCOUNT OFF though i will say, i ran into this: Code:
<cfquery name="dbQry" datasource="someDS" result="test"> INSERT INTO someTable (ID) VALUES (35) </cfquery> <cfdump var="#test#"> gives me this error: Quote:
|
|
#9
|
|||
|
|||
|
i believe he had his examples backwards.
his example Code:
<cfquery name="create" datasource="#dsn#"> SET NOCOUNT ON INSERT INTO OtherTable ( Title, DateModified ) SELECT Title, DateModified FROM MyTable WHERE MyID = <cfqueryparam value="2" cfsqltype="cf_sql_integer"> SELECT SCOPE_IDENTITY() AS OtherID SET NOCOUNT OFF </cfquery> NOCOUNT: Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results. i switched it around and i got the result i was looking for |
|
#10
|
|||
|
|||
|
Great!
|
|
#11
|
|||
|
|||
|
not sure if this will help anyone, but a co-worker said doing this:
Quote:
also works. stated that coldfusion also sends a sql statement at the end of your query to the sql server (select SCOPE_IDENTITY() AS GENERATED_KEYS), so by putting the SQL comments at the end, it comments that last statement out, and also works. thought i would post it here also just in case it helps anyone. |
|
#12
|
||||
|
||||
|
Quote:
No. Your goal is slightly different than the one described in my entry. However, I suspect the main problem is that you are using a different driver version. If you look at the results the entry, it shows the driver used was the built-in CF8 driver for MS SQL Server. From what you have described, I would guess you are using the MS SQL JDBC 1.2 driver or possibly the JTDS driver. Driver version makes a big difference. The results of certain statements can vary widely depending on which driver you are using. I wrote several entries about it. If you are interested in exactly how different, read my entry titled "CF8 + MS JDBC 1.2 Driver - .. And for my next trick, I will make this query disappear!". (Due to my new user status, I cannot post urls yet) Because of those differences (bugs IMO), the solution in the original entry only applies to the built-in CF8 driver. It will not work with the MS JDBC 1.2 driver. Quote:
Yes. That is why the solution does not work for you. When using the JDBC 1.2 driver (and possibly JTDS), CF is returning the "recordCount" and results from the extra statement and ignoring the rest. If you had dumped the query and "result" structure, you could clearly see the "rCnt" column is nowhere to be seen. Instead it is replaced by GENERATED_KEYS. Dan G. Switzer, II was kind enough to point out this issue a few months ago. I wrote about in "CF8 + MS JDBC 1.2 Driver - Generated key issues. Curiouser and Curiouser". Again, I think this is a bug and have submitted a bug report on this/related issues. In any case, I believe the problem only applies to INSERT statements. It should already work correctly for UPDATE and DELETE statements. So assuming you are using the JDBC 1.2 driver, you can still use cfquery's "result" attribute as kiteless suggested. For INSERT's, eliminate the SELECT @@ROWCOUNT and just add an MS SQL comment "--" to the end of the sql. Once you do that, the "recordCount" from cfquery's "result" attribute will work correctly. Code:
<cfquery name="qry" datasource="#dsn#" result="results"> INSERT INTO T_0097878_W (ID, feed_client_id, ..) SELECT ID, feed_client_id, ... FROM T_0097878_R -- this fixes a bug between CF8 and MS SQL JDBC 1.2 driver </cfquery> <cfoutput>recordcount = #results.recordCount#</cfoutput> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > @@Rowcount in CFQuery in CF8 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|