Recent

Author Topic: [SOLVED] Trying to open self-created SQLite db, and getting DBGrid errors. Help?  (Read 3081 times)

Firewrath

  • New Member
  • *
  • Posts: 35
Note: Due to Forum size limits, 'sqlite3.dll' was removed from the project file. I also had to rename 'TestAccount.sql' to '.txt'.

So I've been learning SQL and how to use it with Lazarus in hopes to make my own personal accounting software.
Mainly just for fun and learning. So nothing I plan on releasing.
(I'm no accountant, so watching my own spending is fine, cause if I screw up then its only me. :P)

So I typed up my own sql file for spending and such, then saved it as a database using SQLite Tools and used the attached project to view the file and ...it turned out kind of like the attached pic.

Now, i'll admit the attached project code is a little bit of a mishmash of stuff I pulled off the net/forms and such, but it opens other SQLite database files that I had for testing (Like Chinook and a D&D3.5 SRD Database).
Then when I went to open mine, ...well, It doesn't really work.

So, I created this TestAccount.db and viewed it with the attached project and it does the same thing.
TestAccount.db was made using the TestAccount.sql file attached below and saved as a Database with SQLite Tools.
A program called SQLite Control Center also opened my TestAccount.db just fine and using the attached sql file in SQLite Control Center to create a Database gives the same results.

So can someone tell me where I'm screwing this up?
or point me to something that'll help.
...Though I'll say that finding tutorials for SQLite and Lazarus/Free Pascal is ...difficult. So I may have missed something.
(Plus limited internet doesn't help...)

...oops, forgot: I'm on WinXP with Lazarus 1.6.4
« Last Edit: November 14, 2018, 06:54:39 pm by Firewrath »
Sorry. I currently don't have Internet Access. So my replies might take a week. -_-

gorkamorka

  • New Member
  • *
  • Posts: 11
Hello !

Please try this  ;


change that line

create table TestAccount (id integer primary key, Date DATETIME, Desc text, Type text, Amount REAL, Notes text);

with this

CREATE TABLE TestAccount (
    id     INTEGER  PRIMARY KEY,
    Date   DATETIME,
    [Desc] STRING,
    Type   STRING,
    Amount REAL,
    Notes  STRING
);

Changing "text" type to "string" should give you attached result.

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Changing "text" type to "string" should give you attached result.
Actually, in my experience, it is best to use Varchar.

SQLite does not internally use Varchar, as records always are stored as text, but the definition is read by the database driver, so the program can interpret the data correctly.

So typically use Varchar(20) eg - this ensures that the columns in dbGrid does not get to wide, and actually SQLite is capable of storing strings longer than 20 characters wide, despite the 20 character definition.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Note: Due to Forum size limits, 'sqlite3.dll' was removed from the project file. I also had to rename 'TestAccount.sql' to '.txt'.
You should never include binaries, not exes, not dll's, in attachments. Just sourcecode and resources needed to reproduce a problem.
You may include a link to executables. 
Small executables can be zipped, but wait for a request to do so: we need sourcecode to help you, not the binary result.
« Last Edit: October 25, 2018, 06:06:47 pm by Thaddy »
Specialize a type, not a var.

Firewrath

  • New Member
  • *
  • Posts: 35
Note: Due to Forum size limits, 'sqlite3.dll' was removed from the project file. I also had to rename 'TestAccount.sql' to '.txt'.
You should never include binaries, not exes, not dll's, in attachments. Just sourcecode and resources needed to reproduce a problem.

Sorry about that, I was mainly just pointing out why the dll wasn't in the zip, but noted. ^-^;



Sorry it took me so long to reply, I've been busy. -_-

Changing "text" type to "string" should give you attached result.
Actually, in my experience, it is best to use Varchar.
SQLite does not internally use Varchar, as records always are stored as text, but the definition is read by the database driver, so the program can interpret the data correctly.
So typically use Varchar(20) eg - this ensures that the columns in dbGrid does not get to wide, and actually SQLite is capable of storing strings longer than 20 characters wide, despite the 20 character definition.

I want to say Thanks to both of you, this was actually very helpful. Mainly that Lazarus SQL will use the variables as set from my SQL database.
(That's an interesting way to do things, but eh :P)
Setting my 'Amount' as a Double still gives me weird number errors though. -_-
(See pic)
But 'Varchar(20)' works rather well, just need to align that column text to the right, ...so 'TODO' when I get time, ^-^

Thanks guys. ^-^
Sorry. I currently don't have Internet Access. So my replies might take a week. -_-

 

TinyPortal © 2005-2018