Giter Site home page Giter Site logo

SQLite support about heidisql HOT 41 CLOSED

the-liquid-metal avatar the-liquid-metal commented on May 9, 2024 76
SQLite support

from heidisql.

Comments (41)

ansgarbecker avatar ansgarbecker commented on May 9, 2024 22

Here we go, the very first experimental SQLite implementation for HeidiSQL:

grafik

*Edit: Many features do not yet work, for instance the Table and Data tab show nothing, the Query grids cannot be edited and such things. Very early stage.
However, if you'd like to test it, install the latest built installer, or just update to the latest build and copy sqlite3.dll from here to your HeidiSQL directory. Note you have to put the database filename into HeidiSQL's "Hostname/IP" text field.

from heidisql.

penCsharpener avatar penCsharpener commented on May 9, 2024 7

I'm using the DB Browser for SQLite which does a good job but the HeidiSQL UI is better so if it was possible to support SQLite, that would be great.

from heidisql.

UweRupprecht avatar UweRupprecht commented on May 9, 2024 6

Yes, the ALTER TABLE statement is very limited. As you said, you can work around this limitationl, so this should not be that big deal :)

from heidisql.

FBachofner avatar FBachofner commented on May 9, 2024 5

HeidiSQL forum poster aikona (Eric) doesn't have a Github account but made a useful post which I am excerpting here to help move forward the conversation.

"Delphi uses Firedac as data access library and Firedac supports SQLite."

It seems considering adopting this library (if not already the case) could help with bringing SQLite support to HeidiSQL . . .

from heidisql.

leeoniya avatar leeoniya commented on May 9, 2024 1

@ansgarbecker this is great! will be testing soon. and you have a Christmas present in your account.

from heidisql.

igitur avatar igitur commented on May 9, 2024 1
SELECT * FROM pragma_foreign_key_list('HangFire.JobQueue');

or

PRAGMA foreign_key_list('HangFire.JobQueue');

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024 1

Regarding the current state of SQLite support in HeidiSQL, I would like to close this issue, and let the remaining issues be discussed in separate tickets.
I should announce it on heidisql.com so other users can contribute with reports.

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Does SQLite have some SQL API? If not, then HeidiSQL might be the wrong client for it, as everything is based on SQL here. Also, I need a 32bit + 64bit Windows library/dll to support it. Probably you can put some stuff here to get started here.

from heidisql.

tomasfejfar avatar tomasfejfar commented on May 9, 2024

I'm not sure about what you're asking. There is C API to SQLite - usually, you bundle the DLL (http://www.sqlite.org/download.html) and use it from your code. Then you can connect (https://sqlite.org/capi3ref.html#sqlite3_open) and call SQL as you would with MySQL or any other RDBMS if I understand it correctly. (pardon me if I'm totally off, as I've never developed desktop apps seriously - only playing with buttons and alerts :D)

from heidisql.

UweRupprecht avatar UweRupprecht commented on May 9, 2024

I worked with sqlite3 with delphi (using directly the API and also using ZEOS). So theres should be not that big problem on integrate it to HeidiSQL. Precompiled dll's are available at sqlite.org :)

I think this will be a greate advance for Heidi, cause a lot of developers use sqlite, as you do not need to
setup and install a whole serversoftware. You can just use the dll :)

from heidisql.

igitur avatar igitur commented on May 9, 2024

Slightly off-topic question: I understand that ZeosLib was long ago, but then removed. Am I right? And why was that decision taken?

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Yes, very early versions of HeidiSQL made use of ZeosLib until I removed that in Sep 2009 in e2674ca. There were quite a few features I could not implement with Zeos, so I decided to write my own, more lightweight abstraction layer, which was added in 12a8e2e.

from heidisql.

rentalhost avatar rentalhost commented on May 9, 2024

About the SQL API support, I think that it is available here in C/C++. But I don't have sure if it is compatible with Delphi.

The biggest problem with SQLite is that it have a lot of database limitations like, for instance, do not support ALTER TABLE. Which imples to the need to create a new temp table with the "final state" of modifications, query old table with the existing columns, copy to new table, remove old table and rename new.

So if you intends to implements a SQLite support (and I really hope that you do that), maybe you should create a secret option to enable it while it is developed, once that it will cause a lot of bugs on initial development.

from heidisql.

dcanoh avatar dcanoh commented on May 9, 2024

Hi, Egmond.
I am also interested in SQLite with HeidiSQL.
I would like to hear from you some kind of proposal for me to help to incorporate this support.
I can share some info about your questions:

Does SQLite have some SQL API? .... as everything is based on SQL here. 
.... 32bit + 64bit Windows library/dll to support it. 
.... some stuff here to get started .....

