Recent

Author Topic: Database  (Read 7155 times)

ThomasK1201

  • New Member
  • *
  • Posts: 31
Database
« on: March 23, 2015, 12:56:23 pm »
Hi guys!

For my instruction I have to make a program where students can practice all kinds of excercises about math.
To see how good they are at math, the teachers should be able to check that. So I need a database. There are some tutorials on the internet, but I dont understand if I need an extra program to make a database.
So my question: Do I need an extra program and, if not, what do I have to do to make a database?

Thomas.
« Last Edit: March 23, 2015, 01:09:25 pm by ThomasK1201 »

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Database
« Reply #1 on: March 23, 2015, 02:30:48 pm »
At first you have to make decision about what "database" you are going to use
a)Custom?
you can start reading from here http://wiki.freepascal.org/File_Handling_In_Pascal
b)sqlite?
start from here http://wiki.freepascal.org/SQLite and https://www.sqlite.org as well
c)mysql?
http://wiki.freepascal.org/mysql
d)firebird?
http://wiki.freepascal.org/firebird
e)mssql?

......
etc
in any case to make the database is not required an extra app
if your choice is a) then you are on your own
if your choice is b) or c) or any other well known db engine then you can use tools  to help you build your db structure etc
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

ThomasK1201

  • New Member
  • *
  • Posts: 31
Re: Database
« Reply #2 on: March 23, 2015, 11:01:54 pm »
I think I do something wrong. I typed the whole first example in Lazarus, but I get an error: Expected Unit, found Program. The very first word is done wrong (probably by myself) :|
By the way; I chose option A.

This is what I got right now:
Code: [Select]
program CreatFile;

uses
    Sysutils;

const
  C_FNAME = 'textfile.text';

var
  tf0ut: Textfile;

begin
  AssignFile(tf0ut, C_FNAME);

  {$I+}

  try
    rewrite(tf0ut);

    writeln(tf0ut, 'Hello textfile!');
    writeln(tf0ut, 'The answer to life, the universe and everything: ', 42)

    CloseFile(tf0ut);

  except
    on E: EInOutError do
       writeln('file handling error occured. Details: ', E.ClassName, '/' E.Message);
  end;

  writeln('file ' C_FNAME, 'created if all went ok. Press enter to stop.');
end.

An example of what Im not sure about is:
The piece of code C_FNAME. Should I replace NAME by a name given by me? Or goes it say that the name = ... (TextFile in the given example)?
« Last Edit: March 23, 2015, 11:03:51 pm by ThomasK1201 »

kapibara

  • Hero Member
  • *****
  • Posts: 656
Re: Database
« Reply #3 on: March 23, 2015, 11:35:07 pm »
You might want to check out the free book "Start Programming Using Object Pascal". Starting at page 48, filehandling is explained:

http://code-sd.com/books/startprog/

About.Com has many tutorials about filehandling:

http://delphi.about.com/od/fileio/
Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Database
« Reply #4 on: March 24, 2015, 07:27:29 am »
I think I do something wrong. I typed the whole first example in Lazarus, but I get an error: Expected Unit, found Program. The very first word is done wrong (probably by myself) :|
The code looks fine. It's that you seem to put it in the wrong file. By default what you see is .pas unit, the program itself resides in the .lpr which you can see and open in the Project Inspector dialog. That's where the compilation starts from.

ThomasK1201

  • New Member
  • *
  • Posts: 31
Re: Database
« Reply #5 on: March 24, 2015, 09:13:00 pm »
Ok I changed MainUnit.pas to MainUnit.lpr and it seems to work  :D
But how can I save the results in the database and how can I show those results in another form?

ThomasK1201

  • New Member
  • *
  • Posts: 31
Re: Database
« Reply #6 on: March 25, 2015, 10:39:51 pm »
Guys? I don't want to insist too much, but I'm pretty stuck and I have to hand in my project very soon..

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: Database
« Reply #7 on: March 26, 2015, 01:11:00 am »
have you looked here? http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/howtousedataawarecontrols.html

have you decided on what database to create/use?

being stuck is not a sin, but you might want to post what you have done.
Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

kapibara

  • Hero Member
  • *****
  • Posts: 656
Re: Database
« Reply #8 on: March 26, 2015, 07:39:17 am »
@ThomasK1201
It takes months to get some understanding of the SQL language and real database programming. What you need to do is to use simple flat files, ascii or binary, as storage. One advantage with that is that data access is very fast.

What are you going to store in your database?

And how will the content be produced? Is it just several text files with math questions? How will it be used later? Should it be possible to edit the data after storing it? Should it be possible to search the database?

Give us a detailed summary of all the requirements of the program. And what design you have come up with so far.
« Last Edit: March 26, 2015, 07:47:47 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

ThomasK1201

  • New Member
  • *
  • Posts: 31
Re: Database
« Reply #9 on: April 07, 2015, 09:09:06 pm »
Sorry I spend a few weeks to other things then this instruction, but Im back :S

In the database the results of the exercises made by students will be stored (Im not sure if this sentence is right :P). So the teacher should see what Pietje Puk wrote as answer on 1+1.

Thomas.

eny

  • Hero Member
  • *****
  • Posts: 1659
Re: Database
« Reply #10 on: April 08, 2015, 02:57:12 am »
A simple example to get you going: Pietje Puk en het Lazarus mysterie  :P

This is a SQLite3 example, so you also have to download the sqlite dll from here: https://www.sqlite.org/2015/sqlite-dll-win32-x86-3080803.zip.
Extract it and put it in the bin folder of the program.

For the rest: see all comments above.
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

 

TinyPortal © 2005-2018