i know, i know, my next post was supposed to be about connecting to firebirdsql database tables via an odbc connection. i promise it is coming, but in the meantime, i had an epiphany the other day and i wanted to share it.

the elite foxpro programmers out there will probably think this is a silly thing to write about and something that i probably should have known all along, but i really think what i learned by accident points to something bigger that everyone should take the time and think about. but before i get to the moral of the story, perhaps i should tell the story first.

at the foxforward 2007 convention, i asked a group of seasoned foxpro programmers about all the articles i had read on the web pro and con of using remote views or sql pass through. without a single hesitation on anyone's part they all said in unison that sql pass through was the only way to go. my reason for asking the question was because i'd never seen a definitive answer to the question and frankly, i was curious to know if there was actually a preferred way of accessing remote data.

this left me with a problem. you see, i guess i'm lazy because i really like designing my screens visually and working with visual objects. because i like to use grids in certain situations, i was having lots of problems with sql passthrough. i could never figure out how to use the data environment to open and manage my tables because every time i wanted to use a cursor that i created on the fly using passthrough in a grid, the init of the grid would happen before the query ran. i would get errors unless i performed the query in the beforeopen tables event, but when i did this, i would have to manually open and close the tables and make sure that all of the properties were set right.

because foxpro is so flexible, i figured no problem, just create remote views, parameterize them and use them in grids making sure that no data was loaded to the view until after i set the parameters and requeried the view. this worked and handled most of the situations that i ran across. however, this created a new problem because it required me to have lots and lots of predefined remote views when sometimes all i really wanted was a short list of stuff to display for the user. "oh, well" i thought, "i guess you just have to find what works and stick with it."

but still it nagged at me. if all the programmers at foxforward said pass through was the way to go, then why was i having so much trouble achieving what i wanted. either i was missing something or they were just blowing smoke. i suspected that the former was the correct answer.

anyway, fast forward to the other night when i was working once again with a grid that i wanted to set up using data generated from a query, but in this case, i just wanted to access local data run a query on it and have the results displayed in a grid. my age-old problem re-emerged because everytime the grid instantiated, it generated an error because the controlsource wasn't found. i figured i'd deal with that later and went ahead and wrote my refresh/requery code to re-issue the sql statement whenever the user changed something on the screen. i knew that grids will go blank if you issue the requery command so i knew that i needed to issue the following series of commands:

  1. thisform.lockscreen = .t.
  2. thisform.stdgrid1.controlsource = ''
  3. requery('gridview')
  4. thisform.stdgrid1.controlsource = 'gridview'
  5. thisform.lockscreen = .f.
  6. thisform.refresh()

and while looking at this code, it suddenly dawned on me that i'd been staring the solution to my problem right in the face and never seen it before now. i could create my grid visually using the raw table, set up all of the click,dblclick and other code that i wanted to attach to the grid. then, clear the controlsource and make it blank. once the form and grid was instantiated, i could issue whatever sql passthrough commmands i wanted to create a cursor and then assign the cursor to the controlsource of the grid!

i got even more excited after i tried it and it worked perfectly. the only issue was making sure that the fields i requested in my sql command matched the columns i'd predefined in the grid. i wanted to share it with someone but when i turned to my wife and started to explain it, and her eyes glazed over, and i knew that i was going to have to put this on my blog even if people laughed at me about how silly i had been to not know all this stuff to begin with.

but the point about not knowing this previously is this: all this time i had been programming in visual foxpro and my assumption was that once i put something in a box on a property, it was written in stone. the flexibility of foxpro gave me another way to accomplish what i wanted to do and cludgy as it seemed even to me, it worked, so why go back and figure out another, better way to do. at the same time, it is sometimes hard for programmers to admit they just figured something out, but it is more important to think about the programmers who are just starting out with foxpro and make sure they don't have to work out all of the same problems all by themselves.

ultimately while feeling stupid, i began to wonder how many programmers out there have done exactly the same thing: accept that what we put in a box should always stay there? how many programmers have accepted the status quo of how they do things and never examined possible alternatives? i realize that many of us work in production mode, sling the code, send the bill, and look for a new client. but my small problem led to a huge realization and i wanted to share it because who knows who else might need the same insight.

moral of the story:

moving out of our comfort zone can sometimes lead to living in an even more comfortable zone.

go ahead...think outside the box.

 

3 Responses to Go ahead…Think Outside The Box

  • Bernard Bout says:

    >>using Remote Views or SQL Pass through

    You forgot to include Cursor Adapters. That is a 1 stop solution, object oriented and Bindable back into the backend. No need of extra code for your Updates and Deletes.

  • paultarver says:

    >>You forgot to include Cursor Adapters.

    I appreciate the comment, but I intentionally left out Cursor Adapters because I was writing from my personal experience and so far I don’t have any production experience with Cursor Adapters. Besides, the article was not really intended to be a complete discussion of the different choices within FoxPro, but rather it was my attempt to point out that we often get so comfortable doing things the same old way that we forget to think about ‘possibilities.’

    You are absolutely correct that Cursor Adapters are a great option, but I just didn’t feel comfortable talking about a feature that I don’t have any real hard knowledge about. That’s probably the quickest way to get laughed out of the FoxPro Blog world! 🙂

    Thanks for reminding other readers of the article about it though!

    PHT

  • Bernard Bout says:

    I know what you mean. Have a read of this post of mine from last year. The Title of this post should interest you :), then read the rest of the posts. You will not be disappointed.

    http://weblogs.foxite.com/bernardbout/archive/2006/05/17/FirstPost.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *