Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select expression for both VFP and SQL DB
Message
 
 
To
29/03/2019 09:15:13
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01667660
Message ID:
01667687
Views:
37
>>Hi,
>>
>>I have an expression that works SQL Server DB:
>>
>>select  CAST(0 AS BIT) AS MYFIELD
>>
>>
>>Of course the above will not work for VFP. Is there a way to change the expression above that it would create a calculated logical field in VFP as well as SQL DB?
>>
>>TIA
>
>For using MS SQL Server and VFP simultaneously for an application I have created a series of wrappers. One of them is GetSQLText, which is called before any command is sent to processing. Its purpose is to preprocess the SQL passed and return an SQL command that is compatible with the backend. In code I separate VFP and SQL specific portions with < VFP > and < SQL > tags:
>
>
>* GetSQLText.prg
>Lparameters tcSQL,tcMode,tlDebug
>
>Local lcLeft,lcRight,lnOccurence
>lcLeft  = Iif(Upper(m.tcMode) = 'SQL', '<VFP>','<SQL>')
>lcRight = Iif(Upper(m.tcMode) = 'SQL', '</VFP>','</SQL>')
>
>For lnOccurence = 1 To Occurs(m.lcLeft,Upper(m.tcSQL))
>	If Atc(m.lcLeft,m.tcSQL) > 0
>		tcSQL = Strtran(m.tcSQL,Strextract(m.tcSQL,m.lcLeft,m.lcRight,1,1+4))
>	Endif
>Endfor
>For lnOccurence = 1 To Occurs(m.lcLeft,Upper(m.tcSQL)) && check against erronous closing tags
>	If Atc(m.lcLeft,m.tcSQL) > 0
>		tcSQL = Strtran(m.tcSQL,Strextract(m.tcSQL,m.lcLeft,m.lcLeft,1,1+4))
>	Endif
>Endfor
>
>
>** Remove tcMode tags
>tcSQL = Strtran(Strtran(m.tcSQL,'<'+m.tcMode+'>','',1,-1,1),'</'+m.tcMode+'>','',1,-1,1)
>** All CRLF to CR
>tcSQL = Chrtran(Strtran(m.tcSQL,Chr(13)+Chr(10),Chr(13)),Chr(10),Chr(13))
>** Eliminate blanklines
>Do While Occurs(Chr(13)+Chr(13),m.tcSQL) > 0
>	tcSQL = Strtran(m.tcSQL,Chr(13)+Chr(13),Chr(13))
>Enddo
>** All CR to CRLF + if mode is VFP: if tlDebug to ' ;'+CRLF else ' '
>tcSQL = Strtran(m.tcSQL,Chr(13),Chr(13)+Chr(10))
>If m.tlDebug
>	_Cliptext = Iif(Upper(m.tcMode) = 'VFP', ;
>		Strtran(m.tcSQL, Chr(13)+Chr(10),' ;'+Chr(13)+Chr(10)), ;
>		m.tcSQL)
>Endif
>If Upper(m.tcMode) = 'VFP'
>	tcSQL = Strtran(m.tcSQL, Chr(13)+Chr(10), ' ')
>Endif
>Return tcSQL
>
>
>
>
>Sample call with your problem:
>
>
>Local lcSQL
>Text to m.lcSQL textmerge noshow
>Select 
>  <VFP>Cast(0 as Logical)</VFP>
>  <SQL>Cast(0 as bit)</SQL> 
>     as myField
>from myTable
>EndText
>
>MessageBox( GetSQLText(m.lcSQL,'VFP'), 0, 'VFP', 10000)
>GetSQLText(m.lcSQL,'VFP', .T.) && copied to clipboard
>MessageBox( _cliptext, 0, 'VFP-Debug mode', 10000)
>MessageBox( GetSQLText(m.lcSQL,'SQL'), 0, 'SQL', 10000)
>
>
>PS: I send all commands to VFP using VFPOLEDB.

Hi Cetin,
Thank you very much for your input and for sharing your code.
I am using a Cursor Adapter in a data-driven mode. All fields that have to be in the SQL Select are in a meta .DBF table. So, for calculated field (like the one I have asked in this thread) I use the "Cast(0 as bit)" in the field_expression column of the DBF. My solution is either not to use the calculated column, when the back end is VFP. Or, add another field to the meta DBF (e.g. VFP_EXPR) and enter the "Cast(0 as Logical" in this field.
Then, when the CA is initialized, both - VFP and SQL - will be covered.
But I have not yet decided what to do for VFP.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform