Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WRONG way: SQL Select in VB - use METHOD!
Message
General information
Forum:
Visual FoxPro
Category:
VFPX/Sedna
Title:
WRONG way: SQL Select in VB - use METHOD!
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01069681
Message ID:
01069681
Views:
59
Hey there!
After watching Jim Gray´s PASS 05 keynote the other day I still think LINQ is one of the best inventions since Fox < g >, but all of a sudden it seems the wrong way round:

They´re trying to mimic the SQL Select syntax - closer in VB, or not as close in C# (FROM .. SELECT) - where people rub against.

I think what they really should try is to more objectify the whole db thing. I.e., Select, Insert,.. METHODs - and NOT go the T-SQL way.

AFAIK for DLINQ they´re modelling a class after the db structure. Are they jeopardizing their own venture into the OO world by stopping short and going the T-SQL way the other half?

With these thoughts in mind I took Craig Boyd´s quick and dirty take on LINQ and turned and twisted it (beyond recognition < g >) to what is my understanding after listening to Jim Gray´s speech.

As it seems that we´ll inherit (nice pun) LINQ from VB the one or other way, it´d be good to see it done right.
OTOH the example could suggest the direction how to do LINQ the Fox way.

Hoping for some input
G
CLEAR
PRIVATE loCies

DO CreateCountryCursor && sample data from which to pull our countries

* Fill the loCies Collection
loCies = CREATEOBJECT("collectionq")
SELECT crsCy
SCAN
 loCies.ADD(CREATEOBJECT("Country", ALLTRIM(crsCy.country),;
  ALLTRIM(crsCy.capital), crsCy.population))
ENDSCAN

USE IN SELECT("crsCy") && close it now that we're done

* Query
loCies.QWhere = [U] &&actually something like [cName = "U"]
loCies.QInto = [crsCW] &&actually [CURSOR crsCW] - don´t want to parse
loCies.Select
BROWSE 

* record
DEFINE CLASS country AS CUSTOM
 cName = ""
 capital = ""
 population = 0
 PROCEDURE INIT (tcName, tcCapital, tnPopulation)
  WITH THIS
   .cName = tcName
   .capital = tcCapital
   .population = tnPopulation
  ENDWITH
 ENDPROC
ENDDEFINE

************************************
* subclass - no direct class extension in VFP
************************************
DEFINE CLASS collectionq AS COLLECTION
*query parameters as properties grouped by the Q-prefix
 QSelect = "*"
 QFrom = ""
 QInto = ""
 QWhere = ""
 QGroupBy = ""
 QOrderBy = ""
 QSet = "" &¶meter for Update()
 
 PROCEDURE Select
* BEGIN I´m not going to implement this generalized
  CREATE CURSOR (this.QInto) (country c(21), capital c(19))
  FOR EACH oCW IN this 
   IF oCW.cName = this.QWhere
    INSERT INTO (this.QInto) (country, capital) VALUES (oCW.cName, oCW.capital)
   ENDIF 
  ENDFOR
* END I´m not going to implement this generalized - you get the idea
 ENDPROC
 
 PROCEDURE Insert &&synonymous for ADD()
*...
 ENDPROC 

 PROCEDURE Update &&synonymous for ADD()
*...
 ENDPROC 

 PROCEDURE Delete &&synonymous for REMOVE()
*...
 ENDPROC 
ENDDEFINE

* data courtesy Craig Boyd
PROCEDURE CreateCountryCursor
 CREATE CURSOR crsCy(country c(21), capital c(19), area I, population I)
 INSERT INTO crsCy(country, capital, area, population) VALUES ("Australia", "Canberra", 7686850, 20090437)
 INSERT INTO crsCy(country, capital, area, population) VALUES ("Austria", "Vienna", 83858, 8184691)
 INSERT INTO crsCy(country, capital, area, population) VALUES ("United Kingdom", "London", 244820, 60441457)
 INSERT INTO crsCy(country, capital, area, population) VALUES ("United States", "Washington, D.C.", 9629091, 295734134)
 INSERT INTO crsCy(country, capital, area, population) VALUES ("Zimbabwe", "Harare", 390580, 12746990)
ENDPROC
Next
Reply
Map
View

Click here to load this message in the networking platform