Source language: Translate to:

Unique random generation

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Unique random generation

Postby smartmedia » Wed Apr 15, 2009 3:28 am

Hi..

My goal is:
Export some or all database records in a csv file. The database contains blob filed with images. How i will import again all the records and the images again from csv without problem.
My first thought is:
First create a field in the table beside the id auto inc field to keep a second unique id of the record which will used to track the image.
After export the csv to a file, i will create a loop, inside that loop i go to the first record and start extracting the images in a directory. Now i must give the image the same name as is in the second id relative to the record.
To avoid to problems that random id must be really unique. Maybe something like this.
gjs43dsfkas93dsfk45Lhi7984d6we98sjui or 239847345876293462938467287356348756823764

Any idea how i will create this random with 100% unique results...???
Or any idea how to export records that contains images inside and import them later without problem...???
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby Gaev » Wed Apr 15, 2009 5:22 am

smartmedia:

Why not make up the unique file names using the "unique" autoinc field value ... and append 1, 2, 3 etc. for each blob/image within the particular record.

This way, you also get a convenient automatic backward reference from the filename to the record where it was extracted from.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby HPW » Wed Apr 15, 2009 5:23 am

Maybe hpwGetGUID from hpwUtility can help.
Hans-Peter
User avatar
HPW
 
Posts: 2521
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Postby smartmedia » Wed Apr 15, 2009 5:57 am

Hi..

Thanks both of you.
I will follow Hans solution, is exactly what i want.
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

About exporting graphic files

Postby carlos torres » Wed Apr 15, 2009 6:07 am

Dear Smartmedia

I had similar problems exporting/using pictures for an evaluation program. At the begining I used to save the name of the pictures in a field and save all of those pictures in an specific folder. After that I tried to load them from a blob field BUT sometimes it fail loading/showing the pictures load then I had a lot of problems because some answers depende onf the picture information.

Now I return to the first solution (saving the name in a filed) loading the picture in picture filed (just for checking that it really belongs/match to the question). In order to export those pics I create a new table w/ the whole name of the picture (including path).

Here is part of the code I use
Code: Select all
...///to publish
   .debugbreakpoint ""
   SetVar "[SelectedFolder]" "[PathPublicar]"
   FolderBox "Select a folder to export Data:" "[SelectedFolder]"
   If "[SelectedFolder]" "<>" ""
      StrReplace "[SelectedFolder]" "\" "" "[SelectedFolder]"
      .../// if you want to keep that info
      RegistryWrite "HKEY_CURRENT_USER" "Software\YourAppName\Publish" "[SelectedFolder]"
      .../// if you have different type of files check folders
      ...///P_[TbName] P for Publish and TbName for the Table name you are using
      FolderExists "[SelectedFolder]\P_[tbName]\Audio" "[bExiste]"
      If "[bExiste]" "=" "FALSE"
         CreateFolder "[SelectedFolder]\P_[tbName]\Audio"
      EndIf
      FolderExists "[SelectedFolder]\P_[tbName]\Video" "[bExiste]"
      If "[bExiste]" "=" "FALSE"
         CreateFolder "[SelectedFolder]\P_[tbName]\Video"
      EndIf
      FolderExists "[SelectedFolder]\P_[tbName]\Data" "[bExiste]"
      If "[bExiste]" "=" "FALSE"
         CreateFolder "[SelectedFolder]\P_[tbName]\Data"
      EndIf
      ...///
      .../// COPY FILES
      dbpOpenTable "Quiz" "P_[tbName]" ""
      ...///
      Loop "1" "[Quiz.P_[tbName].$RecCount]" "[nG]"
      ..///
         dbpGotoRecord "Quiz" "P_[tbName]" "[nG]"
         ...///
         SetVar "[fromFile]" "[Quiz.P_[tbname].Archivo]"
          ...//////////
         ExtractFileExt "[Quiz.P_[tbname].Archivo]" "[EXT]"
         ExtractFileName "[Quiz.P_[tbname].Archivo]" "[ArchivoName]"
         ...///GRAFICAS
.          IfEx "[EXT]=[#34].JPG[#34] OR [EXT]=[#34].BMP[#34] OR [EXT]=[#34].GIF[#34] OR [EXT]=[#34].TIF[#34]"
.             SetVar "[toFile]" "[SelectedFolder]\P_[tbName]\GRAFICAS\[ArchivonAME]"
.          EndIf
           .../// VIDEOS
          IfEx "[EXT]=[#34].AVI[#34] OR [EXT]=[#34].MPG[#34] OR [EXT]=[#34].ASF[#34] OR [EXT]=[#34].WMV[#34]"
               SetVar "[toFile]" "[SelectedFolder]\P_[tbName]\VIDEO\[ArchivoName]"
          EndIf
          ...///AUDIO
          IfEx "[EXT]=[#34].MP3[#34] OR [EXT]=[#34].WAV[#34] OR [EXT]=[#34].MID[#34] "
              SetVar "[toFile]" "[SelectedFolder]\P_[tbName]\AUDIO\[ArchivoName]"
          EndIf
          ...AlertBox "before Copy [nG]" "fromFile=[fromFile]|toFile=[toFile]"
          FilecOPY "[fromFile]" "[toFile]"
      EndLoop
      .../////
      ...///copY dbase
   
      SetVar "[fromFile]" "[DbPath][DbName]"
      SetVar "[toFile]" "[SelectedFolder]\P_[tbName]\Data\Quiz.MDB"
      FileCopy "[fromFile]" "[toFile]"
      ...///
   Else
       .../// no selected folder 2 export
      Return
   EndIf


Hopefully it will help you

regards

carlost
User avatar
carlos torres
 
Posts: 289
Joined: Mon May 02, 2005 8:14 am
Location: Pamplona, Colombia

MAY BE....

Postby virger » Wed Apr 15, 2009 8:21 am

MAY BE SOME LIKE THIS

-----------------------------------
StrParse "[time]" ":" "[n]" "[x]"
Random "1357" "[rnd]"
StrReplace "[n3]" "[#32]" "[rnd]" "[n3]" ""
Random "54321" "[rnd]"
Math "[rnd]+12345" "" "[rnd]"
SetVar "[rnd]" "[year][monthnum][daynum][n1][n2][n3][rnd]"
----------------------------------------------------------------------

LOOK, USE
YEAR, MONTH, DAY
TIME
---------------------

PURA VIDA
FROM COSTA RICA
CENTRAL AMERICA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest