Topic: need help in deleting all the data in database

hello mvd developer & users,
can anybody help in my work: i want to erase all the data in database while the project is moved from one system to another.
that means the data enter in computer-1 will get deleted when the project is run on computer & in computer-2 you will get a fresh application.

Re: need help in deleting all the data in database

Hello,


Simply remove the file sqlite.db from project's folder.

Dmitry.

3 (edited by nrmuduli 2015-12-28 03:04:19)

Re: need help in deleting all the data in database

hello dmitry
your suggestion is really appreciated but the application is not running where MVD application Installed/ developed.

on removing sqlite.db, it shows error ' the database file not found' & asks for the location of the file.
pls. note that the above mention scenario is at end users where some end users may or may not contact for a new  fresh application. i want any sql script or anything that can check computer serial no & delete data in table on new computer.

awaiting for a reply
thanks....

4 (edited by mathmathou 2015-12-28 06:18:43)

Re: need help in deleting all the data in database

Hello nrmuduli,


Interesting question you are asking here.


If I understand correctly, you want your users to be able to copy/paste the install folder from one computer to another, but if MVD detects that it is running on a new system for the first time, all data from database must be erased.


Hmmmm....


Here is what I would do. All this must take place on the Form1 OnShow event because this is the first thing that happens when you launch application made with MVD (or whatever the name of your first form).


  • each time your application is launched, you must check if the computer unique ID is present in database

  • if present and the same as before, OK, the application runs normally

  • if present but not the same, then all tables must be erased and the application starts from fresh

  • if not present, then it's the same, clear all tables and start from fresh


With what MVD has to offer today, I would suggest using the getHardDiskSerial as unique ID. It's the best I can think of for the moment.


Then, this serial must be inserted into database, and checked each time the application starts.

Something like :

procedure Form1_OnShow (Sender: string; Action: string);
var
    unique_id : String;
    HD : String;
    known_id : Integer;
begin

    HD := GetHardDiskSerial('C'); //generate unique ID from hard drive serial
    known_id := SQLExecute('SELECT COUNT(id) FROM new_install WHERE unique_id="'+HD+'"'); //count this ID from database
        if known_id = 0 then //if result of count = 0 then this is not the same hard drive
            begin
                SQLExecute('DELETE FROM new_install'); //delete everything from all tables
                SQLExecute('DELETE FROM tableA');
                SQLExecute('DELETE FROM tableB');
                SQLExecute('DELETE FROM tableC');
                SQLExecute('DELETE FROM tableD');
                SQLExecute('INSERT INTO new_install(unique_id) VALUES("'+HD+'")'); //insert new ID for next start test
            end;
end;

What I've done here is :

  • generate an ID from the serial number of drive C

  • check in database if this serial is known

  • if not known then erase all tables and insert that ID in table new_install

  • on next start on the same computer, serial is known and nothing happens, the application starts normally

  • but if the folder has moved from computer A to computer B, the Hard Drive serial will change, and everything is erased with insertion of a new serial


CAUTION : this is far from perfect. For example, if Hard Drives are the same, I suppose that serial numbers will be different, but that's just a guess on my part. And what if the folder is copied on the second computer of the same user who needs his data to work ? Or if he moves his install folder from drive C to drive D on the same computer ?


Anyway, let see what the others think of all that.


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: need help in deleting all the data in database

hiii Mathias,

you guess exactly what i am talking about. your script works well and i have tested in 3 computers all goes well.
as  i am a mechanical engg so very new to MVD & sql, small scripts are also big thing for me. any way you saved my work.
it is almost perfect for any small personal database so don't think your script is imperfect.

kudos to you.

Re: need help in deleting all the data in database

You're welcome nrmuduli,


Happy new year smile


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor