DbCreateTemp() function

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

DbCreateTemp() function

Post by sudip »

Hi All,

Is there a way to create temporary table with HMG?

Previously I asked the same query in this forum. I received answer from G. Filatov to use hb_dbcreatetemp() function. I tried it with HMG, but it doesn't work. Apart from Minigui Extended, I tried with another Harbour library (gtwvg) and it compiles in both cases. So, if I am not wrong, I assume, hb_dbcreatetemp() is a Harbour function, may be a low level function (please correct me if I am wrong).

Whenever I tried to compile with hb_dbcreatetemp() with HMG, I got linking error.

I want to use it for:-
1) Storing array to temporary table for recent Report Generator, by Master Roberto Lopez.
2) Storing records from MySql query.
And also many other places.

So, it will be very helpful if we can create temporary table with HMG. (I am not sure, whether I shall place this post in this forum or place it in WishList. :? )

Thanks in advance.

With best regards.

Sudip
With best regards,
Sudip
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: DbCreateTemp() function

Post by dhaine_adp »

Is there a way to create temporary table with HMG?
Hi Sudip,

Creating a temporary file with HMG is not possible yet. If the Harbour gives an error try a UDF to accomplish the same. Anyway I have never tried to create a temporary file using hb_dbcreatetemp().

I used my own temporary file creation routine. Here take a look at my code:

Code: Select all

*************
function Test

   LOCAL aTempStru_ := {{"F1","C", 5,0},;    // Code
                        {"F2","C",40,0}}     // Description

   PRIVATE HomeFolder := "\APP\TEMP\"

   PRIVATE dbTemp

   IF .NOT. GetTempFile( @dbTemp, HomeFolder )
      msgstop( "Temporary file creation failed!", "Error" )
      RETURN NIL
   ENDIF
   DBCREATE( ( dbTemp ), aTempStru_, RDDSETDEFAULT() )
   RETURN NIL


//---------------------- UDF to create temp file -------------------------------

********************************************************************************
**  Function: GetTempFile()                                                   **
**   Purpose: Generate TempFile()                                             **
**                                                                            **
**  Category: File I/O                                                        **
**                                                                            **
**    Syntax: GetTempFile( cExp1, <cExp2> ) --> Temporary File                **
**                                                                            **
** Arguments: cExp2is the Target Folder to where the temporary file is to be  **
**              created.                                                      **
**            cExp1 is the variable to hold the temporary filename. This      **
**            variable is needed to be pass by reference.                     **
**                                                                            **
**   Returns: Full path and filename of the temporary file created.           **
**                                                                            **
**     Notes:                                                                 **
********************************************************************************
function GetTempFile( cFileName, cLocation )

   LOCAL nTimesAttemp := 0
   LOCAL lSuccess  := FALSE

   DEFAULT cLocation TO ( TrashHome )

   PRIVATE dbMakeTemp

   WHILE .NOT. lSuccess .OR. nTimesAttemp <= 100
      dbMakeTemp := cLocation + DaleAidTempFile()
      nTimesAttemp++
      IF FILE( ( "&dbMakeTemp" + ".DBF" ) )
         LOOP
      ENDIF
      lSuccess := TRUE
   END
   IF .NOT. lSuccess
      dbMakeTemp := ""
   ENDIF
   cFileName := dbMakeTemp
   RETURN lSuccess



