Temporary table

Issues and Discussions related to Harbour

Moderator: Rathinagiri

franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Temporary table

Post by franco »

Hi all,
I am now trying to create reports like I did in visual fox.
to create in fox select * from table into cursor ...... I now have a temp file.
What I am doing in hmg3.2 is in samples,miscellaneous,temporary.table
aadd(adbf, {"itemcd", "c", 10, 0})
aadd(adbf, {"itemnm", "c", 40, 0})
aadd(adbf, {"rate", "n", 8, 2})

if !hb_dbcreatetemp("curItem", adbf)
msgbox("Cannot create temporary table: Item")
RELEASE WINDOW ALL
return nil
endif

if select("curItem") = 0
use curItem new
endif
select curItem
append blank .............. EG: or append from table for fieldname = 'something'
curItem->itemcd := "CD"
curItem->itemnm := "Compact Disc"
curItem->rate := 10.00
unlock
This all working fine but I wonder if the temp table is in memory as I can not find it
on my computer. Also if I create an index with same name it also is not visible.
My main concern is when i release the window is the table and index erased.

I could create a real table and index and erase later but more programing involved.

Thanks in advance ............ Franco ;)
All The Best,
Franco
Canada
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: temporary table

Post by Javier Tovar »

Hola Franco,

No te preocupes por si ocupa memoria o no, HMG hace que la memoria sea optimizada!, solo hay problemas de memoria si tienes una tarea que no termina, por ejemplo un while!!!. Por lo demás no te preocupes!!!

Saludos
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: temporary table

Post by franco »

sorry Javier, I have forgotten how to convert to english, so I cannot read your reply

Franco
All The Best,
Franco
Canada
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

temporary table

Post by Pablo César »

franco wrote:I now have a temp file.
What I am doing in hmg3.2 is in samples,miscellaneous,temporary.table
..//..
...all working fine but I wonder if the temp table is in memory as I can not find it
on my computer
Sorry Franco, but I am not understanding what you are trying to say. If you use hb_dbcreatetemp you will certainly create a temp file into the memory, not at disk. Why do you what to fin at your computer ? For what ?
franco wrote:Also if I create an index with same name it also is not visible
You can create index but with this TEMP file into the MEMORY will also not be saved at disk. Same case that dbf TEMP when is used hb_dbcreatetemp.
franco wrote:My main concern is when i release the window is the table and index erased.
Table and index will not be deleted because it doesn't exist as files saved at disk, only in the memory. But for what do you need these files saved ?
franco wrote:I could create a real table and index and erase later but more programing involved.
Not much work. Change hb_dbcreatetemp for hb_dbcreate
franco wrote:sorry Javier, I have forgotten how to convert to english, so I cannot read your reply
Franco, you posted at spanish section. :roll: (Topic is being chabge to the right place)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

temporary table

Post by Pablo César »

Franco, if you want to create files saved at disk, you can do this:

Code: Select all

#include <hmg.ch>

* Temporary Table Test by Grigory Filatov
* Slightly modified by Roberto Lopez

Function Main

CreateTemp()
   
   define window winMain ;
      at 0, 0 ;
      width 640 height 480 main ;
      title "Temporary Table" 
      
      DEFINE GRID brwTemp
         COL 0
         ROW 0
         WIDTH 600
         HEIGHT 340
         HEADERS {"Item Code", "Item Description", "Rate"}
         WIDTHS {125, 300, 100}
         ROWSOURCE "curItem"
         COLUMNFIELDS {"itemcd", "itemnm", "rate"}
      END GRID
      
   end window
   
   winMain.center
   winMain.activate

Return

