Recent

Author Topic: Problems with Updating database through Lazarus  (Read 12301 times)

JackHatton

  • New member
  • *
  • Posts: 7
Problems with Updating database through Lazarus
« on: February 10, 2014, 07:55:07 pm »
Hiya,

First off, I'm a rookie programmer so try to be as simple with me as you can!

So I'm trying to get a database working in my Lazarus program. My program is console based and not form based so I find it harder to find the solution to my problems as lots of people tend to be using form based programming if they're using a database.

The code below works fine.

db_UpdateDatabase('INSERT Into UserDetails VALUES("4", "External2", "auditor2", "4", "0")');

But I'm trying to use my variables and it's not working (I've tried many syntax's, but not quite sure what I should really be using):

db_UpdateDatabase('Insert INTO UserDetails VALUES("'+IntToStr(NoOfUsers)+'", "'+NewUsersUsername+'", "'+NewUsersPassword+'", "'+IntToStr(NewUsersAccessLevel)+'", "0")');

The program runs but when it gets to the point where this happens it will just sort of close (lots of text comes up but it's so fast you can't tell anything it says)

SQLite is my external database thing i'm using.

I've uploaded all relevant files for my project in a rar file here: https://www.mediafire.com/?o07yidktp635od1

If anyone could help me out with this, it'd be a great help. Trying to get my project finished by Friday so. :D :P

Thanks in advance,
Jack Hatton
« Last Edit: February 10, 2014, 08:16:51 pm by JackHatton »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Problems with Updating database through Lazarus
« Reply #1 on: February 10, 2014, 09:13:23 pm »
The program runs but when it gets to the point where this happens it will just sort of close (lots of text comes up but it's so fast you can't tell anything it says)
It worked here.  :P I just needed to change one thing, db_Load('n:/AccountsDatabase.db'); to db_Load('AccountsDatabase.db');

JackHatton

  • New member
  • *
  • Posts: 7
Re: Problems with Updating database through Lazarus
« Reply #2 on: February 10, 2014, 11:31:55 pm »
Quote
It worked here.  :P I just needed to change one thing, db_Load('n:/AccountsDatabase.db'); to db_Load('AccountsDatabase.db');

Did you actually get the add Add User Account procedure working?

Login > Admin Settings > Add User Account

I tried what you said but it still didn't work for me  %) - the actual program does RUN but when it comes to this Add User procedure it doesn't work.
« Last Edit: February 11, 2014, 01:25:06 am by JackHatton »

JackHatton

  • New member
  • *
  • Posts: 7
Re: Problems with Updating database through Lazarus
« Reply #3 on: February 10, 2014, 11:52:20 pm »

Quote
It worked here.  :P I just needed to change one thing, db_Load('n:/AccountsDatabase.db'); to db_Load('AccountsDatabase.db');

Did you actually get the add Add User Account procedure working?

Login > Admin Settings > Add User Account

I tried what you said but it still didn't work for me  %) - the actual program does RUN but when it comes to this Add User procedure it doesn't work.
[/quote]

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Problems with Updating database through Lazarus
« Reply #4 on: February 11, 2014, 12:28:11 am »
Did you actually get the add Add User Account procedure working?

Login > Admin Settings > Add User Account
Check the attachment.

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Problems with Updating database through Lazarus
« Reply #5 on: February 11, 2014, 12:52:56 am »
...the actual program does RUN but when it comes to this Add User procedure it doesn't work.
That's when you should use the debugger. Go to that line and press F5 then run inside Lazarus (press F9).

JackHatton

  • New member
  • *
  • Posts: 7
Re: Problems with Updating database through Lazarus
« Reply #6 on: February 11, 2014, 01:26:12 am »
Just tried doing this. It didn't change anything. I think it's suppose to pause the program or something? (not really sure) but yeah the same thing happened.  %)

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Problems with Updating database through Lazarus
« Reply #7 on: February 11, 2014, 01:36:41 am »
If it did not pause there then it did NOT reach that point. Place another one somewhere else like on db_Load('AccountsDatabase.db'); for instance. If it pauses then move using F8 (step over) or F7 (step into).

mangakissa

  • Hero Member
  • *****
  • Posts: 1090
Re: Problems with Updating database through Lazarus
« Reply #8 on: February 11, 2014, 10:14:32 am »
After changing the path to the database, I managed to add a new account. I could even login with the new created user. But creating another user causes a primary key error. Your variable 'NoOfUsers' has a wrong number.
Debugging is working normally (but crashes even more on console application).
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

JackHatton

  • New member
  • *
  • Posts: 7
Re: Problems with Updating database through Lazarus
« Reply #9 on: February 11, 2014, 05:59:47 pm »
Thanks for all the replies so far.

Okay. I found the reason why it wasn't working for me.

Basically, in my Tools > Options > Debugger I have the debugger type and path set to none. If I have it as normal then it works but when it is set to none it doesn't. However, I have a Try and Except statement and I was told that I needed to do this for my Try and Except statement to work. So at the moment I can only have one working or the other. Any suggestions as to how I can get them both working at the same time? :)

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: Problems with Updating database through Lazarus
« Reply #10 on: February 11, 2014, 06:41:40 pm »
Thanks for all the replies so far.

Okay. I found the reason why it wasn't working for me.

Basically, in my Tools > Options > Debugger I have the debugger type and path set to none. If I have it as normal then it works but when it is set to none it doesn't. However, I have a Try and Except statement and I was told that I needed to do this for my Try and Except statement to work. So at the moment I can only have one working or the other. Any suggestions as to how I can get them both working at the same time? :)

Well you either misunderstood or who ever told you that didn't understand something. In any case the bold is a false statement you having a debugger or not has nothing to do with your try...except block working, it never had.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Problems with Updating database through Lazarus
« Reply #11 on: February 11, 2014, 07:03:58 pm »
As Taazz has explained, the debugger works regardless of try and except blocks. So just go ahead and set your debugger and try it.

JackHatton

  • New member
  • *
  • Posts: 7
Re: Problems with Updating database through Lazarus
« Reply #12 on: February 11, 2014, 08:30:07 pm »
Okay, so I tried turning my debugger back on and the try and except thing wouldn't work. So I added the 'EConvertError' to the exceptions like this:

http://wiki.lazarus.freepascal.org/images/4/44/Debugger_options_language_exceptions.png

I think that was what I was supposed to do? But anyway it seems to have worked and now I seem to be having problems with the add procedure again...

I tried turning off the debugger again to see if it was fixed. Even though I thought this was what was the problem, it didn't work. So I don't know what the problem is but I had it working when I was at Sixth form when the debugger was on and then when i turned it off it didn't work. So I thought that was the reason but I am confused now. The error I get now is:


EDatabaseError: Attempt to write a readonly database

Guessing something is different here at home than at my school. Any suggestions?  :-\
« Last Edit: February 11, 2014, 08:32:04 pm by JackHatton »

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Problems with Updating database through Lazarus
« Reply #13 on: February 11, 2014, 09:01:39 pm »
Go to your project folder. Right-click on your database file (AccountsDatabase.db). Remove the check mark next to Read-only attribute.

Try again.

Edit:
You copied your files from a read-only source (like a CD/DVD?)
« Last Edit: February 11, 2014, 09:03:19 pm by engkin »

JackHatton

  • New member
  • *
  • Posts: 7
Re: Problems with Updating database through Lazarus
« Reply #14 on: February 11, 2014, 09:52:38 pm »
The read-only attribute wasn't checked. I made the database file through SQLite and have just been sending it through emails.

 

TinyPortal © 2005-2018