8/17/2019 Tehnik Pemrograman VFP & MYSQL
1/63
.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
2/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
3/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
4/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
5/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
6/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
7/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
8/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
9/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
10/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
11/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
12/63
Halaman 9 hingga 10 tidak ditampilkan dalam pratinjau ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
13/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
14/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
15/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
16/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
17/63
Halaman 13 hingga 140 tidak ditampilkan dalam pratinjau ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
18/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
19/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
20/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
21/63
Halaman 144 bukan bagian dari pratinjau buku ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
22/63
Halaman 146 bukan bagian dari pratinjau buku ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
23/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
24/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
25/63
Halaman 149 hingga 153 tidak ditampilkan dalam pratinjau ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
26/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
27/63
Halaman 157 bukan bagian dari pratinjau buku ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
28/63
Halaman 155 bukan bagian dari pratinjau buku ini.
8/17/2019 Tehnik Pemrograman VFP & MYSQL
29/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
30/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
31/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
32/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
33/63
8/17/2019 Tehnik Pemrograman VFP & MYSQL
34/63
How to Connect to a SQL Server from Visual FoxPro (Page 1 of 2 )
In Microsoft public newsgroups, I've noticed a recent increase in the number of questions
that deal with how to connect from Visual Foxpro to SQ Server, and the problems related to
ma!ing this connection" So I've decided to write this article to cover such an importanttopic"
#here are two functions that can be used to establish a connection with the a remote SQ
Server from Visual Fox$ro%
• SQ&onnect( • SQString&onnect(
The SQLConnect() Function
#here are two wa)s to use the SQ&onnect( function to connect to a remote data source,
such as SQ Server" #he first requires that )ou suppl) the name of a data source as definedin the *+& +ata Source -dministrator applet of the &ontrol $anel"
#he following example creates a connection to a remote server using the *+&.orthwind+S.%
*&- h&onn
h&onn / SQ&onnect0*+&.orthwind0, 0sa0, 00(
#he second wa) to use SQ&onnect( is to suppl) the name of a Visual Fox$ro connection
that was created using the create connection command" #he &12-#2 &*..2I*.command stores the metadata that Visual Fox$ro needs to connect to a remote data source"
#he following example creates a Visual Fox$ro connection named .orthwind and thenconnects to the database described b) the connection%
*&- h&onn
&12-#2 +-#--S2 cstemp&12-#2 &*..2I*. .orthwind 3
+-#-S*41&2 0*+&.orthwind0 3
4S21I+ 0sa0 3$-SS5*1+ 00
h&onn / SQ&onnect0.orthwind0(
SQLStringConnect() Function
#he other function that can be used to establish a connection to a remote data source, suchas SQ Server, is SQString&onnect(" 4nli!e SQ&onnect(, SQString&onnect( requires a
single parameter, a string of semicolon6delimited options that describes the remote datasource and optional connections settings"
#he valid options are determined b) the requirements of the *+& driver" Specific
requirements for each *+& driver can be found in that *+& driver's documentation"
8/17/2019 Tehnik Pemrograman VFP & MYSQL
35/63
#he following table lists some commonl) used connection string options for SQ Server%
Option Description
+S. 1eferences an *+& +S."
+riverSpecifies the name of the
*+& driver to use"
ServerSpecifies the name of the SQ
Server to connect to"
4I+Specifies the login I+ or
username"
$5+Specifies the password for the
given login I+ or username"
+atabaseSpecifies the initial database
to connect to"
-$$
Specifies the name of the
application ma!ing theconnection"
5SI+#he name of the wor!stationma!ing the connection"
#rusted7&onnectionSpecifies whether the login isbeing validated b) the
5indows .# +omain"
.ot all of the options listed in the above table have to be used for each connection"
For instance, if )ou specif) the #rusted7&onnection option and connect to SQ Server using.# -uthentication, there is no reason to use the 4I+ and $5+ options since SQ Server
would invariabl) ignore them" #he following code demonstrates some examples of using
SQString&onnect("
Note: 8ou can use the name of )our server instead of the string"
SQ Server 9::: code example%
*&- h&onn
h&onn / SQString&onnect0+river/SQ Server3Server/;SQ9:::2*?( function"
8/17/2019 Tehnik Pemrograman VFP & MYSQL
36/63
Visual Fox$ro returns error @A9B for all errors against a remote data source" #he fifthelement of the arra) returned b) -211*1( contains the remote data source6specific error"
Cdefine M7*D4##*. :
Cdefine M7S#*$SI>.I&*. @B*&- h&onn
h&onn / SQ&onnect0*+&.orthwind0, 0falseuser0, 00(IF h&onn ; :(*&- -11-8 la2rrorE@
-211*1la2rror(M2SS->2*? 3
la2rrorE9, 3M7*D4##*. = M7S#*$SI>.I&*., 3
02rror 0 = #1-.SF*1Mla2rrorEA((2.+IF
Disconnecting From SQL Serer
It is ver) important that a connection be released when it is no longer needed b) theapplication because connections consume valuable resources on the server, and the numberof connections ma) be limited b) licensing constraints"
8ou brea! the connection to the remote data source using the SQ+isconnect( function"SQ+isconnect( ta!es one parameter, the connection handle created b) a call to either
SQ&onnect( or SQString&onnect(" SQ+isconnect( returns a @ if the connection wascorrectl) terminated and a negative value if an error occurred"
#he following example establishes a connection to SQ Server, and then drops theconnection%
*&- h&onn,ln1esultGh&onn / SQString&onnect0+river/SQ Server3Server/;SQ9:::2*?0&onnection has done0(
ln1esult / SQ+isconnecth&onn(IF ln1esult ; :
M2SS->2*?0+isconnect failed0(
2.+IF HH ln1esult ; :2.+IF HH h&onn < :
If the parameter supplied to SQ+isconnect( is not a valid connection handle, Visual Fox$ro
will return a run6time error C@BB(" &urrentl) there is no wa) to determine whether aconnection handle is valid without attempting to use it"
#o disconnect all SQ pass through connections, )ou can pass a value of Jero toSQ+isconnect("
8/17/2019 Tehnik Pemrograman VFP & MYSQL
37/63
#o establish the connection with the remote server )ou can use one of two functions
SQ&onnect( *1 SQString&onnect( and there are two wa)s to use the SQ&onnect(function to connect to a remote data source" #he first requires that )ou suppl) the name of
a data source as defined in the *+& +ata Source -dministrator applet of the control paneland the second wa) to use SQ&onnect( is to suppl) the name of a Visual Fox$ro
connection that was created using the create connection command"
#he other function is SQString&onnect( requires a single parameter, a string of semicolon6delimited options that describes the remote data source and optional connections settings"
5e have to !now that both the SQ&onnect( and SQString&onnect( functions return aconnection handle" #o brea! the connection to the remote data source is b) using the
SQ+isconnect( function"
8/17/2019 Tehnik Pemrograman VFP & MYSQL
38/63
Integrating SQL Server with Visual FOXPRO
Integrating SQL Server with Visual FoxPro
Updated !ul" 1#$ 2%%1
&" 'oert reen
Introuction
*our good friends on the Visual FoxPro tea+ at ,i-rosoft spent a great deal of ti+e to +a.eVisual FoxPro a roust and powerful front/end for -lient/server appli-ations0 'e+ote views and
SQL pass/through provide powerful tools to ta.e advantage of SQL a-./ends su-h as ra-le
and SQL Server via &3 (pen ataase 3onne-tivit")0
ne of the great truis+s of appli-ation develop+ent is that there are +an" wa"s to do
ever"thing0 ne of the hardest things to do when uilding an appli-ation is to de-ide on anapproa-h and to .now if it is etter than the other approa-hes0 In -lient/server develop+ent this
is -o+pounded " the fa-t that "ou are dealing with two dataase engines$ Visual FoxPro on thefront/end and a ver" powerful SQL dataase engine on the a-./end0
4his session will explore two approa-hes to uilding -lient/server appli-ations re+ote views and
SQL pass/through0 *ou will see so+e of the pros and -ons of ea-h approa-h0 f -ourse$ the est
solution will var" fro+ appli-ation to appli-ation ut after "ou see the exa+ples here "ou willhave a etter feel for the strengths of these two +ethods and how "ou would use the+ to uild
-lient/server appli-ations0
!he Sam"le #ata
4he data used in this session5s exa+ples is fro+ a SQL Server 607 ased lirar" appli-ation0 4helirar" wants to .eep tra-. of its +e+ers$ its oo.s and its loans0 4he lirar" dataase s-he+a is
shown in Figure 10
http://technet.microsoft.com/en-us/library/Cc966498.sqlfox1_big%28en-us,TechNet.10%29.gif
8/17/2019 Tehnik Pemrograman VFP & MYSQL
39/63
Figure $% Li&rar' #ata&ase Schema
!a&le Structures
ne of the -entral tales in the Lirar" appli-ation is the ,e+er tale$ whi-h -ontains one row
for ever" +e+er of the lirar"0 8n interesting twist here is that 9uveniles -an onl" e +e+ersof the lirar" if the" have a sponsoring adult0 Sin-e a 9uvenile lives$ presu+al"$ in the sa+e
pla-e as the adult there are separate tales for 8dult and !uvenile0 4his saves dis. spa-e e-ause
all of a 9uvenile5s address infor+ation is redundant on-e "ou .now who the adult is0 8lso$ the 9uvenile5s expiration date is the sa+e as the adult5s0 Further$ "ou don5t -are aout the adult5s irth
date although "ou do -are aout a 9uvenile5s irth date$ ut onl" e-ause on their 1:th irthda" he
or she e-o+es an adult (at least as far as the tales are -on-erned;)0
4he following -ode shows the SQL Server state+ents used to -reate the ,e+er$ 8dult and!uvenile tales
CREATE TABLE member ( member_no member_no NOT NULL IDENTITY(1,1), lastname shortstrin NOT NULL , !irstname shortstrin NOT NULL , mi""leinitial letter NULL , #hotora#h imae NULL )CREATE TABLE a"$lt ( member_no member_no NOT NULL , street shortstrin NOT NULL , %it& shortstrin NOT NULL , state state%o"e NOT NULL , 'i# 'i#%o"e NOT NULL , #hone_no #honen$mber NULL , e#r_"ate "atetime NOT NULL )
CREATE TABLE $*enile ( member_no member_no NOT NULL , a"$lt_member_no member_no NOT NULL , birth_"ate "atetime NOT NULL )
4he +e+er>Identit" -ontains the auto+ati-all" generated +e+erIdentit"0
8/17/2019 Tehnik Pemrograman VFP & MYSQL
40/63
#eclarative Referential Integrit'
In prior versions of SQL Server referential integrit" was enfor-ed through the use of triggers$
whi-h is the sa+e wa" Visual FoxPro enfor-es referential integrit"0 SQL Server 60% added
de-larative referential integrit"$ whi-h allows "ou to define "our 'I rules as part of the datastru-ture0 4he first step is to -reate a Pri+ar" ?e" -onstraint in ea-h tale$ as shown in the
following -ode
ALTER TABLE member ADD CON+TRAINT member_i"ent RI-ARY .EY CLU+TERED
(member_no)ALTER TABLE a"$lt ADD CON+TRAINT a"$lt_i"ent RI-ARY .EY CLU+TERED (member_no)ALTER TABLE $*enile ADD CON+TRAINT $*enile_i"ent RI-ARY .EY CLU+TERED
(member_no)
4he Pri+ar" ?e" -onstraint -reates a Uni@ue index$ whi-h enfor-es the uni@ueness of the
+e+er
8/17/2019 Tehnik Pemrograman VFP & MYSQL
41/63
!he Views
In the Lirar" dataase (the Visual FoxPro version) "ou will find the re+ote views
v8dult,e+er and v!uvenile,e+er0 4he following shows the SQL state+ents that define thetwo views
SELECT Member.member_no, Member.lastname, Member.firstname, ; Member.middleinitial, Adult.street, Adult.city, ; Adult.state, Adult.zip, Adult.phone_no, Adult.epr_date ;!"#M dbo.adult Adult, dbo.member Member ;$%E"E Adult.member_no & Member.member_no ; A'( Member.member_no & )nMember*( SELECT Member.member_no, Member.lastname, Member.firstname, ; Member.middleinitial, +uenile.adult_member_no, ; +uenile.birth_date, Adult.street, Adult.city, Adult.state, ; Adult.zip, Adult.phone_no, Adult.epr_date ;!"#M dbo.adult Adult, dbo.-uenile +uenile, ; dbo.member Member ;$%E"E Adult.member_no & +uenile.adult_member_no ;
A'( +uenile.member_no & Member.member_no ; A'( Member.member_no & )nMember*(
4he two views are ver" straightforward0 4he +e+er5s na+e is in the ,e+er tale and the
address is in 8dult0 8 9uvenile5s irth date and sponsoring adult -an e found in the !uvenile
tale0 &oth views are ased on the sa+e -onne-tion and are +ade +odifiale " identif"ing the
pri+ar" .e" in ea-h tale and " +ar.ing the other fields as updatale0 4his o--urs in the Update3riteria ta in the View esigner0
Loaing the Form
4he for+ ,B,&VIB=0S3C uses these two views0 4he following -ode is the for+5s Load+ethod0 4he for+ -o+es up with no data loaded e-ause the two views are opened with the Doata option0 pti+isti- row uffering is then set for the view -ursors0
#pen (atabase library se AdultMember *n / 'o(ata& CursorSet0rop123ufferin42, (3_3!#0T"EC#"(, ; 2AdultMember25se +uenileMember *n / 'o(ata& CursorSet0rop123ufferin42, (3_3!#0T"EC#"(, ; 2+uenileMember25
Locating a +em&er
4he user -an enter a +e+er5s I and press the Lo-ate utton0 4his supplies a value for the
n,e+erI para+eter and the view is re@ueried0 4he following -ode is in the 3li-. event of the
Lo-ate utton
8/17/2019 Tehnik Pemrograman VFP & MYSQL
42/63
nMember*( & 6al1This!orm.ttMember*(.6alue5Select AdultMember & "e7uery15*f "ecCount12AdultMember25 & / Select +uenileMember & "e7uery15 *f "ecCount12+uenileMember25 & / lcMessa4e & 2There is no member 8ith this *(.2 & Messa4e3o1lcMessa4e , M3_*C#'*'!#"MAT*#'59code intentionally left out:
4he -ode first -he-.s to see if the user had +ade -hanges0 It then stores the entered I to then,e+erI variale0 4he 8dult view is re@ueried first0 If no re-ord is found with that I the
!uvenile view is re@ueried0 If no re-ord is found with that I then the I is not valid0 If the
+e+er is found the infor+ation is displa"ed on the for+0
*ing a +em&er
=hen the user presses the 8dd utton he or she is presented with an e+pt" for+0 4he re-ord isnot a-tuall" saved until the Save utton is pressed0 4he 3li-. event -ode of the 8dd utton first
-he-.s to see if the user has +ade -hanges to the -urrent +e+er re-ord0 4ale'evert() is issued
on the view that is not in use to +a.e sure Visual FoxPro does not thin. -hanges are pending inthat view0 8 lan. re-ord is then added to the view in use and the for+ is refreshed0 4he user
enters the new +e+er5s infor+ation in the lan. re-ord0 =hen the user presses Save$ Visual
FoxPro will send the new re-ord to SQL Server0
Saving Changes
ne of the ni-e features of views is that dealing with the a-./end is handled for "ou0 4he
4aleUpdate() fun-tion is used to save -hanges to the view5s underl"ing tale(s)0 Visual FoxProhandles this auto+ati-all"0 4he following -ode is in the 3li-. event of the Save utton
I! TableU#"ate() 2 -essaeBo(l%-essae, -B_ICONIN0OR-ATION)Else This0orm3+ho4ErrorEn"i!
4he v8dult,e+er or v!uvenile,e+er view is sele-ted$ depending on whether the -urrent
+e+er is an adult or a 9uvenile0 8 4aleUpdate() is then issued0 If it wor.ed$ the data was
saved0 If it didn5t$ the user is shown what the prole+ is0
Doti-e that e-ause this -ode uses 4aleUpdate()$ it handles oth adding new +e+ers and+a.ing -hanges to existing +e+ers0
#eleting a +em&er
4o delete a row on the a-./end it +erel" needs to e deleted in the view0 4he following -ode is
in the 3li-. event of the elete utton
8/17/2019 Tehnik Pemrograman VFP & MYSQL
43/63
+ele%t (This0orm3%5ie4InUse)DeleteI! TableU#"ate() 2 -essaeBo(6This member has been "elete"36, 7 -B_ICONIN0OR-ATION) A##en" Blan/8%o"e intentionall& le!t o$t9Else This0orm3+ho4Error 2TableRe*ert()En"i!
8fter the user is as.ed to -onfir+ the deletion the appropriate view is sele-ted$ the re-ord isdeleted fro+ the view and 4aleUpdate() is issued0 If it wor.s$ the re-ord is gone on the a-./
end0 If it doesn5t$ the user is shown what went wrong0
Issues
Isn5t Visual FoxPro wonderfulE ow eas" -an -lient/server e$ "ou as.E 4his for+ is elegantl"si+ple and eas" to use0 4here are onl" three prole+s with it0
,ou can-t a new mem&ers
4o test this$ press the 8dd utton$ add a new +e+er and press Save0 8fter a s+all pause "ou
will see the +essage shown in Figure 20
Figure .% /rror +essage *fter *ing a +em&er
=hen the 8dd utton was pressed$ a lan. re-ord was appended to the v8dult,e+er view
-ursor0 4his view is +ade up of two tales$ 8dult and ,e+er0 =hen the Save utton is pressed$Visual FoxPro sends the na+e infor+ation to the ,e+er tale0 SQL Server auto+ati-all"
supplies the +e+er I0 So far so good0 Visual FoxPro also sends the address infor+ation to the
8dult tale0 &ut it doesn5t send an"thing for the +e+er5s I0 4hat -olu+n is left e+pt"$ whi-h is
invalid and -auses the 4aleUpdate() to fail0
For this to wor.$ the new row needs to e added to the ,e+er tale first and the resulting I
needs to e put into the 8dult tale along with the address infor+ation0 4here is no reason to
thin. that Visual FoxPro view .nows this0 ow -ould itE Visual FoxPro doesn5t .now what theI is and wouldn5t .now to send it in the 8dult tale an"wa"0
,ou can-t elete mem&ers
http://technet.microsoft.com/en-us/library/Cc966498.sqlfox2_big%28en-us,TechNet.10%29.gif
8/17/2019 Tehnik Pemrograman VFP & MYSQL
44/63
In the Lirar" dataase (the SQL Server version) there is referential integrit" defined etween
the 8dult and !uvenile tales and etween the ,e+er and Loan tales0 *ou -an not delete a
+e+er if he or she is an adult responsile for 9uvenile +e+ers or if he or she has outstandingloans0 *ou would expe-t SQL Server to re9e-t the deletion and send a-. an error0
owever$ "ou should e ale to delete a +e+er if he or she has no asso-iated 9uveniles and nooutstanding loans0 4r" this and "ou will see the error +essage shown in Figure G0
Figure 0% /rror +essage *fter #eleting a +em&er
4his error$ on-e "ou de-ipher the SQL Server language$ tells "ou that "ou have violatedreferential integrit" etween the 8dult and ,e+er tales0 4his will happen if "ou tr" to deletethe ,e+er row efore "ou delete the 8dult row0 4his oviousl" is what the view is doing0 For
the delete to wor. the row has to e deleted fro+ 8dult first and then fro+ ,e+er0 &ut again$
how is Visual FoxPro supposed to .now thatE
!he error messages are incom"rehensi&le
If "ou tr" to delete a +e+er with 9uveniles "ou will e stopped0 If "ou tr" to delete a +e+er
with loans "ou will e stopped0 owever$ SQL Server will send a-. to Visual FoxPro an error
+essage with language si+ilar to the one in Figure G0 4his is totall" in-o+prehensile to the
user0
3onsider another exa+ple0 4he 8dult tale has the following 3he-. -onstraint defined
ALTER TABLE a"$lt :IT; NOC;EC. ADD CON+TRAINT #hone_no_r$le C;EC. (#hone_no LI.E
?)@>@>@>@>@>@>@>
8/17/2019 Tehnik Pemrograman VFP & MYSQL
45/63
(sing Views ) *ttem"t .
So are views useless in this situationE Should "ou give up on the+E Dot without at least one
+ore atte+pt0 4he prole+ aove is that the views are +ade up of two tales and "ou have no-ontrol over how Visual FoxPro tries to insert or update rows0 4here are spe-ifi- rules "ou have
to follow ased on the Lirar" dataase s-he+a ut "ou -an5t +a.e the views ehave0
8s an alternative approa-h$ the for+ ,B,&VB=20S3C uses three views instead of two0 4he
views v,e+er4ale$ v8dult4ale and v!uvenile4ale are all ased on a single SQL Servertale0
Loaing the Form
4he for+ still -o+es up with no data loaded0 8ll three views are opened with the Doata option
and opti+isti- row uffering is then set for the+0
4he three views are all ased on the sa+e shared -onne-tion0 4he 3onne-tandle propert" ofan" of the views stores the -onne-tion handle used " the views0 4his handle will e used
shortl"0
:hat is the %onne%tion han"le $se" b& the *ie4sThis0orm3n;an"le 2 C$rsoretro#(6Conne%t;an"le6, 7 6*-emberTable6)
Locating a +em&er
=hen the user wants to see a new +e+er5s infor+ation he or she will still provide a +e+er I
and press Lo-ate0 4he -ode in this for+ differs slightl" fro+ the previous version in that the
,e+er view is re@ueried first0 If no re-ord is found then "ou i++ediatel" .now the I is notvalid0 4he 8dult view is re@ueried next0 If no re-ord is found then the +e+er +ust e a
9uvenile0
Saving Changes
In the previous version of the for+ a si+ple 4aleUpdate() was issued when the user pressedSave0 8s "ou saw$ that is insuffi-ient given the tale stru-tures0 4his version of the for+ ta.es a
+ore -o+pli-ated ut ulti+atel" +u-h +ore su--essful approa-h0 If the user is -urrentl" adding
a re-ord the first half of Save utton5s 3li-. event -ode will e run0
I! This0orm3lA""-o"e 2 3T3 :ait :in"o4 6+a*in ne4 member in!ormation3336 No:ait
4he -ode adds the new +e+er to the ,e+er tale first0 8 row will then e added to the 8dult
tale0 &oth rows should e added or neither should e added0 4herefore a transa-tion has to e
started0 4he 4ransa-tions propert" of a -onne-tion is used to -ontrol transa-tion pro-essing0 Inthe for+5s Load +ethod the view5s -onne-tion handle was stored to the for+ propert" nandle0
SQLSetProp() is then used to start a transa-tion0
8/17/2019 Tehnik Pemrograman VFP & MYSQL
46/63
Bein a transa%tion 2 +FL+etro#(This0orm3n;an"le, 6Transa%tions6, =)
4he v,e+er4ale view is then sele-ted and a 4aleUpdate() is issued0 If it wor.s the new+e+er5s na+e infor+ation will have een added to the ,e+er tale0 In addition the +e+er
will have a +e+er I0 If the 4aleUpdate() failed the user should see what happened and the
transa-tion is rolled a-. using the SQL'olla-.() fun-tion0
A"" the ne4 member to the member table +ele%t *-emberTable I! Not TableU#"ate() This0orm3+ho4Error Rollba%/ the transa%tion 2 +FLRollba%/(This0orm3n;an"le) Ret$rn En"i!
If the 4aleUpdate() wor.ed then the new row +ade it into the ,e+er tale0 4he next step is to
find out what +e+er I was assigned0 SQLBxe-() is used to send a Sele-t state+ent to SQLServer0 4his Sele-t retrieves the value of >>Identit"$ whi-h stores the last Identit" value
inserted into a tale0 In this -ase that will e the +e+er I0 SQLBxe-() uses the sa+e
-onne-tion handle the views use0 4his is effi-ient e-ause it doesn5t re@uire another -onne-tion toSQL Server0
0in" o$t the member_no o! the ne4 member I! +FLEe%(This0orm3n;an"le, 6+ele%t GGi"entit&6)8 >8%o"e intentionall& le!t o$t9
4he +e+er>Identit"0 4hisenfor-es the relationship etween ,e+er and 8dult0 Dote that this involves -hanging the
pri+ar" .e" of the 8dult tale0 4here is no other -hoi-e0 4he expiration date for this +e+er isset to one "ear fro+ toda" and 4aleUpdate() is issued to save this infor+ation to the 8dult tale0If it doesn5t wor. the transa-tion is rolled a-.0 4his would re+ove the row fro+ the ,e+er
tale0
A"" the ne4 member to the a"$lt table +ele%t *A"$ltTable The member_no is the #rimar& /e& b$t it is $#"atable in the *ie4 !or $st this *er& reason3 The e#iration "ate is one &ear !rom to"a&3 Re#la%e member_no :ith sHlres$lt3e#, 7 e#r_"ate :ith DToT(o-onth(Date(),1=))
I! Not TableU#"ate()8%o"e intentionall& le!t o$t9
If ever"thing wor.ed to this point the transa-tion is -o++itted with the SQL3o++it() fun-tion0If that fails then ever"thing is rolled a-.0
E*er&thin 4or/e" so %ommit the transa%tion3 I! +FLCommit(This0orm3n;an"le) 8 > This0orm3+ho4Error
8/17/2019 Tehnik Pemrograman VFP & MYSQL
47/63
Rollba%/ the transa%tion 2 +FLRollba%/(This0orm3n;an"le) Else8%o"e intentionall& le!t o$t9
If the user is not adding a new +e+er the -ode is so+ewhat si+pler0 8 transa-tion is still
started0 4he infor+ation in the ,e+er tale is saved first and then the infor+ation in the 8dultand !uvenile tales is saved0 If ever"thing wor.ed the transa-tion is -o++itted0 If not it is all
rolled a-.0
Else :ait :in"o4 6+a*in member in!ormation3336 No:ait Bein a transa%tion 2 +FL+etro#(This0orm3n;an"le, 6Transa%tions6, =) +a*e the in!ormation to the member table +ele%t *-emberTable I! Not TableU#"ate()8%o"e intentionall& le!t o$t9 +a*e the in!ormation to the a"$lt table
+ele%t *A"$ltTable I! Not TableU#"ate()8%o"e intentionall& le!t o$t9 E*er&thin 4or/e" so %ommit the transa%tion3 I! +FLCommit(This0orm3n;an"le) 8 > This0orm3+ho4Error Rollba%/ the transa%tion 2 +FLRollba%/(This0orm3n;an"le) Else 2 -essaeBo(6This member
8/17/2019 Tehnik Pemrograman VFP & MYSQL
48/63
2 +FLRollBa%/(This0orm3n;an"le)8%o"e intentionall& le!t o$t9
If the -orresponding 8dult or !uvenile re-ord has alread" een re+oved "ou -an re+ove the,e+er tale re-ord0 4he elete +a" still fail$ for instan-e if this +e+er has outstanding loans0
In that -ase the transa-tion is rolled a-. and the 8dult or !uvenile re-ord is put a-. into the
relevant tale0
+ele%t *-emberTableDeleteI! Not TableU#"ate() This0orm3+ho4Error Rollba%/ the transa%tion 2 +FLRollBa%/(This0orm3n;an"le)8%o"e intentionall& le!t o$t9
If oth of the 4aleUpdate() fun-tions wor.ed then the transa-tion is -o++itted with theSQL3o++it() fun-tion0 If that doesn5t wor. the transa-tion is rolled a-.0
Issues
4wo of the three prole+s with the first version of the for+ are solved here0 Dew +e+ers -an
e added and +e+ers -an e deleted0 If referential integrit" is violated the deletion will fail0 For exa+ple$ suppose "ou tr" to delete a +e+er who has no asso-iated 9uveniles ut does have
outstanding loans0 *ou will see the error shown in Figure 70
Figure 3% /rror +essage when +em&er with Loans is #elete
So the prole+ of the in-oherent error +essages still re+ains0 *ou -ould write -ode to parse the
error +essages and loo. for -ertain phrases0 *ou -ould then translate the SQL Server +essages
into so+ething a user would want to see0 4his is a lot of wor. and re@uires a thorough fa+iliarit"with SQL Server error +essages0 It also +a.es it @uite diffi-ult to port "our appli-ation to other
a-./end dataases$ for exa+ple ra-le0
(sing SQL "ass)through
4he alternative to using views is to rel" solel" on SQL pass/through0 4his +eans that "ou sendSQL state+ents to the a-./end and expli-itl" tell it what to do0 If "ou want to add a re-ord "ou
send an Insert0 4o save a re-ord "ou send an Update0 4his oviousl" involves +ore wor. than
using views0 It does however allow "ou to e in -o+plete -ontrol over what happens and when ithappens0
Loaing the Form
http://technet.microsoft.com/en-us/library/Cc966498.sqlfox5_big%28en-us,TechNet.10%29.gif
8/17/2019 Tehnik Pemrograman VFP & MYSQL
49/63
4he for+ ,B,&BCB30S3C is the sa+e for+ used aove$ onl" it uses SQL pass/through
instead of views0 4he following -ode is in the for+5s Load +ethod0
O#en Database librar&This0orm3n;an"le 2 +FLConne%t(
8/17/2019 Tehnik Pemrograman VFP & MYSQL
50/63
60rom member, a"$lt, $*enile 6 7 6:here member3member_no 2 $*enile3member_no 6 7 6 An" a"$lt3member_no 2 6 7 6 $*enile3a"$lt_member_no 6 7 6 An" member3member_no 2 6 7 6 AllTrim(This0orm3tt-emberID35al$e)I! +FLEe%(This0orm3n;an"le, l%+FL, 6%_member6) 8 >8%o"e intentionall& le!t o$t9
If the -
8/17/2019 Tehnik Pemrograman VFP & MYSQL
51/63
AllTrim(This0orm3ttLastName35al$e) 7 6 8%o"e intentionall& le!t o$t9nNe4-emberID 2 sHlres$lt3e#
8n Insert is then -onstru-ted to add the new row to the 8dult tale0 4he >>Identit" value fro+the server is used in this Insert to -orre-tl" lin. the 8dult row to the ,e+er row0
A"" the ne4 member to the a"$lt tablel%+FL 2 6Insert a"$lt (member_no, street, %it&, state, 6 7 6'i#, #hone_no, e#r_"ate) 6 7 65al$es (6 AllTrim(+tr(nNe4-emberID)) 6,
8/17/2019 Tehnik Pemrograman VFP & MYSQL
52/63
It is prett" straightforward$ although a it ul."$ to -onstru-t an Update state+ent to send to the
server0 *ou .now the na+es of the tale5s -olu+ns and the values are sitting in -ontrols on the
for+0 *ou -an 9ust uild the Set part of the Update one -olu+n after another0 owever$ "ou wantto e a it +ore -lever than that0 *ou don5t want to waste SQL Server5s ti+e updating a -olu+n
that has not -hanged0 4he -ode here uses the ldVal() fun-tion$ +ade possile " the use of the
uffered -ursor$ to -he-. the value of ea-h field in the -ursor to its original value0 nl" if it has-hanged does it e-o+e part of the Update state+ent0 &" the wa"$ re+ote views do this
auto+ati-all"0
l%+FL 2 66 U#"ate this member in the member tableI! %_member3!irstname 89 Ol"5al(6%_member3!irstname6) l%+FL 2 l%+FL 6!irstname 2 8%o"e intentionall& le!t o$t9
4he sa+e pro-ess as aove then o--urs for the 8dult tale0 4he next part should " now e ver"
fa+iliar0 3o++it if it all wor.ed and rolla-. if it didn5t0
#eleting a +em&er
ne of the enefits of using SQL pass/through rather than re+ote views is that "ou gain -ontrolover what happens and when it happens0 4he -ode run when the user -li-.s the elete utton is a
good exa+ple of this0
4here are various reasons "ou +ight not e ale to delete a +e+er0 If the +e+er has
asso-iated 9uveniles or if the +e+er has outstanding loans an" elete will fail0 *ou -an easil"deter+ine if either of these is true " sending a Sele-t state+ent to the server0 4he -ode here uses
SQLBxe-() to -he-. for oth of these -onditions0 If either is true a user/friendl" +essage is
displa"ed and nothing further happens0
8/17/2019 Tehnik Pemrograman VFP & MYSQL
53/63
0irst %he%/ to see i! this is an a"$lt 4ith a%ti*e $*enilesl%+FL 2 6+ele%t member_no 0rom $*enile 6 7 6:here a"$lt_member_no 2 6 7 This0orm3tt-emberID35al$eI! +FLEe%(This0orm3n;an"le, l%+FL) 8 > This0orm3+ho4Error Ret$rnElse I! Re%Co$nt(6sHlres$lt6) 89 >
l%-essae 2 6This member %an not be "elete"3 6 7 6;eshe is an a"$lt 4ith a%ti*e $*eniles36 2 -essaeBo(l%-essae, -B_ICONIN0OR-ATION) Ret$rn En"i!En"i! No4 %he%/ to see i! this member has a%ti*e loansl%+FL 2 6+ele%t member_no 0rom loan 6 7 6:here member_no 2 6 7 This0orm3tt-emberID35al$e
I! +FLEe%(This0orm3n;an"le, l%+FL) 8 > This0orm3+ho4Error Ret$rnElse I! Re%Co$nt(6sHlres$lt6) 89 >
l%-essae 2 6This member %an not be "elete"3 6 7 6;eshe has a%ti*e loans36 2 -essaeBo(l%-essae, -B_ICONIN0OR-ATION) Ret$rn En"i!En"i!
If there are additional -he-.s that need to e perfor+ed that -ode -an e pla-ed after the -ode
aove0 *ou have -o+plete -ontrol over what "ou -he-. and what order the -he-.s are run0 If allthe -he-.s su--eed and the +e+er -an e deleted a transa-tion is started0
4here are relationships defined etween the ,e+er tale and the Loanhist and 'eservation
tales0 Loanhist -ontains a row for ever" oo. orrowed and returned " the +e+er0 4he'eservation tale -ontains a row for ever" oo. the +e+er has on reserve0 If the +e+er is
deleted the asso-iated infor+ation in those two tales needs to e re+oved0 It needs to deleted
first or else there will e a referential integrit" violation0
Delete the loan histor& re%or"s !or this memberl%+FL 2 6Delete loanhist :here member_no 2 6 7 AllTrim(This0orm3tt-emberID35al$e)I! +FLEe%(This0orm3n;an"le, l%+FL) 8 >8%o"e intentionall& le!t o$t9 Delete the loan reser*ation re%or"s !or this memberl%+FL 2 6Delete reser*ation :here member_no 2 6 7 AllTrim(This0orm3tt-emberID35al$e)I! +FLEe%(This0orm3n;an"le, l%+FL) 8 >8%o"e intentionall& le!t o$t9
8/17/2019 Tehnik Pemrograman VFP & MYSQL
54/63
4o delete an adult +e+er "ou have to delete the row in the 8dult tale first and then "ou -an
delete the row in the ,e+er tale0 4his is still part of the transa-tion so if an"thing goes wrong
ever"thing is rolled a-.0
Delete the memberl%+FL 2 6Delete a"$lt :here member_no 2 6 7
AllTrim(This0orm3tt-emberID35al$e)I! +FLEe%(This0orm3n;an"le, l%+FL) 8 >8%o"e intentionall& le!t o$t9l%+FL 2 6Delete member :here member_no 2 6 7 AllTrim(This0orm3tt-emberID35al$e)I! +FLEe%(This0orm3n;an"le, l%+FL) 8 >8%o"e intentionall& le!t o$t9
If all of the eletes wor.ed then the entire transa-tion is -o++itted and the +e+er is re+oved04he user should then e loo.ing at an e+pt" s-reen so a lan. re-ord is added to -
8/17/2019 Tehnik Pemrograman VFP & MYSQL
55/63
On the one han this "rovies less intero"era&ilit'
8 downside to this approa-h is that it sa-rifi-es interoperailit" to a -ertain degree0 4he SQL
state+ents sent to the a-./end via the SQLBxe-() are written in the a-./end5s language0 4heexa+ples here were designed to wor. with SQL Server0 ow +u-h of a rewrite would e
involved to port this appli-ation to ra-leE
It is true that the asi- for+ of a Sele-t$ Insert$ Update or elete doesn5t var" +u-h fro+ a-./
end to a-./end0 So the exa+ple here +ight e easil" ported0 owever$ the point is an i+portantone and depending on the -o+plexit" of the SQL state+ents "ou use "ou +ight li+it "our ailit"
to swap a-./ends0 f -ourse$ if the appli-ation is written for one and onl" one a-./end this
will not e a ig issue0
On the other han this "rovies more intero"era&ilit'
3onsider what happens if "ou are using re+ote views and "ou tr" to delete a +e+er who has
outstanding loans0 'eferential integrit" defined on the server will prevent the deletion0 owever$the error +essage sent a-. " ra-le will differ fro+ the +essage sent a-. " SQL Server0
*ou -ould parse the +essages and translate the+ into a user/friendl" for+ ut "ou will have to parse differentl" for ea-h a-./end0 4his li+its "our interoperailit" e-ause "ou will have to
-reate parsing routines for ea-h server0
=ith the SQL pass/through approa-h "ou would send a Sele-t state+ent to the a-./end loo.ing
for this +e+er in the Loan tale0 If the Sele-t finds a row the +e+er -an5t e deleted0 4he+essage shown to the user is the sa+e regardless of what was sent in the SQLBxe-()0 4his serves
to in-rease "our interoperailit"$ assu+ing that the for+ of the Sele-ts$ Inserts$ Updates and
eletes doesn5t var" greatl" a+ong the various a-./ends$ whi-h is a reasonale assu+ption0
(sing Store Proceures
In the approa-h 9ust reviewed$ the wor. is split etween the -lient and the server0 4he server does
the a-tual data +anipulation$ whi-h involves sear-hing for re-ords and adding$ updating and
deleting re-ords0 owever$ the -lient -ontrols the logi-$ telling the server what to do and whatorder to do it in0
8n alternative approa-h is to let the server not onl" do the wor. ut also -ontrol the logi-0 4his is
a--o+plished " rel"ing on stored pro-edures0 8 stored pro-edure is a pre-o+piled set of SQL
state+ents0 &e-ause the" are pre-o+piled there is a perfor+an-e gain to using the+0 In addition$
the" are essentiall" la-. ox routines0
4he SQLBxe-() fun-tion -an e used to send not onl" SQL state+ents su-h as Insert and Update$
ut also -an e used to tell SQL Server to run a stored pro-edure0 Visual FoxPro tells the server
what stored pro-edure to run ut it doesn5t .now what is in the various pro-edures0 VisualFoxPro onl" .nows$ and in fa-t onl" needs to .now$ whether or not the stored pro-edures
wor.ed0
8/17/2019 Tehnik Pemrograman VFP & MYSQL
56/63
Loaing the Form
4he for+ ,B,&P'30S3C uses stored pro-edures to tal. to SQL Server0 SQLBxe-() is still
used so a -onne-tion to the server needs to e estalished in the Load +ethod of the for+0 4hisalso o--urred in the previous exa+ple and in fa-t the Load +ethod of oth for+s is exa-tl" the
sa+e0
Locating a +em&er
8 SQL Server stored pro-edure -alled et,e+er is used to retrieve infor+ation on a +e+er0
4his stored pro-edure ta.es as a para+eter the I of the +e+er whose infor+ation "ou want04his stored pro-edure is -alled when the user presses the Lo-ate utton0
I! +FLEe%(This0orm3n;an"le, 6Ee%$te et-ember 6 7 This0orm3tt-emberID35al$e, 6%_member6) 8 > This0orm3+ho4Error Ret$rn
En"i!
4he stored pro-edure runs a Sele-t and therefore returns a result set to the -ursor -
8/17/2019 Tehnik Pemrograman VFP & MYSQL
57/63
l%+FL 2 6Ee%$te a""a"$lt 6
8/17/2019 Tehnik Pemrograman VFP & MYSQL
58/63
I0 GGerror M2 > BEIN ROLLBAC. TRAN RAI+ERROR(>Identit"
to the >+e+er>Identit" -reates a result set and that this is
sent a-. to Visual FoxPro0 4his is a happ" -oin-iden-e as this -auses the SQLBxe-() to -reate a
result set -ursor -alled s@lresult0 4he value in the exp field in that -ursor is the value of>>Identit" and is easil" retrieved0
4his is good for another reason0 If "ou waited until the stored pro-edure had run and then used
SQLBxe-() to as. SQL Server for the value of >>Identit" it would -o+e a-. e+pt"0 4his is
e-ause the se-ond thing the stored pro-edure does is insert a row into the 8dult tale$ whi-hdoesn5t have an Identit" -olu+n0 4his -auses the value of >>Identit" to e set to Dull0 So if the
stored pro-edure didn5t send a-. the >>Identit" after the Insert into ,e+er then the
infor+ation would have een lost0
Saving Changes
4he -ode to save a +e+er5s infor+ation is in the for+ +ethod Update,e+er0 4he -ode -allsthe stored pro-edure Update8dult$ whi-h ta.es as para+eters the +e+er I and the na+e and
new value of an" fields that need to e updated0
l%+FL 2 66I! %_member3!irstname 89 Ol"5al(6%_member3!irstname6) l%+FL 2 l%+FL 6 G!irstname 2
8/17/2019 Tehnik Pemrograman VFP & MYSQL
59/63
I! Len(l%+FL) 9 > +tri# o!! the last %omma l%+FL 2 Le!t(l%+FL, Len(l%+FL) =) l%+FL 2 6Ee%$te $#"atea"$lt Gmember_no 2 6 7 AllTrim(This0orm3tt-emberID35al$e) 7 6, 6 l%+FLElse 2 -essaeBo(6There is nothin to sa*e36, 7 -B_ICONIN0OR-ATION) Ret$rnEn"i!I! +FLEe%(This0orm3n;an"le, l%+FL) 8 > This0orm3+ho4Error8%o"e intentionall& le!t o$t9
4he SQL Server -ode used to -reate the Update8dult stored pro-edure is as follows
CREATE ROCEDURE $#"atea"$lt Gmember_no member_no,
Glastname shortstrin 2 NULL, G!irstname shortstrin 2 NULL, Gmi""leinitial letter 2 NULL, Gstreet shortstrin 2 NULL, G%it& shortstrin 2 NULL, Gstate state%o"e 2 NULL, G'i# 'i#%o"e 2 NULL, G#hone_no #honen$mber 2 NULLA+ DECLARE GsHlstrin1 *ar%har(=) DECLARE GsHlstrin= *ar%har(=) I0 Glastname 2 NULL AND G!irstname 2 NULL AND Gmi""leinitial 2 NULL AND Gstreet 2 NULL AND G%it& 2 NULL AND Gstate 2 NULL AND
G'i# 2 NULL AND G#hone_no 2 NULLBEIN
RINT 6Nothin to "o36 RETURN END +ELECT GsHlstrin1 2 NULL +ELECT GsHlstrin= 2 NULL I0 Glastname M2 NULL
+ELECT GsHlstrin1 2 GsHlstrin1 6lastname 2
8/17/2019 Tehnik Pemrograman VFP & MYSQL
60/63
I0 GGerror M2 > BEIN ROLLBAC. TRAN RAI+ERROR( BEIN ROLLBAC. TRAN RAI+ERROR( This0orm3+ho4ErrorElse8%o"e intentionall& le!t o$t9
4he SQL Server -ode to -reate the 'e+ove,e+er stored pro-edure is as follows
CREATE ROCEDURE remo*emember Gmember_no member_no
8/17/2019 Tehnik Pemrograman VFP & MYSQL
61/63
A+I0 NOT EI+T+
(+ELECT 0RO- member :;ERE member_no 2 Gmember_no)BEIN
RINT 6 -ember n$mber not !o$n" in -ember table36 RETURN END I0 EI+T+ (+ELECT member_no 0RO- $*enile :;ERE Gmember_no 2 a"$lt_member_no) BEIN RAI+ERROR(
8/17/2019 Tehnik Pemrograman VFP & MYSQL
62/63
DELETE a"$lt :;ERE member_no 2 Gmember_no I0 GGerror M2 > BEIN
ROLLBAC. TRAN RETURN END END DELETE member :;ERE member_no 2 Gmember_no I0 GGerror M2 > BEIN
ROLLBAC. TRAN RETURN END CO--IT TRAN+ACTION
4his stored pro-edure first -he-.s to see if the +e+er exists0 It then -he-.s to see if this is an
adult with a-tive 9uveniles or a +e+er with outstanding loans0 If so the +e+er -an not e
deleted and the stored pro-edure sends a-. an error and user friendl" +essage0 If the deletion-an o--ur a transa-tion is egun and the +e+er5s infor+ation is re+oved fro+ the Loanhist$
'eservation$ !uvenile$ 8dult and ,e+er tales0 8s alwa"s$ if an"thing goes wrong the wholething is rolled a-.0
Issues
ow does SQL pass/through with hand -rafted SQL state+ents -o+pare to SQL pass/throughwith stored pro-eduresE
!his is less wor2
8ssu+ing the stored pro-edures alread" exist there is +u-h less wor. for the Visual FoxPro
progra++er to do in this s-enario0 8ll "ou need is to .now is whi-h stored pro-edure to -all$what para+eters it ta.es and what it returns0 *ou do not need to .now how the stored pro-edure
wor.s or in what order it does things0
,ou have less control in Visual FoxPro
&e-ause all of "our a--ess to SQL Server o--urs through stored pro-edures "ou have ver" little-ontrol fro+ Visual FoxPro over what happens on the server0 f -ourse$ assu+ing that the stored
pro-edures do what the" are supposed to do$ "ou proal" won5t +ind this0
,ou have more control in SQL Server
If "ou are responsile not onl" for the Visual FoxPro front/end ut also the SQL Server a-./end
then "ou have -ontrol either wa"0 owever$ what if "ou are 9ust writing a Visual FoxPro front/end to SQL Server data and that data is -ontrolled " so+eone elseE Providing a--ess to the data
solel" through stored pro-edures is a great wa" for the owners of the SQL Server data to exer-ise
-ontrol over that data0 4he" -an rest assured that the front/end developers don5t +ess up the data04his would -o+e in extre+el" hand" if there is a Visual FoxPro$ a Visual &asi- and an 8--ess
front/end to the sa+e data0
8/17/2019 Tehnik Pemrograman VFP & MYSQL
63/63
!his "rovies more intero"era&ilit'
&e-ause all the wor. is done in the stored pro-edures it should e ver" eas" to swit-h a-./ends0
8t the worst "ou would have to -hange ea-h line of -ode -ontaining a SQLBxe-() to refle-t adifferent s"ntax for -alling stored pro-edures0
Conclusion
In this session "ou have seen exa+ples of using oth views and SQL pass/through for uilding
-lient/server appli-ations using Visual FoxPro0 4he ovious @uestion is when should "ou use one
or the otherE
Using re+ote views has the enefit of eing relativel" si+ple e-ause Visual FoxPro does a lot
of the wor. for "ou0 *ou -an use standard Visual FoxPro fun-tions su-h as 4aleUpdate() for
data entr"0 FoxPro handles the -o++uni-ations with the a-./end server0 8 downside to using
views is that "ou give up a large degree of -ontrol0
8 parti-ularl" good use of views is for reporting0 4he View esigner is a ver" eas" wa" to
-onstru-t +an" Sele-t state+ents0 It is also a great wa" to -onstru-t heterogenous @ueries$ where
so+e of the data is -o+ing fro+ the a-./end server and so+e is -o+ing fro+ lo-al VisualFoxPro tales$ for instan-e loo.up tales0
Using SQL pass/through and sending SQL state+ents dire-tl" to the a-./end gives "ou total
-ontrol0 *ou -reate the SQL state+ents that get run0 *ou -an still use uffered -ursors and get
+u-h of the -onvenien-e of views0 4he -ost however is the wor. involved in -onstru-ting theSQL state+ents0 3alling stored pro-edures on the a-./end via SQL pass/through greatl"
redu-es the urden of writing SQL state+ents ut also ta.es awa" "our -ontrol of what happens
and when0
4he purpose of this session is not to -onvin-e "ou to use either views or SQL pass/through0'ather$ "ou should -onsider oth of the+ to e powerful tools "ou -an use to uild appli-ations0
If "our data stru-tures and validation re@uire+ents are not -o+plex then "ou should -onsider
using views0 If "ou need +ore -ontrol or views -an5t handle so+ething "ou want to do "oushould -onsider SQL pass/through0 *ou -an also use oth whenever that +a.es sense0