********************************************************************************
**  Function: DaleAidTempFile()                                               **
**   Purpose: Generate a temporary file based on System Time.                 **
**                                                                            **
**    Syntax: cExp := DaleAidTempFile() --> returns value for cExp            **
** Arguments:                                                                 **
**   Returns: Returns 8 Characters Temporary Filename.                        **
**                                                                            **
**     Notes: The LOCAL Memory Variables:                                     **
**                                                                            **
**              AtomicSecs is equivalent to International System              **
**                units or (SI) as defined in 1967 by Atomic Standards where  **
**                1 second is equivalent to 9,192,631,770 oscillations, or    **
**                periods, of the radiation corresponding to the transition   **
**                between two hyperfine (closely spaced) energy states of     **
**                the Cesium-133 atom.                                        **
**                                                                            **
**              SecsInYear is equivalent to number of seconds in a year       **
**                disregarding the leap year.                                 **
**                                                                            **
**              Seconds is the number of seconds elapsed since midnight.      **
********************************************************************************
function DaleAidTempFile()

   LOCAL AtomicSecs := 9192631770,;
         Seconds    := LEFT(TIME(),2),;
         SecsInYear := 31449600,;
         Days2Secs  := 86400

   LOCAL JulianDate := DATE() - CTOD("01/01/"+ALLTRIM(STR(YEAR(DATE())))),;
         SinceBoY   := 0,;
         JulianTime := ""

   LOCAL RetVal  := "",;
         Modulus := ""
         
   SinceBoY   := JulianDate * Days2Secs
   JulianTime := ALLTRIM(STR(INT(SinceBoY / SecsInYear) * 100))
   Modulus    := ALLTRIM(STR(INT(AtomicSecs % SECONDS())))
   RetVal     := "DA" + RIGHT(JulianTime + Modulus + Seconds, 6)
   RETURN RetVal

Regards,

Danny
Regards,

Danny
Manila, Philippines
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: DbCreateTemp() function

Post by Rathinagiri »

As Roberto has assured, I think array feature would also be added in Report Generators. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: DbCreateTemp() function

Post by sudip »

Hi Danny,

Thanks a lot! :)

With best regards.

Sudip
With best regards,
Sudip
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: DbCreateTemp() function

Post by sudip »

rathinagiri wrote:As Roberto has assured, I think array feature would also be added in Report Generators. :)
Very good news!!! :)
Regards.
Sudip
With best regards,
Sudip
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: DbCreateTemp() function

Post by sudip »

Hello Danny,

Thank you very much. I really like your code. Excellent. :D

Regards.

Sudip
With best regards,
Sudip
claudiotedesco
Posts: 132
Joined: Thu Jul 31, 2008 12:05 pm

Re: DbCreateTemp() function

Post by claudiotedesco »

Cuando se trabaja en RED hay que tener algo en cuenta para generar los DB temp?

When working in a network must have something in mind to generate the temp DB?

Claudio
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: DbCreateTemp() function

Post by dhaine_adp »

Cuando se trabaja en RED hay que tener algo en cuenta para generar los DB temp?

When working in a network must have something in mind to generate the temp DB?

Claudio
Hola Claudio,

Como programador, me cree es su discreción si para crear el archivo temporal (s) si en la unidad local o en la unidad de red (compartido y / o carpetas públicas). Incluso puedes crear un archivo temporal en la unidad local y en la unidad de red al mismo tiempo. Entonces es también su trabajo para eliminar los archivo temporal (s) de la aplicación ha creado. Al eliminar completamente su programa depende de la lógica y el objetivo que desea lograr.

El GetTempFile () la función genera el nombre de archivo de 8 caracteres. Y como usted puede ver que sólo comprueba la existencia de ". DBF". La función de sí mismo, no crea el archivo y le dio un nombre de archivo. Ni siquiera la append ". DBF" a la extensión de nombre de archivo temporal.

Si modifica el código a algo como esto:

Code: Select all

**************************************************
function GetTempFile( cFileName, cLocation, cExt )

   LOCAL nTimesAttemp := 0
   LOCAL lSuccess  := .F.
   LOCAL lPutExt   := .F.

   DEFAULT cLocation TO ( TrashHome )
   DEFAULT cExt      TO ".DBF"

   PRIVATE dbMakeTemp

   lPutExt := cExt == ".DBF"    // tell the program not to append .dbf extension if is to be 
                                         // used for tables

   WHILE .NOT. lSuccess .OR. nTimesAttemp <= 100
      dbMakeTemp := cLocation + DaleAidTempFile()
      nTimesAttemp++
      IF FILE( ( "&dbMakeTemp" + cExt ) )
         LOOP
      ENDIF
      lSuccess := .T.
   END
   IF .NOT. lSuccess
      dbMakeTemp := ""
   ELSE
      IF lPutExt
         dbMakeTemp += cExt
      ENDIF
   ENDIF
      cFileName := dbMakeTemp
   RETURN lSuccess
Modificación que le daría el nombre de archivo temporal con extensión que desee.

La variable de memoria "TrashHome" es uno heredado privado declarado en la variable de mi Main() HMG Application.

