SQLEXEC(), returning varchar fields as character.

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
jawed4
Posts: 2
Joined: Fri Nov 19, 2021 2:51 pm

SQLEXEC(), returning varchar fields as character.

Post 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.
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

SQLEXEC(), returning varchar fields as character.

Post 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.
User avatar
xinjie
Posts: 9
Joined: Wed May 20, 2020 10:05 am

SQLEXEC(), returning varchar fields as character.

Post by xinjie »

You only need to pay attention to the Format property of the control that binds the data source:F
jawed4
Posts: 2
Joined: Fri Nov 19, 2021 2:51 pm

SQLEXEC(), returning varchar fields as character.

Post 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.
Post Reply