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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add database to project programically

Status
Not open for further replies.

JICGreg

Technical User
Mar 14, 2007
34
0
0
The create database command does not automatically add a database to a project. The only help I have been able to find says talks about adding the database manually to the project.

Can the database be added via code to the project? How?

Thanks
 
You can use Project object's properties to do that. ie:

Code:
_vfp.ActiveProject.Files.Add( _samples+'data\testdata.dbc' )

Cetin Basoz
MS Foxpro MVP, MCP
 
Do you really need to include the Database as a 'captive' element within the Project?

Or can the Database be a FREE database?

If it can be FREE, it can easily be created programatically within your code if it were to be found to be missing. And any necessary Connections can also be created.

If it can be FREE you can easily include it with the other distribution files such as any other 'free' application files and tables.

Good Luck,
JRB-Bldr
 
What is:
" a 'captive' element within the Project"

and how do you create it? I have never heard of it in VFP before.

Cetin Basoz
MS Foxpro MVP, MCP
 
Mike - correct.

'Captive' is my terminology for INCLUDED within the Project and, consequently, 'captive' within the resultant EXE and 'FREE' for Excluded.

 
Adding a database to a project doesn't make it included. VFP isclever enough to add databases as 'FREE'. Its purpose is to keep track of your project files IMHO.

Cetin Basoz
MS Foxpro MVP, MCP
 
Cetin - My understanding was (perhaps inaccurate 'understanding') that anything that went into the Project file (unless manually flagged as EXCLUDE) was then compiled into the EXE where it was no longer dynamic (ergo it was 'captive' within the EXE).

And since when you allow a VFP Project to self-build its contents from the Start program, it will not automatically add the Databases and Data Tables, so the addition of these elements never seemed to be necessary - unlike actual referenced program elements which may be INCLUDED or EXCLUDED within the Project.

How about that? - I guess that all those people must be wrong - I'm really not too old to learn.

However if what you say is true, then what would be the purpose for adding a Database to a Project?

In all my years of FP and VFP application development I have never added a Database to a Project and everything has worked just fine for the applications that I have distributed to clients. Especially since my typical application architecture has the Databases and Data Tables residing in their own child directory off of the code directory.

I just make certain to ensure that the Databases are included among the distribution files along with any other needed Data Tables and all is just fine. I also make certain that my code will look for the presence of required tables and databases and can build them if needed.

Thanks for yet one more opportunity to continue learning.
JRB-Bldr
 
JRB-Bldr,

Your understanding is basically correct.

The reason to add a database to the project is purely for your own convenience in the development environment. It gives you an easy mechanism for getting at your tables, for example to browse a table or to modify its structure.

That said, there is absolutely no obligation to add a database to a project. As you pointed out, it is perfectly safe to leave them out. By default, databases and tables are excluded from the build, so it makes no difference one way or the other to the finished application.

The only (minor) point I would take issue with is your terminology. The term "captive" is not usually used in this context (although most people would understand what you mean), and "free" is normally applied to tables that are not part of a DBC, rather than databases that are not part of the project.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike - thanks for your clarification. And for the confirmation that my 'understanding' hasn't been TOTALLY off the mark for all these years (despite the confusion caused by my own terminology).

So, in general, what we have been batting back and forth is related to development Style rather than a development Necessity. I assumed as much.

If so, then that brings me back to the original posting by JICGreg. Why?

Why would he want to have a Database "added via code" to the Project? Especially when it is, from the application's functional perspective, not necessary.

If it is to support his own development style, then what is wrong with adding it one and only one time manually?

Oh well, perhaps we have 'kicked this dead horse around the block' too much as it is.

Hopefully JICGreg got the answer they wanted.

Thanks,
JRB-Bldr
 
JRB-Bldr,

So, in general, what we have been batting back and forth is related to development Style rather than a development Necessity. .

Yes, I agree.

If so, then that brings me back to the original posting by JICGreg. .... Why would he want to have a Database "added via code" to the Project? Especially when it is, from the application's functional perspective, not necessary.

It's a good point.

JICGreg: You've had some good replies to your question. Are you still here?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
However if what you say is true, then what would be the purpose for adding a Database to a Project?

If it is true or not can be tested:) Do not take my word and test.

As I said earlier in my message "Its purpose is to keep track of your project files IMHO.".

It doesn't effect the workings of your executable. I don't see a usefulness on a project that I would look back into after a month or two but if I need to check after many months or maybe years than it would be nice to see what database (if any) was used.

If you ask my opinion in general, VFP project manager is not a nice "manager" anyway. It is a container to keep track of the files + sometimes you end up with less or more files than needed by your application.

Cetin Basoz
MS Foxpro MVP, MCP
 
To add to Mike's explaination to jrbbldr:

Yes, files are automatically added to a pjx, if you just start with a main.prg and compile it. But there are different defaults for different types of files and databases are by default not included into the application.

There are at least two behaviors of the project manager you need to take into account, though:

1. In regard to databases the project manager tends to keep them opened. Especially if a databse node is expanded in the project manager you can even CLOSE DATABASE in the command window, still the database is keept open.

Take these few steps: Open a project containing a dbc in the data tab of the manager, expand that tab, the database is opened and a combobox in the standard toolbar of the VFP ide will display the database alias name.

Now execute "CLOSE DATABASE" in the command window, the comobobox in the standard toolbar will turn white, so it seems the command has done it's job, but the database is still open, expand the combobox and you'll see there still is the database alias name entry, the database is just not set as the active one.

Now select the database node in the project manager and click the close button, this really closes the database and the tree node. The combobox in the standard toolbar now does not have the database in it any more.

2. Even files in the project that are excluded from the build are compiled during a build run with either "(Re)compile all files" set or if they have more recent source code than their object code.

Because of the project manger behvior described in 1, you might have code working witout any "OPEN DATABASE" command, because the project manager might have the database open by default. This might lead to an EXE not working, while the application works in the IDE.

Another more famous behavior difference is in regard to a missing READ EVENTS, because the IDE will keep an app running as itself will function as the missing read events, the command window being active and keeping everything running after the main.prg has finished and a menu and/or form is established. But also the wrong usage of a database in code can lead to a non working EXE.

I do add databases into the project manager, but I tend to recommend not to do so, because that forces you to handle the database in code in regard to OPEN and CLOSE it, and that will then work in any case.

Bye, Olaf.
 
Yes Mike,

that's why I said I tend do recommend to keep databases in a separate pjx. If you know what you're doing and what the project manager is doing, you're also safe to have a dbc included in the project. Especially beacuse of drag&drop operations, modfiying database and tables, the handling or development style.

Having databases and other things (eg project hooks) in a seperate pjx is also a good and practical way of handling this.

A real world project does not need to be put together into one pjx.

Bye, Olaf.
 
Well my project manager doesn't open and keep them open if I don't explicitly tell it to do so.

Cetin Basoz
MS Foxpro MVP, MCP
 
Another reason not to keep the databases in the project, you might want to use different sets of data with the same code.

For instance you might have an accounting program that was used by 1/2 a dozen divisions within a company all with independent data that should not be seen by the other divisions. Each could have the same table names but be stored in different directories.
 
Storing the database and its tables in different folders has nothing to do with it. Having dbc and tables in project doesn't prevent it any way.

Cetin Basoz
MS Foxpro MVP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top