Y, sin embargo, el parámetro <cLocation> dirá que el camino temporal se creará el archivo y la unidad de red no es una cuestión en absoluto. Para ilustrar ver la llamada a la función GetTempFile a continuación:

GetTempFile(@cFileName, "Z:\PUBLIC\Common \", ".TXT")
GetTempFile(@cPDFName, "C:\INFORMES\", ".PDF")
GetTempFile(@cExlFile, "Y:\VENTAS\PREDICCION\", ".XLS)
GetTempFile(@dbReport, "Z:\TEMP\") -> devuelve el nombre de archivo sin extensión. DCREATE () hará que la. DBF extensión.

Y para mí, mi principal razón para no crear los archivos temporales como se indica en la modificación de los códigos es simple, "Seguridad de Datos". Si la solicitud de choque debido a error en mi código, los archivos temporales sin una extensión no está asociado a ningún programa. Para los usuarios habituales, la recuperación de los imformation parece ser confuso. Y destacó que durante la formación y en mi CBTs' (equipo de formación, vídeos y presentaciones de diapositivas en power point) que encuentra en los archivos de la carpeta temporal que se especifican los archivos basura.

En realidad eso es una burda dispositivo de seguridad que hace mucho tiempo y hasta este momento no tengo ningún usuario que me dijo que los archivos temporales contiene información. Eso es porque el simple hecho de que no saben los pro y los resultados del programa. Si me necesita para recuperar información sobre los archivos temporales de la fecha y hora y firma de bytes del archivo le dirá qué tipo de archivo que fue. Por último, en la siguiente aplicación se ejecute con éxito y / o terminación, los archivos temporales se eliminarán por FERASE ().

Para más información acerca de los tipos de archivo, por favor visite: http://www.wotsit.org


Saludos cordiales,


Danny

--- English --------------------


Hello Claudio,

As programmer, I believed it is your discretion where to create the temp file(s) whether on the local drive or in the network drive (shared and or public folder). You can even create a temp file on local drive and on the network drive at the same time. Then it is also your job to delete those temp file(s) the application has created. When to delete completely depends on your program logic and goal that you want to accomplish.

The GetTempFile() function generates 8 characters filename. And as you can see it only checks for the existence of ".DBF ". The function itself does not create the actual file and gave you a file name. It does not even append the ".DBF" extension to the temp file name.

If you modify the code to something like this:

Code: Select all

See the code listing above
That modification would give you temp file name with extension that you wish.

The memory variable "TrashHome" is an inherrited private variable declared on the Main() of my HMG Application.

And yet, the parameter <cLocation> will tell which path the temp file will be created and the network drive issue is not an issue at all. To illustrate see the call to GetTempFile function below:

GetTempFile( @cFileName, "Z:\PUBLIC\COMMON\",".TXT" )
GetTempFile( @cPDFName, "C:\REPORTS\", ".PDF" )
GetTempFile( @cExlFile, "Y:\SALES\FORECAST\", ".XLS" )
GetTempFile( @dbReport, "Z:\TEMP\" ) --> returns filename without an extension. DCREATE() will put the .DBF extension.

And for me, my main reason for not creating the temp files as stated on those code modification above is simple, "Data Security". If the application crash due to bug on my code, those temp files without an extension is not associated with any programs. For regular users, retrieval of those imformation seems to be confusing. And I stressed that out during training and on my CBTs' (computer based training, videos and power point slide shows) that the files located on temporary folder I specified are junk files.

Actually that's a crude security that I device a long time ago and until this moment I don't have any user who told me that those temp files contains information. That's because of the simple fact that they don't know the ins and the out of the program. If I needed to recover information on those temporary files the date and time stamp and byte signature of the file will tell what type of file was that. Finally, on the next application run and or succesful termination, those temp files will be deleted by FERASE().

For more information regarding file types please visit: http://www.wotsit.org


Regards,


Danny
Regards,

Danny
Manila, Philippines
claudiotedesco
Posts: 132
Joined: Thu Jul 31, 2008 12:05 pm

Re: DbCreateTemp() function

Post by claudiotedesco »

Sudip

muchas gracias por tu consejo
lo voy a tomar en cuenta

CLAUDIO
Post Reply