Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Borislav Borissov
  Where is Borislav Borissov?
 Sofia
 Bulgaria
 Borislav Borissov
 To: one delacruz
  
 
 
 one delacruz
 Tags
Subject: RE: evaluate my code
Thread ID: 188822 Message ID: 188830 # Views: 1 # Ratings: 0
Version: Visual FoxPro 6 Category: Databases, Tables and SQL Server
Date: Tuesday, August 12, 2008 9:28:31 AM         
   


> Hi all,
>
> Can someone help me evaluate this?
>
>
> SQLPREPARE( gnhandle, "SELECT * from thetable t WHERE t.checkthis = ?checking and t.checktype = 1", "SQLRESULT" )
> if SQLEXEC( gnhandle ) <> -1
>    if RECCOUNT("SQLRESULT") > 0
>       messagebox ("Not allowed entry")
>       return .F.
>    else
>        exit
>    endif
> endif

> ***SAVING FOLLOWS****
>
> checking value is 2008-01
> In my table my data are:
> checkthis: 2008-01
> checktype: 1

lopera,
I see you start using vfp tag, but you forgot to close it :-)

1. I don't see any reason to use SQLPREPARE() here. If the code is not in a loop, there is no need of it
2. I don't see where you declare "checking" variable
3. If you only have to check if some records exists in the remote table, there is no need to return the whole resultset. Just return 1 or 0. Something like this:
checking = [2008-01]
TEXT TO lcSQL NOSHOW
     IF EXISTS(SELECT * from thetable t WHERE t.checkthis = ?m.checking and t.checktype = 1)
        SELECT 1 AS TestValue
     ESLE
        SELECT 0 AS TestValue
ENDTEXT

IF SQLEXEC(gnhandle, lcSQL,[SQLResult]) > 0
   if SQLRESULT.TestValue == 1
      MessageBox ("Not allowed entry")
      return .F.
   ELSE
      EXIT
   ENDIF
ELSE
   *** Error executing the code
   AERROR(laError)
   MessageBox([Can not execute the statement. Reason: ]+laError[1,2])
   RETURN .f.
ENDIF

That code will run faster, because the back end will STOP execution when the first record is found and because you will not sendind over the net the whole resultset, but only 4 bites (1 as integer).


-----------------
Borislav Borissov

Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.

ENTIRE THREAD

evaluate(done) Posted by lopera @ 8/12/2008 9:11:02 AM
RE: evaluate my code Posted by Merinissa Galapon @ 8/12/2008 9:27:12 AM
RE: evaluate my code Posted by lopera @ 8/12/2008 9:31:45 AM
RE: evaluate my code Posted by Borislav Borissov @ 8/12/2008 9:28:31 AM