Tell me how we can proceed.

You can find me in cano.hernan, in gmail.

HERNAN CANO M
Systems Analyst

from heidisql.

erdincgc avatar erdincgc commented on May 9, 2024

We all waiting for the great HeidiSQL's Sqlite support :) ... It will come true one day :)

from heidisql.

FBachofner avatar FBachofner commented on May 9, 2024

Hallo Ansgar:

Here we go, the very first experimental SQLite implementation for HeidiSQL

What a fabulous Christmas present. Fröhliche Weihnachten!

I'll definitely test this when I return home in the New Year.

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Todo:

  • multiple queries executed one by one return too many results
  • multiple queries executed in one go always return 1 result
  • table tab does not show columns
  • data tab shows an error

from heidisql.

penCsharpener avatar penCsharpener commented on May 9, 2024

I did a very quick test and tried creating a database by entering a path where no sqlite file existed to see if it would create it. I opened a blank database but I couldn't create tables without running into errors.

from heidisql.

igitur avatar igitur commented on May 9, 2024

Good work, @ansgarbecker .

I notice that some statements are still wrong, e.g. to get the list of columns in a table, this is currently executed:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG='main' AND TABLE_NAME='HangFire.List';
/* no such table: INFORMATION_SCHEMA.COLUMNS */

but it should be:

PRAGMA table_info('HangFire.List');

The full list of pragma commands is available at: https://www.sqlite.org/pragma.html

from heidisql.

igitur avatar igitur commented on May 9, 2024

@ansgarbecker I see you're now doing queries like this for determining column info:

SELECT "sql" FROM sqlite_master WHERE "type"='table' AND name='HangFire.AggregatedCounter';

I really really really think you should be using the PRAGMA commands to avoid having to parse SQL statements that's returned by the queries that you're using. The PRAGMA statements' results are much easier to work with.

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

@igitur The SQL code currently fits better into HeidiSQL's routine for retrieving table columns and keys. I will probably change the complex way of parsing that stuff. But I also see that PRAGMA table_info(...) does not provide key details, apart from the "pk" value. Foreign keys are also not included. How would you retrieve these if not from the SQL code?

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

@igitur one more pragma-related question: how to check if an index returned by PRAGMA index_list('xyz') is a foreign key or a normal index? PRAGMA foreign_key_list() does not return the same key name, and PRAGMA index_info() does not return the index type.

from heidisql.

igitur avatar igitur commented on May 9, 2024

I don't have much experience with that, but I did a quick test and it seems index_list returns only normal indices and foreign_key_list returns only foreign keys. Here is a sample script:

drop table if exists contacts;
drop table if exists groups;

create table groups (
  id integer primary key autoincrement,
  group_name text
);

create table contacts (
    first_name text NOT NULL,
    last_name text NOT NULL,
    email text NOT NULL,
    group_id  int not null,
    constraint FOREIGNKEYNAME foreign key (group_id) references groups
);

CREATE UNIQUE INDEX idx_contacts_email 
ON contacts (email);

CREATE INDEX idx_contacts_name 
ON contacts (first_name, last_name);     

insert into groups (id, group_name) values (1, 'Normal');
insert into groups (id, group_name) values (2, 'Admin');

INSERT INTO contacts (first_name, last_name, email, group_id)
VALUES('John','Doe','[email protected]', 1);

INSERT INTO contacts (first_name, last_name, email, group_id)
VALUES('David','Brown','[email protected]', 1),
      ('Lisa','Smith','[email protected]', 2);
      
select * from contacts;

PRAGMA index_list('contacts');
PRAGMA foreign_key_list('contacts');

from heidisql.

srsbiz avatar srsbiz commented on May 9, 2024

New build 10.3.0.5807 is incompatible with older MySQL servers (before 5.5. I think) due to lack of comment for indexes.

Opening table either to edit results in error: Column "Index_comment" not available.

from heidisql.

igitur avatar igitur commented on May 9, 2024

@srsbiz This thread is about SQLite support. File a new issue, please.

from heidisql.

pantantrollo avatar pantantrollo commented on May 9, 2024

In the portable versions, in which the configuration is shared in a single file portable_settings.txt, the stable version (v.5571) gives an error when starting because there are sentences in this file, which refer to sqlite when it has been configured in the versions that support it. (The .exe files are in the same folder, obviously 😅 )

Possible solution would be to have the configuration files with the name of the .exe that launches them.

image

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Please don't do that. Configuration settings are not backwards compatible.

from heidisql.

pantantrollo avatar pantantrollo commented on May 9, 2024

Please don't do that. Configuration settings are not backwards compatible.

