Best DB grid to use with lots of lookup fields - delphi

I have a table with a couple foreign keys, something like this:
CREATE TABLE project.gl(
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
glaccount_id INT(11) UNSIGNED NOT NULL,
project_id INT(11) UNSIGNED NOT NULL,
booking_id INT(11) UNSIGNED NOT NULL,
cc_id INT(11) UNSIGNED DEFAULT NULL,
cu_id INT(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (id),
INDEX FK_gl_booking_id (booking_id),
INDEX FK_gl_cc_id (cc_id),
INDEX FK_gl_cu_id (cu_id),
INDEX FK_gl_glaccount_id (glaccount_id),
INDEX FK_gl_project_id (project_id),
CONSTRAINT FK_gl_booking_id FOREIGN KEY (booking_id)
REFERENCES project.booking (id) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT ......
I would like to display this in a DBGrid, but of course I don't want all the *_id's to show, but instead the data the id points to.
I don't want to use a query to resolve the id's, (for now) I want to use a plain TTable.
Which DBGrid variant would you recommend that can lookup foreign keys, using something like a DBLookupComboBox in the foreign key cell?

Just create a lookup field. Then the TDBGrid automatically shows a combobox for that column where you can select from the available values. The key field is automatically updated then.

See also TDBGridEh from Ehlib, it is more "light" than ExpressQuantumGrid but pretty powerful. It is a commercial product.

I do use the ExpressQuantumGrid from DeveloperExpress for this and many other tasks. It is very powerfull and mature and can have Lookup-Columns. But it is commercial and it is a very "heavy" component.

Related

Why doesn't init script create every table in the script?

I am trying to make an init script for MariaDB, using docker-compose.
Only the 3 first tables are created, so player_team_relation and player table are not created.
create table if not exists user
(
user_id varchar(255) primary key,
username varchar(30) not null,
password_hash varchar(255) not null
);
create table if not exists history
(
history_id bigint auto_increment primary key,
user_id varchar(255) not null,
game_date timestamp not null,
constraint user_history_constraint foreign key (user_id) references user (user_id)
);
create table if not exists team
(
team_id bigint auto_increment primary key,
history_id bigint not null,
player_name varchar(30) not null,
score bigint not null,
hasWon bool not null,
constraint history_team_constraint foreign key (history_id) references history (history_id)
);
create table if not exists player_team_relation
(
player_id bigint not null primary key,
team_id bigint not null primary key,
constraint player_ptr_constraint foreign key (player_id) references player (player_id),
constraint team_ptr_constraint foreign key (team_id) references team (team_id)
);
create table if not exists player
(
player_id bigint auto_increment primary key,
user_id varchar(255) not null,
player_name varchar(30) not null,
wins int not null,
losses int not null,
score bigint not null,
constraint user_player_constraint foreign key (user_id) references user (user_id)
);
I have tried creating the database many times by deleting the volume and creating a new container.
Another example why error checking is always recommended:
The statement
create table if not exists player_team_relation
(
player_id bigint not null primary key,
team_id bigint not null primary key,
...
will fail, since it's not possible to define multiple primary keys per table. For more information on primary keys please check the documentation.
About your column definitions: Are you sure you want to use BIGINT (signed integer) instead of BIGINT UNSIGNED for auto_increment? Do you really need BIGINT? The maximum value of INTEGER UNSIGNED is 4294967295 - more than half of the world's population.

Unable to find column names in a FK constraint

I have created two tables in Snowflake.
create or replace TRANSIENT TABLE TESTPARENT (
COL1 NUMBER(38,0) NOT NULL,
COL2 VARCHAR(16777216) NOT NULL,
COL3 VARCHAR(16777216) NOT NULL,
constraint UNIQ_COL3 unique (COL3)
);
create or replace TRANSIENT TABLE TESTCHILD3 (
COL_A NUMBER(38,0) NOT NULL,
COL_B NUMBER(38,0) NOT NULL,
ABCDEF VARCHAR(16777216) NOT NULL,
constraint FKEY_1 foreign key (COL_A, COL_B) references TEST_DB.PUBLIC.TESTPARENT1(COL1,COL2),
constraint FKEY_2 foreign key (ABCDEF) references TEST_DB.PUBLIC.TESTPARENT(COL3)
);
Now I want to execute a query and see the names of columns that are involved in FKEY_2 FOREIGN KEY
in Table TESTCHILD3, but it seems like there are no DB Table/View that keeps this information. I can find out the column names for UNIQUE KEY & PRIMARY KEY but there is nothing for FOREIGN KEYS.
EDIT
I have already tried INFORMATION_SCHEMA.TABLE_CONSTRAINTS, along with INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS and all the other system tables. No luck. Only DESC TABLE is giving me some info related to CONSTRAINTS and COLUMNS but that also has FOREIGN KEY CONSTRAINTS information missing.
SHOW IMPORTED KEYS IN TABLE <fk_table_name>;
Updated answer:
I was checking on something unrelated and noticed a very efficient way to list all primary and foreign keys:
show exported keys in account; -- Foreign keys
show primary keys in account;
When you limit the call to a table, it appears you have to request the foreign keys that point to the parent table:
show exported keys in table "DB_NAME"."SCHEMA_NAME"."PARENT_TABLE";
You can check the documentation for how to limit the show command to a specific database or schema, but this returns rich information in a table very quickly.
maybe you can try to query this view: INFORMATION_SCHEMA.TABLE_CONSTRAINTS
Note: TABLE_CONSTRAINTS only displays objects for which the current role for the session has been granted access privileges.
For more see: https://docs.snowflake.net/manuals/sql-reference/info-schema/table_constraints.html

Save a list of strings to sqlite database in Swift 4

Is it possible to save a list of strings into a SQLite column in swift4?
If you're looking for an array data type like you find in some SQL engines, SQLite does not have that. You theoretically could encode this list somehow (e.g. a JSON array), but that's pretty kludgy. So, I'd probably go ahead and normalize that, putting the multiple strings in a separate table.
E.g. Let's say you wanted a table users, that had user_id, name, and an array of privileges. You'd probably instead do something like:
CREATE TABLE users (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
);
CREATE TABLE users_privileges (
user_privilege_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
privilege TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users (user_id)
);

Rails 3.1: Is there any way I can view which indexes have been created for my model?

I'm having a problem with my ActiveRecord exception handling and I suspect some of the indexes haven't been created as I thought they did. How can I view the indexes that have been created for my model?
Thanks so much in advance for your wisdom!
You can just look in your db/schema.rb where all the structure of the database is explicitly listed.
Assuming you are using MySQL, from your command line:
$ rails dbconsole
mysql> show create table users;
users | CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT '',
`email` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `index_users_on_email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=latin1 |
Any "KEY" lines are your indexes.

How to insert primary key value explicitly?

I have a table called messages and here is the table structure, I don’t want id is auto increment field but it should be a primary key for that table.
Here is table structure for messages
CREATE TABLE `messages` (
`id` INT(11) NOT NULL,
`user_id` INT(11) NOT NULL,
`text` VARCHAR(255) NOT NULL,
`source` VARCHAR(100),
`created_at` DATETIME DEFAULT NULL,
`updated_at` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`)
);
while insert the data into table I am using below hash object
msg['id'] = 12345;
msg['user_id'] = 1;
msg['text'] = 'Hello world';
If I save this hash into messages table, id is not inserting
message = Message.new(msg);
message.save!
Rails is building insert sql with out id, so id value is not inserting messages table.
How insert the id value in table, This the insert sql rails build with out using id field
INSERT INTO `users` (`updated_at`, `user_id `, `text`, `created_at`) VALUES('2010-06-18 12:01:05', '1', 'Hello world', '2010-06-18 12:01:05');
Setting ID value is often useful when migrating from legacy data or - as I am doing right now - merging two apps while preserving FK integrity.
I just scratched my head for a while and it seems you have to set the PK value before calling save. After the record is saved, ActiveRecord ignores #id= or update_attribute . So while setting up the record from an attribute hash I use:
article = Article.new(attrs)
article.id = attrs["id"]
article.save!
You're working against the way rails works. ActiveRecord reserves the use of the id column and manages it for you.
Why should id not be an auto-incrementing column if it's the primary key?
Why do you need to control its value?
If you need an id column you can control yourself, add another one. It won't be the primary key, but you can make it a unique index too.

Resources