function CreateTemp()
   local aDbf := {}
   aadd(adbf,   {"itemcd", "c",   10, 0})
   aadd(adbf,   {"itemnm", "c",   40,   0})
   aadd(adbf,   {"rate",   "n",    8, 2})
   
   if !hb_dbcreatetemp("curItem", adbf)
      msgbox("Cannot create temporary table: Item")
      RELEASE WINDOW ALL
      return nil
   endif
   
   if select("curItem") = 0
      use curItem new
   endif
   select curItem
   append blank
   curItem->itemcd := "CD"
   curItem->itemnm := "Compact Disc"
   curItem->rate := 10.00
   unlock
   append blank
   curItem->itemcd := "DVD"
   curItem->itemnm := "Digital Versatile Disc"
   curItem->rate := 20.00
   unlock
   append blank
   curItem->itemcd := "BD"
   curItem->itemnm := "Blu-ray Disc"
   curItem->rate := 30.00
   unlock
   
   COPY TO "TEST.DBF" // copying phisically the dbf in the memory to a file
   
   index on itemnm to TempNTX
   
   COPY TO "TEST.DBF" // copying already ordered by the index key
   
   Seek "Digital Versatile Disc"
   If Found()
      MsgInfo(str(Recno())+" - "+itemcd)
   Endif

return nil
Using COPY TO you will get same phisically in file.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

temporary table

Post by esgici »

franco wrote:I wonder if the temp table is in memory as I can not find it
on my computer. Also if I create an index with same name it also is not visible.
My main concern is when i release the window is the table and index erased.

I could create a real table and index and erase later but more programing involved.
Hi Franco

Here a little quote
Harbour\Changelog : wrote: 2009-02-16 17:44 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/dbinfo.ch
+ added DBI_ISTEMPORARY

* harbour/include/hbapirdd.h
* harbour/source/rdd/wafunc.c
+ added hb_rddCreateTableTemp() C function to create temporary
table which are automatically deleted on close. All indexes and
memo files for such tables are also in temporary files and
automatically deleted on close. Please remember that Harbour uses
OS functions to create temporary files so it's installation dependent
how much disk space is available for them. Some RDDs may also do
not create temporary files but keep everything in memory if they
decide it's more efficient.

* harbour/source/rdd/dbcmd.c
+ added .prg function to create temporary files:
hb_dbCreateTemp( <cAlias>, <aStruct>, <cRDD>, ;
<cCodePage>, <nConnection> ) -> <lSuccess>
Not all RDDs have to support it. It's verified by support for
DBI_ISTEMPORARY dbInfo() action.
I hope this will give you an idea :idea:

If you prefer doing everything manually, the TempFile() function of Harbour will be useful.

Happy HMG'ing :D
Last edited by esgici on Wed Sep 03, 2014 4:48 pm, edited 1 time in total.
Viva INTERNATIONAL HMG :D
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Temporary table

Post by Javier Tovar »

franco wrote:sorry Javier, I have forgotten how to convert to english, so I cannot read your reply
-1
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Temporary table

Post by franco »

Thanks to all,
I did not know I posted to Spanish
This whole post was to make sure temp files disappear as I use them a lot in making reports
and did not want them building up on hard drive.
Thanks again and all working well. .......... Franco
All The Best,
Franco
Canada
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Temporary table

Post by esgici »

Hi All
Above Harbour Changelog quote wrote:...Some RDDs may also do not create temporary files but keep
everything in memory if they decide it's more efficient.
Does anyone would clarify : "Which RDDs ?", and "when ?"

Another fuzzy point is : DBCreate() is OK for Clipper and Harbour, but I didn't found hb_dbcreate() function;
would you express me which library required for use it ?

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D
franco
Posts: 818
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Temporary table

Post by franco »

esgici,
I am not sure if this is dll but I must start with #include "hfcl.ch" or the hb_dbcreatetemp()
does not work

I am still having trouble with print grid from a table.
It does not make sense to create a temp table with some fields of a real table, then crate an array
to use print grid. maybe you can help with this.
or how do I just create an array with certain fields of a real table then sort on one of the
fields. I know this is easy but can not find example.
Thanks ............. Franco
All The Best,
Franco
Canada
Post Reply