Ok, sorry I thought, mistakenly, that they were. thx

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Foreign keys are now detected, but generate a MySQL/MariaDB syntax:

CONSTRAINT "2" FOREIGN KEY ("AlbumId")
REFERENCES "main"."albums" ("AlbumId") ON UPDATE NO ACTION ON DELETE NO ACTION

I suppose this should be:

FOREIGN KEY ("AlbumId")
REFERENCES "albums"("AlbumId") ON UPDATE NO ACTION ON DELETE NO ACTION

from heidisql.

igitur avatar igitur commented on May 9, 2024

@ansgarbecker Seems like BOOL fields in Sqlite are not recognised yet. I'm on build 5819

CREATE TABLE "MyTable" (
        Id  integer primary key autoincrement,
       CreatedAt DATETIME not null,
       CreatedBy TEXT not null,
       ModifiedAt DATETIME,
       ModifiedBy TEXT,
       Status TEXT not null,
       EffectiveDate DATETIME not null,
       SomeFlag BOOL not null,
       User_id INT not null,
       constraint FKB3819CC9A2587882 foreign key (User_id) references "User"
    )

image

from heidisql.

igitur avatar igitur commented on May 9, 2024

Same with the UNIQUEIDENTIFIER type in Sqlite.

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

@igitur: next build (08fa8a0) detects BOOL columns as TINYINT, as loosely documented on https://www.sqlite.org/datatype3.html .
Please post some documentation of UNIQUEIDENTIFIER data type for SQLite.

from heidisql.

igitur avatar igitur commented on May 9, 2024

@igitur: next build (08fa8a0) detects BOOL columns as TINYINT, as loosely documented on https://www.sqlite.org/datatype3.html .
Please post some documentation of UNIQUEIDENTIFIER data type for SQLite.

Yes, it's weird that UNIQUEIDENTIFIER isn't in that list. I work Sqlite databases that are generated via NHibernate ORM. See this class in NHibernate that describe all the column types that they support. In fact, there's a whole further discussion about whether UNIQUEIDENTIFIER should be internally mapped to TEXT or BLOB. See https://www.connectionstrings.com/sqlite-net-provider/store-guid-as-text/ for the BinaryGuid property on the .NET driver. Would you be able to do the same?

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Indeed I just could successfully create such a table:

CREATE TABLE [unid](
  [uid] UNIQUEIDENTIFIER
);

... and afterwards a PRAGMA table_info('unid') said that is a "UNIQUEIDENTIFIER" type. So, I just added this type to HeidiSQL's known types, handling it like text columns:

grafik

from heidisql.

igitur avatar igitur commented on May 9, 2024

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

I found out SQLite even allows the creation of custom data types:
grafik
So data types only have their mentioned "affinity" determination, as documented. Further on, HeidiSQL supports the commonly used types, plus a few for which it has a special grid editor, as for example ENUM and SET. UNIQUEIDENTIFIER is also a custom type, and now mapped to the binary group internally.

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

One further question: PRAGMA index_list('mytable') gives me an entry which I yet interpreted as a non-unique index. But that does not seem to exist in SQLite, does it? The entry seems to belong to a foreign key which is also present in mytable, and the sql code in sqlite_master table does not create an extra key for it. So, how do I have to interprete such entries from PRAGMA index_list() ?

from heidisql.

leeoniya avatar leeoniya commented on May 9, 2024

not related to your last question, but it would be useful if the grids showed the internal rowid. more info:

https://www.sqlite.org/rowidtable.html
https://www.sqlite.org/withoutrowid.html

from heidisql.

igitur avatar igitur commented on May 9, 2024

Wow, now I'm learning things about Sqlite that I never knew existed. I agree with @leeoniya about the rowid, but maybe style the column to indicate that it is different. I'm assuming the rowid field is read-only, right? So maybe gray it out or something?

from heidisql.

igitur avatar igitur commented on May 9, 2024

One further question: PRAGMA index_list('mytable') gives me an entry which I yet interpreted as a non-unique index. But that does not seem to exist in SQLite, does it? The entry seems to belong to a foreign key which is also present in mytable, and the sql code in sqlite_master table does not create an extra key for it. So, how do I have to interprete such entries from PRAGMA index_list() ?

Can you give me a script to run on my side so that I can see what you're trying to do?

from heidisql.

ansgarbecker avatar ansgarbecker commented on May 9, 2024

Let us please discuss that rowid thing in a separate issue.

For the index stuff, I am trying to find out what the result of PRAGMA index_list('mytable') exactly shows me. In the current HeidiSQL code, the results are taken as non-unique indexes, while that seems wrong. Instead, they seem to show me foreign keys, though there is also PRAGMA foreign_key_list('mytable'). I am confused :)

from heidisql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.