Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CursorAdapter Issues
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00823597
Message ID:
00823609
Views:
24
This is a Gotcha I discovered in developing my CA VCX Builder. From the comments in my builder:
* * * * * *   S Q L   S E R V E R   G O T C H A   * * * * * *

*!*	If using ADO, there is a problem using a 
*!*	parameterized query on an NCHAR data type. A SelectCmd like
*!*	
*!*	cCustomerID = [M%]
*!*	select * from Customers where CustomerID like ?cCustomerID
*!*	
*!*	will return no records because in the Northwind database where
*!*	this example was tested against, the CustomerID is a NCHAR(5)
*!*	data type. When the SQL is passed to the server, the parameter
*!*	value of 'M%' gets RPADded with spaces to make the paramter 
*!*	value a width to match the field width in the table. In other
*!*	words the values is passed as 'M%   '. This does not happen
*!*	with NVARCHAR datatypes. The workaround is to create your SQL as:
*!*	
*!*	cCustomerID = [M%]
*!*	select * from Customers where CustomerID like RTRIM(?cCustomerID)
If interested, you can get my builder and all the source code including the comments above plus additional comments on the CA from:

http://www.mctweedle.com/downloads/cabuilder.zip


>Form's DataEnvironment has one CursorAdapter. The SelectCMD contains one parameter: e.g.
>
>
SELECT * FROM Customer WHERE FirstName LIKE ?vp_FirstName
>
>I am using SQL Server and FirstName is char(30) field. As per documentation, when I issue CursorFill(), VFP generates ADODB.Command object behind the scene and builds the cursor. I have noticed something strange here. When I set vp_FirstName to '%', it doesn't return all rows. I got the SQL from SQL Profiler which looks like this:
>
>
 exec sp_executesql N'select * FROM Customer WHERE Customer.FirstName LIKE @P1 ', N'@P1 char(30)', '%                             '
>
>
>Notice that it appeneds 29 trailing spaces to the parameter value and that's why it is not working the way I would expect. If I change the Data Type to VARCHAR(30), it works.
>
>Has anyone noticed this too?
Mark McCasland
Midlothian, TX USA
Previous
Reply
Map
View

Click here to load this message in the networking platform