Home » U++ Library support » U++ SQL » Fields of the same name in diff tables
Fields of the same name in diff tables [message #21685] |
Mon, 01 June 2009 02:43  |
jeremy_c
Messages: 175 Registered: August 2007 Location: Ohio, USA
|
Experienced Member |
|
|
I am confused about how to do this:
TABLE_(HIVE_ACCESSORY)
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
STRING_ (NAME, 128) NOT_NULL
END_TABLE
TABLE_(HIVE)
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
STRING_ (NAME, 128) NOT NULL
BLOB_ (DESCRIPTION)
END_TABLE
This results in compilation errors of duplicate ID and NAME values. I saw elsewhere in the forum that you should use INT_ on first use and INT on subsequent (of the same name). However, when I do that my HIVE table has only the field DESCRIPTION. It does not contain ID or NAME.
Any thoughts on how to accomplish my task? Do I have to create unique field names for all table entries?
Jeremy
|
|
|
|
|
|
|
|
Re: Fields of the same name in diff tables [message #21713 is a reply to message #21712] |
Mon, 01 June 2009 23:09   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
jeremy_c wrote on Mon, 01 June 2009 14:34 | What would I default it to if I don't want a default? Simply what I want (in SQL) is:
CREATE TABLE ABC (
NAME varchar(80) NOT NULL
);
Jeremy
|
I am not sure, I believe that the real reason is that choosen DB does not allow that.. You can easily test by issuing the command manually.
Mirek
[Updated on: Mon, 01 June 2009 23:09] Report message to a moderator
|
|
|
|
|
|
Re: Fields of the same name in diff tables [message #21718 is a reply to message #21717] |
Mon, 01 June 2009 23:58   |
jeremy_c
Messages: 175 Registered: August 2007 Location: Ohio, USA
|
Experienced Member |
|
|
Ok, here is the full definition:
TABLE_(SUPPLIER)
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
STRING_ (NAME, 80) NOT_NULL UNIQUE
STRING_ (ADDRESS1, 128)
STRING_ (ADDRESS2, 128)
STRING_ (CITY, 128)
STRING_ (STATE, 80)
STRING_ (POSTAL_CODE, 24)
STRING_ (PRIMARY_PHONE, 35)
STRING_ (SECONDARY_PHONE, 35)
STRING_ (EMAIL, 128)
STRING_ (WEB_ADDRESS, 500)
BLOB_ (DESCRIPTION)
END_TABLE
Here is the resulting SQL:
-- From S_BeekPRO.sql
create table SUPPLIER (
ID integer primary key autoincrement,
NAME text not null,
ADDRESS1 text,
ADDRESS2 text,
CITY text,
STATE text,
POSTAL_CODE text,
PRIMARY_PHONE text,
SECONDARY_PHONE text,
EMAIL text,
WEB_ADDRESS text,
DESCRIPTION blob
);
-- From A_BeekPRO.sql
create unique index IDX_SUPPLIER$NAME on SUPPLIER(NAME);
Here is the output from sqlite3 session:
C:\Develop\Tools\upp\out\MSC9.Debug.Debug_full.Gui>sqlite3 BeekPRO.db3
SQLite version 3.6.7
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema SUPPLIER
CREATE TABLE SUPPLIER ( ID integer primary key autoincrement ,
ADDRESS1 text, ADDRESS2 text, CITY text, STATE text, POSTAL_CODE
text, PRIMARY_PHONE text, SECONDARY_PHONE text, EMAIL text,
WEB_ADDRESS text, DESCRIPTION blob);
Here is the output from the log:
* C:\develop\tools\upp\out\MSC9.Debug.Debug_full.Gui\BeekPRO.exe 01.06.2009 17:52:23, user: jeremy
ERROR Cannot add a NOT NULL column with default value NULL(0): Preparing: alter table SUPPLIER add NAME text not null
ERROR table SUPPLIER has no column named NAME(0): Preparing: create unique index IDX_SUPPLIER$NAME on SUPPLIER(NAME)
Jeremy
[Updated on: Tue, 02 June 2009 08:06] Report message to a moderator
|
|
|
|
|
Re: Fields of the same name in diff tables [message #21722 is a reply to message #21719] |
Tue, 02 June 2009 14:27   |
jeremy_c
Messages: 175 Registered: August 2007 Location: Ohio, USA
|
Experienced Member |
|
|
I like the idea of Ultimate++ generating table structures for me, I just think it needs a little more work and a little more documentation. Now, I am a database programmer by trade, so when it comes to an enterprise application, I doubt that UPP can ever keep up with what can be accomplished using the database, for instance, all sorts of trigger functions and other server side programming. For desktop applications w/simple databases, however, it's great.
Now, about managing SQL independent. What I do is I always have a directory structure such as:
project/docs
project/src
project/sql
project/sql/0001.sql
project/sql/0001_r.sql
project/sql/0002.sql
project/sql/0002_r.sql
0001.sql is the first version of my database schema. 0002.sql is the create/alter statements necessary to bring 0001.sql (current at the time) to my new version. So, if I were starting a new project, I could psql thedb < 0001.sql ... psql thedb < 0002.sql, etc... Now, 0001_r.sql and 0002_r.sql are "Revert" scripts which will undo the changes. I don't always make those but it's a good idea.
Jeremy
|
|
|
Re: Fields of the same name in diff tables [message #21723 is a reply to message #21718] |
Tue, 02 June 2009 14:47   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Well, this works:
Quote: |
TABLE_(SUPPLIER)
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
STRING_ (NAME, 80) NOT_NULL SQLDEFAULT("")
STRING_ (ADDRESS1, 128)
STRING_ (ADDRESS2, 128)
STRING_ (CITY, 128)
STRING_ (STATE, 80)
STRING_ (POSTAL_CODE, 24)
STRING_ (PRIMARY_PHONE, 35)
STRING_ (SECONDARY_PHONE, 35)
STRING_ (EMAIL, 128)
STRING_ (WEB_ADDRESS, 500)
BLOB_ (DESCRIPTION)
END_TABLE
|
Hard to say what it dislikes.. I guess this is rather question to the sqlite3 forum...
Mirek
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:04:36 CEST 2025
Total time taken to generate the page: 0.01789 seconds
|