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!

Table problem

Status
Not open for further replies.

DaZZleD

Programmer
Oct 21, 2003
886
0
0
US
Hi,

I have an application that needs to create some tables when it's launched. It first deletes the tables if they exist then recreate them. The problem is that one field (called 'sc') gets translated into 's_' when the table actually gets created in the db.

Code:
  with form1.Table1 do begin
    Active := False;
    TableName := 'Angajatori';
    with FieldDefs do begin
      Clear;
      with AddFieldDef do begin Name := 'nr_crt';DataType := ftInteger;Required := True; end;
      .....................................
      with AddFieldDef do begin Name := '[b]sc[/b]';DataType := ftString; size := 10; end;
      .....................................
    end;
    with IndexDefs do begin
      Clear;
      with AddIndexDef do begin Name := 'nrcrt';Fields := 'nr_crt';Options := [ixPrimary];end;
    end;
    CreateTable;
  end;

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
You don't say which version of Delphi or which DBMS you are using but it worked okay for me with Delphi 7 and Paradox. The <b>sc</b> field was created as <b>sc</b>.

Incidentally, your code will probably be easier to maintain and more portable if you use SQL. Something like this would have the same effect, assuming you have a TQuery component on your form called Query1.
Code:
 with form1.Query1 do begin
  SQL.Clear;
  SQL.Add ( 'CREATE TABLE Angajatori ( nr_crt INT, sc char(10), Primary Key ( nr_crt) )' );
  ExecSQL;
 end;
I think that is much clearer than using the non SQL method.


Andrew
Hampshire, UK
 
i'm using delphi 5 and SQL. i have used the non sql method since i thought it might save me trouble when using different dbms through bde.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
SQL is the language used to access most databases. Which database are you using? Possible candidates are

dBASE
InterBase
MS SQL Server
MySQL
Oracle
Paradox

and others

I think it is preferable to use SQL to access a database rather than using the BDE specific way that you have done.

SQL skills are likely to be more useful for you than BDE ones even though there are differences in the amount of SQL understood by and the SQL syntax used by the various databases.

Andrew
Hampshire, UK
 
If you are using a RDBMS you can make use of stored procedures, to execute the SQL. I use for this the BDE, but the command are SQL. For the rest I totally agree with Andrew

Steven van Els
SAvanEls@cq-link.sr
 
MS SQL Server

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
I checked SQL Profiler and it seems that the command gets sent by delphi to the server with sc replaced with s_

I agree that sql is mostly used, however, as you pointed out, the dialect and amount of sql syntax differs from one dbms to another. This is why I thought BDE can come in and take care of the problems.

The replace is strange though.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Just for larks can you add a space at the end of the field name:

with AddFieldDef do begin Name := 'sc';DataType := ftString; size := 10; end;

to

with AddFieldDef do begin Name := 'sc ';DataType := ftString; size := 10; end;

It will normally trim the space off. The conversion looks like another byte is getting merged into the character generating a '_' instead of 'c' --perhaps there is a requirement for at least 3 characters for fieldnames?

Scotto the Unwise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top