DBF to array, or memory

This forum is for eXpress++ general support.
Message
Author
Victorio
Posts: 638
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

DBF to array, or memory

#1 Post by Victorio »

I am searching if in Alaska or eXpress exist some function to create array from database, or read content of database to memory. (some like array2csv but type dbf2array)
I need open database and have its content in memory, but database after open and read must be closed in short time, because other user need exclusive access to it.
I do not need write to database, only have open it in memory without need create its copy to hdd and in read only mode.

Now I have this with copy (Filecopy) dbf and cdx to temporary database and then open this temporary database. Time to filecopy is short about 1-3 seconds, but I do not want always creating some teporary files.

I thinking about create array and read content dbf to this array and show this array by DATA with DCBROWSECOL...
Or ideal will be read data from database, close dbf, and have data in memory and sometimes can "refresh" data again from dbf with short open and close dbf.

I think that such a solution exists, but I do not know, where can found solution.

One graphical software in our office work with graphical maps , this read from file, and this file is closed, and program write to i only when save changes.
So this is sometimes problem, because in network environment I do not know, who work with same datafile and two users can rewrite our data.

User avatar
rdonnay
Site Admin
Posts: 4828
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DBF to array, or memory

#2 Post by rdonnay »

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], oBrowse, aData[0], aFields, nFields, i

DC_LoadRdds()

USE vl800490vfp ALIAS 'TEST' VIA 'FOXCDX'

aFields := TEST->(dbStruct())
nFields := Len(aFields)

wtf aFields

DO WHILE !TEST->(Eof())
  AAdd(aData,TEST->(Scatter()))
  TEST->(dbSkip())
ENDDO

@ 0,0 DCBROWSE oBrowse DATA aData SIZE 120,30

FOR i := 1 TO nFields
  DCBROWSECOL ELEMENT i HEADER aFields[i,1] WIDTH aFields[i,3] PARENT oBrowse
NEXT

DCREAD GUI FIT TITLE 'Browsing Database as an Array'

RETURN nil

* -----------

PROC appsys ; RETURN
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4828
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DBF to array, or memory

#3 Post by rdonnay »

Here is another method:

Code: Select all

#INCLUDE "dcdialog.CH"

FUNCTION Main()

LOCAL GetList[0], oBrowse, aData[0], oData, aFields, nFields, i

DC_LoadRdds()

USE vl800490vfp ALIAS 'TEST' VIA 'FOXCDX'

aFields := TEST->(dbStruct())
nFields := Len(aFields)

wtf aFields

DO WHILE !TEST->(Eof())
  oData := DataObject():new()
  FOR i := 1 TO nFields
    oData:&(aFields[i,1]) := TEST->(FieldGet(i))
  NEXT
  AAdd(aData,oData)
  TEST->(dbSkip())
ENDDO

@ 0,0 DCBROWSE oBrowse DATA aData SIZE 120,30

FOR i := 1 TO nFields
  DCBROWSECOL OBJECTVAR (aFields[i,1]) HEADER aFields[i,1] WIDTH aFields[i,3] PARENT oBrowse
NEXT

DCREAD GUI FIT TITLE 'Browsing Database as an Array'

RETURN nil

* -----------

PROC appsys ; RETURN
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1439
Joined: Wed Feb 24, 2010 3:44 pm

Re: DBF to array, or memory

#4 Post by Auge_Ohr »

hi,
Victorio wrote:So this is sometimes problem, because in network environment I do not know, who work with same datafile and two users can rewrite our data.
are you Boss of the Company ?

i wonder what you are try to do. you try to HACK a DBF which is in EXCLUSIVE Mode.
even if you got the Chance to "copy" it what happened to other App if they try to access ?

Limitation on Network mean that you do NOT have the Right to access it.
i will not give any Tips to someone who want to HACK Database where User have no Access.
greetings by OHR
Jimmy

Victorio
Posts: 638
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: DBF to array, or memory

#5 Post by Victorio »

Roger, thank you very much for tips and source. I must test it and I am sure this will work .

