Page 1 of 1
SQLEXEC(), returning varchar fields as character.
Posted: Fri Nov 19, 2021 3:16 pm
by jawed4
Hello Guys, Need Help.
I am using VFP9 as front end for Sqlserver.
For fetching data and updating I am using SQLEXEC(), but this returning character type of fields instead of varchar type field on backend.
This resulting trailing spaces on backend table. Needing your help.
Not interested in CursorAdapter or Vfp RemoteViews, is there any other way.
Thanks a Lot.
SQLEXEC(), returning varchar fields as character.
Posted: Sat Nov 20, 2021 2:37 am
by kevclark64
I have only used SqlExec with Postgres, not with SQL Server. However, with postgres you set data options like that through the ODBC driver setup.
SQLEXEC(), returning varchar fields as character.
Posted: Sat Nov 20, 2021 12:18 pm
by xinjie
You only need to pay attention to the Format property of the control that binds the data source:F
SQLEXEC(), returning varchar fields as character.
Posted: Sat Nov 20, 2021 3:07 pm
by jawed4
Thanks XINJI, and XSHARP
I tried format as F but this is not working.
Then I found this paragraph by googling and this command is working.
I found the following paragraph
A better solution
VFP 9.0 offers a much better solution. Unlike earlier releases, version 9.0 supports the varchar data type in remote views. If both the RV and back-end fields are varchars, the data will not be padded with spaces, so the problem won't arise.
However, this does not happen automatically. By default, any varchar columns on the back-end will still be mapped to character fields in the view, as in earlier versions. To get the benefits of varchars, you have to explicitly change the data type in the view.
If you are starting a new application and you haven't yet created your remote views, you're in luck. All you have to do is to execute the following command before you create the views:
CURSORSETPROP("MapVarchar", .T., 0)
This tells VFP to map varchars in the view to varchars on the back-end. By passing 0 as the third parameter, you stipulate that this setting will apply to all views created in the session. This only affects new views that you create; any existing views are unaffected. The setting is not persistent, so be sure to execute the above command before you create any views in the current session.