Skip to content

CSV import into a chosen schema, match columns by name, and locale number display - #4251

Open
deepsidhu1313 wants to merge 3 commits into
sqlitebrowser:masterfrom
deepsidhu1313:feature/import-export-2
Open

deepsidhu1313 wants to merge 3 commits into
sqlitebrowser:masterfrom
deepsidhu1313:feature/import-export-2

Conversation

@deepsidhu1313

Copy link
Copy Markdown
Contributor

Three independent commits.

  1. Choose the schema on CSV import (refs Import CSV into specified schema #2443). The Import CSV dialog has a Schema combo next to the table name (main by default, then temp and the attached schemas). Table lookup, CREATE and INSERT use the chosen schema. This also fixes a shadowing bug: the INSERT used an unqualified table name, so with a temp table of the same name the rows went to the temp table instead of the table just created in main. Tests in the new test-import-csv-options (6 of 8 failed before).
  2. Advanced option "Match columns by name" for CSV import into an existing table (refs Import CSV column order #243), off by default and not persisted; it needs "Column names in first line". Each CSV column goes to the table column with the same name (case-insensitive), unmatched CSV columns are skipped and missing table columns get their DEFAULT or NULL. The positional path is unchanged. There is no drag-to-reorder UI.
  3. Opt-in setting databrowser/locale_numbers (Preferences > Data Browser) that formats Display-role values of INTEGER/REAL/NUMERIC columns with the system locale (refs [Feature]: Number convert to locale number? #3718). Edit, copy and export roles still see the plain number, digits are not rounded, and columns with a Display Format are untouched. Untyped columns and Execute SQL results are not formatted. New test-locale-numbers (13 of 24 failed before).

Refs #2443, #243, #3718

The Import CSV dialog always created the table in the main schema and
looked for an existing table of that name there. Add a Schema selection
next to the table name so a file can be imported into the temp schema or
into an attached database. It defaults to main, so nothing changes unless
the user picks another schema.

The temp schema is always offered because SQLite does not report it
until something has been created in it.

The INSERT statement used the unqualified table name, so rows went to
a temp table of the same name instead of the table which had just been
created in main. Use the schema qualified name for it.

Close: sqlitebrowser#2443
When importing a CSV file into an existing table, the columns of the
file were inserted in the order they are in, whatever their names were.
A file with the columns in a different order than the table, or with
additional columns, could not be imported without editing it first.

Add the advanced option "Match columns by name". When it is on and the
first line contains the column names, each column of the file is
imported into the table column with the same name (ignoring the case).
Columns of the file which have no match are skipped and columns of the
table which are not in the file get their default value. The option is
off by default, so the import works as before unless it is turned on.
It only has an effect on tables which exist already.

Refs: sqlitebrowser#243
Numbers in the data browser were always shown the way SQLite writes
them, e.g. 1234567.5, whatever the number format of the user is.

Add the option "Show numbers in the system number format" to the data
browser preferences. When it is on, the values of columns with an
INTEGER, REAL or NUMERIC type affinity are shown with the digit grouping
and the decimal separator of the system locale, e.g. 1.234.567,5. It is
off by default, so nothing changes unless the user turns it on.

Only the display changes. The digits are never rounded, and what is
edited, copied or exported stays the plain number. Values which are not
plain decimal numbers, such as text or numbers with an exponent, and
columns with a display format are left as they are. Columns without a
numeric type and the results of SQL queries are not changed either
because there is nothing which tells a number from a text in them.

Refs: sqlitebrowser#3718

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants