Solved

Create Table - With Alias

Posted on 2014-01-08
5
485 Views
Last Modified: 2014-01-13
OK, so I'm creating a table and making the name dymanic...bu when it shows in the Data Session Window under Aliases is shows as "H"...why and how can I assign it a name?

PUBLIC TableName
TableName = PADL(ALLTRIM(STR(client)),4,"0") + "_Items"

So my table name is for example 0101_Items

CREATE TABLE &TableName (field1, field2, field3...)

But as I mentioned above in the Data Session Window under Aliases it shows as "H"???
0
Comment
Question by:smithmrk
5 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 400 total points
ID: 39767276
Table names names are not allowed to begin with a number. Only letters and undersore.
File names don't have that restriction, but workarea names.

I would have expected an error, but obviously VFP handles this by giving the workarea the letter corresponding to the workarea number.

Look at your harddrive, the DBF will be named as you wanted, but opening it the workare will have a single letter name.

Don't confuse the workarea name with the table name, nor the file name. This three names can differ:

Create Database nametest
Create Table filename NAME tablename (field1 I)
Use && close the table
* reopen it in three ways
* specify databasename!tablename
Use nametest!tablename IN 0 Alias workareaname1
* specify dbf filename
Use filename In 0 AGAIN Alias workareaname2
* specify just the tablename, it will be looked for in the currently set database
Use tablename IN 0 AGAIN Alias workareaname3

Open in new window


This is not to demonstrate the effect of a file name beginning with a digit, this is showing how many ways there are to address a table and workarea. People often confuse the workarea name with the table name, as it normally is the same, but some rules apply to workarea names (eg not using an alias=workarea name twice) but you can have as many files with the same name (in different directories) all belonging to the same DBC, as long as they are added with unique tablenames.

You have to know the details in VFP to avoid the pitfalls.

Bye, Olaf.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39767278
By the way: It's recommended to only specify a differing alias name, if you need to use a table twice in the same datasession, to have two record pointers or use the two aliases as controlsource to feed two comboboxes, for example. Therefore you normally also don't use file names starting with a digit, because while that'spossible, you'dalways need to open those files with ALIAS. It's bad for writing generic code relying on workareas getting the same name as the file. For the same reason avoid spaces in the dbf file name.

You know better than me, how you would like to alter your naming of the DBFs, perhaps add the "items_" in front or just add an underscore or add a "client_" in front.

Bye, Olaf.
0
 
LVL 12

Assisted Solution

by:jrbbldr
jrbbldr earned 50 total points
ID: 39768115
I think the bigger issue here is the confusion between the term "TableName" and "Alias".

Your code shows you are allowing users to create a TableName (albeit possibly violating the name convention rules), not necessarily an Alias.

True, if you do not specifically assign a different Alias name to a Table, the Alias will default to the TableName.  However note that spaces within the TableName will be changed to under-scores within the defaulted Alias.

But most often when differing Aliases are required that is done via an option of the USE command and does not need to be directly associated with the TableName.

Example of specifically assigning (within the code) a different Alias to a Data Table:
[b]USE MyTable IN 0 [u]ALIAS CustNames[/u][/b] 

Open in new window


If you want your users to create their own Data TableNames then put in code to prevent them from violating the naming convention.

Then, within your code, you can utilize these individually named Data Tables but assign them to a common Alias for use if that is so desired.

Good Luck
0
 
LVL 41

Assisted Solution

by:pcelba
pcelba earned 50 total points
ID: 39773152
To create a table having an alias assigned is very easy. You just have to create database:

TableName = PADL(ALLTRIM(STR(client)),4,"0") + "_Items"
CREATE DATABASE &TableName
CREATE TABLE &TableName  NAME YourNewAlias  (field1, field2, field3...)

Above code just shows "Everything is possible in FoxPro" but this solution is not the one I would recommend to use... So please forget it and read above posts :-)
0
 

Author Closing Comment

by:smithmrk
ID: 39776600
Thanks to everyone!
I ended up just moving my client_id field to the end as Olaf said tables can not start with a number so I just moved my number to the other end and so now I have:

TableName = "Items_" + PADL(ALLTRIM(STR(client)),4,"0")

This works for me!
Thanks again to everyone,

Mark
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now