Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql statement from database

Status
Not open for further replies.

imox

Programmer
May 13, 2013
37
DE
Hello,

I currently learn foxpro, because I have to adapt an old program. My question is how I can get a statement from the internal foxpro databse. I need the data in a programm code.

Thank you

Imox
 
Hi Imox,

Welcome to the forum.

Unfortunately, your question is very vague. It is not clear what you want to know.

If you would give us more information about what you are trying to achieve, we will try to help you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I *think* Imox is trying to get a description of the existing VFP database in a form he can use
to understand it's structure or perhaps replicate it in a SQL databse.

My suggestion, if that is the case, would be to use the gendbc tool which is
found in the tools folder (here on my machine: C:\Program Files\Microsoft Visual FoxPro 9\Tools\Gendbc)

Martin

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Thanks. I found a solution :)

Here an example I think it explain it better then a sentence ;)

Code:
SELECT * FROM TABLE INTO CURSOR tblCurser
SCAN 

MESSAGEBOX(column)

ENDSCAN
 
Glad you've found a solution.

It looks as if you are trying to see the contents of a certain field in every record in your table. If that's right, your code will do that (assuming you replace "column" with the name of the field). But it will only show one record at a time, and you will have to click OK to keep moving on to the next record.

If your aim is to get a quick overview of the contents of a table, it's much better to use a Browse:

Code:
USE TheTable IN 0
SELECT TheTable
BROWSE

Try it and see if that's what you want.

(You can remove the first line if the table is already open.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Sorry - that is no clearer to me!

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Indeed if you only intend to browse data and you have VFP installed you can double click a DBF file and it will open in VFP and show up in a window, a so called browse window, because it's there to browse in the data and the BROWSE command also shows it.

And the caption line will show the field description, if there is one, or the technical field name, in most cases, if the DBF designer didn't used the field description. If it's about the field names then SCAN..ENDSCAN is wring, it doesn't scan all fields names from field 1 to field N, it scans from record 1 to record N.

Bye, Olaf.
 
Thanks for all!

How can I pass the cursor to a nother procedure? e.g.

Code:
PROCEDURE test
	SELECT * FROM table INTO CURSOR cur
	SCAN
             **** TO SOMETHING
	     bla(@cur)
	ENDSCAN
ENDPROC


PROCEDURE bla(cur as Cursor)
    **** TO SOMETHING
ENDPROC
 
You don't need to pass it. In the scenario in your code, the cursor will be available in the second procedure, and you can just go ahead and access it in any way you like.

By the way, when you get several replies to a question - as you have done here - it would be helpful if you could give some feedback, to let us know which of the replies were useful to you, if any. This is especially true where there is some doubt about the meaning of your original question.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Thanks a lot it works ;) until now were all usefull. My problem is solved!
 
Just some more suggestions:

As you call some procedure within the scan/endscan loop you work on one record, you could also pass just the data of one record, by creating a record object and passing that as by reference parameter:
Code:
[COLOR=#BABDB6]PROCEDURE test
	SELECT * FROM table INTO CURSOR cur
	SCAN
             **** DO SOMETHING[/color]
             SCATTER NAME loRecord

	     bla(@loRecord)[COLOR=#BABDB6]
	ENDSCAN
ENDPROC


PROCEDURE bla([COLOR=#000000]toRecord as Object[/color])
    **** DO SOMETHING
ENDPROC[/color]

The loRecord (or toRecord) object will have the values of the current record in properties named as the cursor fields. You can change record data etc, and finally GATHER NAME loRecord to update the current record in the cursor cur. You can also INSERT FROM NAME loRecord to insert a new record.

Another thing you could do is pass the cursor name "cur" as string and then let your function bla work with that alias name instead of hardcoding the cursorname cur. This parameter would typically be called tcAlias (t = taken as input, c=char, Alias = name of a cursor). And you can for example SELECT (tcAlias) or Evaluate(tcAlias+".field") or Replace field with value in (tcAlias).

Bye, Olaf.
 
Great! This was what I had been looking for.

Thanks a lot.
 
It is possible to declare the cursor in the first function as LOCAL? So I can create a new cusor in another procedure?
 
To expand on this: Cursors and variables are two seperate things. Variables are what you knw from other programming languages, cursors are not objects, but DBF, tables. They are also stored in memory, unless they get too large and are swapped to HDD, but they are not part of the variable memory stack, they exist in the datasession and take a workare there, the adressing with names just is equal to objects as name.field, but they are not variables.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top