Jimmy : no, I am not boss :P , but I have exclusive access to LAN as administrator and also to all databases as developer of some additional software for our office.
But exist some old software (programmed before 10-12 years ), which still use in our company - office.
Because maintenance this old software was complicated, and I have not source codes, we need bypass some problems with it.
Problematic database in not in exclusive everytime, but only for short time when control structure and eventually change structure, after it close and open again as shared.

"even if you got the Chance to "copy" it what happened to other App if they try to access ?"
good remark : yes it may be problem, small chance but exist. When I copy, other app crash with access denied.
To prevent this I need open dbf for the shortest time as possible. For this my app first test if dbf is identical with my "shared" copy, and only when no, try copy it.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: DBF to array, or memory

#6 Post by Eugene Lutsenko »

You just need to check a file is open or not without trying to access it or copy. This check works even if the file someone is used and does not prevent him to do it. If the file is opened it is necessary to wait, when it will be closed. If the file is closed, feel free to copy.

Code: Select all

**********************************************************
******** Проверка, открыт файл или нет (от Роджера Доннея)
**********************************************************
FUNCTION IsFileOpened( cFileName )

*#include "fileio.ch"
LOCAL lStatus := .F.       // Файл cFileName закрыт
LOCAL nHandle := FOpen( cFileName, FO_READWRITE+FO_DENYWRITE )

IF nHandle <= 0
  lStatus := .T.           // Файл cFileName открыт или его нет
ELSE
  FClose(nHandle)
ENDIF

RETURN lStatus
[/size]

But how to make the copy process did not prevent access to the database of the program which with it works, I don't know. It is hoped that if the copy process is fast, then the probability of failure will be very small.

And it is possible to collect statistics of the time and duration for the treatment of the native program without copying it, and only checking the database is open or not. And then copy it in those time periods when the probability of treatment of the main program is minimal. These statistics have all the time to update, can be cumulative, but the oldest periods to remove.

Victorio
Posts: 638
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: DBF to array, or memory

#7 Post by Victorio »

Yes, You are right, I must put to program some control if someone use dbf file.

I can minimalise collision users with one dbf, because "other" app first when start open set several dbf files, after it user must click to button and select function, and after again other button.
Very very speed user need several seconds for it. This time can be minimal 5-10 seconds.
This time from open set dbf to open one problematic database as exclusive is enough for me to get copy from this dbf.
Collision can be only when copy process need more time.

Thanks for tips, ideas,... I must try it.

By the way, this forum is super. With the help of Roger, Jimmy, Eugene, Tom, ... sorry, if I missed someone I could solve many many problems when programming. :clap:

User avatar
Auge_Ohr
Posts: 1439
Joined: Wed Feb 24, 2010 3:44 pm

Re: DBF to array, or memory

#8 Post by Auge_Ohr »

Victorio wrote:But exist some old software (programmed before 10-12 years ), which still use in our company - office.
Because maintenance this old software was complicated, and I have not source codes, we need bypass some problems with it.
as you talk about DBF : are they Cl*pper Apps ?
if Author give you Rights you can decompile Cl*pper EXE/OVL ... depend on Linker (Plink86 / Blinker up to v2.x)

... but i still do not understand why you want to access a Copy of "external" DBF while running ?
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4828
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DBF to array, or memory

#9 Post by rdonnay »

Code: Select all

depend on Linker (Plink86 / Blinker
Yes, I have been successful decompiling some old Clipper apps.
This is possible if the compression of Blinker was not used.
The eXpress train is coming - and it has more cars.

Victorio
Posts: 638
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: DBF to array, or memory

#10 Post by Victorio »

Jimmy, no, "other" app is in Visual Foxpro 9.

"... but i still do not understand why you want to access a Copy of "external" DBF while running ?"

Because VFP app and my app use same databases. VFP read and write to databases, my app only read access.
Everything works good, because dbf are in VFP open SHARED, only one dbf author open for short time as exclusive. This is problem. He promised me, to change also this to set as SHARED, but he is ill and changes was not realised.
I do not exactly know, why he need exclusive, maybe reindex, or pack, or some other operation, fact is that after several seconds database is open shared.

Post Reply