Why not subclass classes\wwSQL.vcx (which I'm sure you are doing already) and add a method "sqlbuildselectstatementfromobject"? Use one of the other sqlbuilds as sample to iterate through object fields.
If you are just passing SQL select string and no object, overwrite the execute method to format lcSQL by calling another method "sqlbuildselectstatementfromstring".
Craig
This would probably work for the Insert and Update calls, but my issue is with the initial Select statement, where I frequently have queries to pull a set of child records like this code sample below.
As you can see, the field list in the Select statement contains lots of refernces to field names, some of which may be reserved words int SQL Server.
Textto lcSql PRETEXT 15 TEXTMERGE NOSHOW Select JobItems.qty,Nvl(parts.part_no, Space(PART_NO_FIELD_SIZE)) as part_no,Nvl(parts.altpartno, Space(ALT_PART_NO_FIELD_SIZE)) as altpartno, JobItems.dwg_no,Nvl(parts.desc, JobItems.desc) as Desc, JobItems.price, JobItems.qty * JobItems.price as Total, JobItems.taxable, JobItems.qty_ship, JobItems.qty_billed, JobItems.<this.cFkField>, JobItems.item, JobItems.job_num, JobItems.id, JobItems.part_id, JobItems.quoteitem_idFrom<This.cFilename> JobItemsLeft Outer Join Parts On<This.cFilename>.part_id = Parts.id Where <this.cWhereClause><this.cOrderBy>EndText lnReturn = This.Query(lcSql)
Why not subclass and modify the two methods (sqlbuildinsertstatementfromobject and sqlbuildupdatestatementfromobject) on the ww business class to add the [] bracket's around the field names?
This is very non-trivial because of the complexity of SQL. How would you know, what's a field or a literal? I wouldn't trust an automated process for this to be honest - it probably would introduce more errors than it prevents.
+++ Rick ---
Why?
I have field names in my tables that are reserved words. This was not a problem with DBF Selects, but is proving to be as I move to Sql Server with the same data tables.
Example: an integer field named "order"
Others too.
So, wrapping each field would just be a safety net.
Mike,
brackets are needed when sending names with spaces in them (which generally is a bad idead IMHO). It is good practice to do it but nobody ever does unless the code is generated.
Matt, agree with Mike though - why do you need this? It's unlikely that there's a real need for the brackets?
+++ Rick ---
Matt,
I don't your your specific need but... in general... You don't need those brackets just because you are sending to SQL Server. If you are using wwBusiness and have it properly setup to connect to SQL Server then you can send your "For Instance" query directly to the Query function of a wwBusiness subclass and it should return your cursor.
I am using wwBusiness to execute Select statements against SQL Server. I have tons of Select statements in my app from the time where it ran against FoxPro DBFs, but now I need these Sql Statements to run against SQL Server. I'm hoping someone has written a helpful function that would add brackets around all the table and field name in the query string.
Does anyone know of a custom FoxPro procedure or regex that will automatically add brackets around all the table and field names in a SQL Select statement string?
For instance:
Select mach_name, mach_num, orderFrom Machines Whereorder< 100
Needs to become:
Select [mach_name], [mach_num], [order] From [Machines] Where [order] < 100
I also have Joins, Order By, and Group By clauses in some of the Select statements that I need to get cleaned up as well.
I'm trying to avoid adding brackets manually, because for a while the SQL statements still need to run against DBFs tables, so I if add them now, it will break the DBF version of the app. I know there are other VFP vs. Sql Server issues that I must address, but this is the biggest one I am facing now.