Solved

Adding new FIELD to database

Posted on 1998-06-21
5
157 Views
Last Modified: 2010-04-04
Hi all.

Is it possible to add a new FIELD to a Paradox database?  I have a table which looks like this:

Name: String
ID:   Integer
Word: String

Now, I want to add another field to this table at run-time.  It has to be an integer field. So we would now have

Name: String
ID:   Integer
Word: String
Ref:  Integer

Any ideas?  The reason it has to be done like this is because I need to add a new field for each user.  There could be as few users as 20 and as many as 500.

Stuart.
0
Comment
Question by:Stuart_Johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 50 total points
ID: 1354993
You have to create a new table and use tableN.fieldDefs.add method to add new field definition. After that copy all you existing data to the new table and rename it. (there is an example in delphi help). It is easier to use SQL to create new table if you are familier with SQL.

BTW I wonder why you need to add one field for each user. Something is not wrong with your database design. It appears to me that your database is not normalised. Try to normalise it and you can avoid adding indefinite number of field at runtime.  

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1354994
Thanks for the suggestion.  Just so you know, the reason we want to add a new field for each person is this.  We have a class of 20 students (this could vary as I mentioned before, upto at least 500).  We have a list of over 8700 words which we need to teach to these students.  We need to assign each student one record for each word with a status on that word.

For example.

WORD   STUDENT1   STUDENT2
------|---------|----------|--- >
EGG   | 1       | 3  
BIN   | 0       | 2
GREEN | 2       | 0

Etc.  Now, can you see why we want to do it this way?  The other way would be too slow and difficult.

Can you give me info on how to do that with SQL?

Cheers!


Stu.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1354995
Create an event to add field: something like this

procedure TForm1.Button1Click(Sender: TObject);
begin
{What the following code does is actually same as this SQL statement:  alter table "my.db" add newItem integer}
  with query1 do begin
    close;
    sql.clear;
    sql.add( 'alter table ''cat.db'' add newItem integer');
    execSql
  end;
end;

That simple! That's why I love Delphi :-)



0
 
LVL 2

Expert Comment

by:kjteng
ID: 1354996
if the Ref is not more than 255, you may then do this:

1. create two string fields, namely s1_255 and str256_511
2. intilised the value of both field to '0000...0' ie 255 times of zero
3. if ref value of student with number 1 to 255 change, just assign the new value to  1st character of s1_255, something like this
   a:= table1.fieldbyname( 's1_255').asString;
   a[n]:= 'a'   { n = 1..255}
4. similarly for student number higher than 255:
   b:= table1.fieldbyname( 's256_511').asString;
   b[n-255]:= 'b' { n = 256..511}
  etc
5  to show the ref for student n, showMessage( b[n-255])
Will this work for you?

Bye.
Will come back 8 hours later.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1354997
Excellent!! Wonderful!  Thanks for that! I used the SQL method.  Neater and quicker.

Stu.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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