Liberty BASIC Community Forum
« Copying a database »

Welcome Guest. Please Login or Register.
Oct 18th, 2017, 07:58am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Copying a database  (Read 744 times)
LBcode
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 101
xx Copying a database
« Thread started on: Jan 10th, 2016, 4:46pm »

Can code be created in a LB program that would copy and save that database? I want it to be used as a backup or like a restore point for the program.
User IP Logged

metro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 194
xx Re: Copying a database
« Reply #1 on: Jan 10th, 2016, 6:36pm »

you may find these useful
https://lbpe.wikispaces.com/file.operations
https://basic.wikispaces.com/CopyFileFunction
User IP Logged

Win10 64 HP laptop + desktop Mint Linux 64bit
LBcode
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 101
xx Re: Copying a database
« Reply #2 on: Jan 10th, 2016, 7:41pm »

I had been to the CopyFileFunction link. The file.operations link seems to be what I will have to use. I was hoping I could copy and move a folder instead of individual files since it would be a lot easier. Thanks for your help metro.
User IP Logged

metro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 194
xx Re: Copying a database
« Reply #3 on: Jan 10th, 2016, 8:39pm »

sorry, thought one file for a DB
there maybe a better option than this
why not try a batch file.
you could use DefaultDir$ and MyDocument folders (or other destination)
create a *.bat file within your code and execute with the "RUN" command
using a wildcard you could copy all *.dat files from one folder to another
I have also used batch files to backup and compress or restore and decompress databases using arj
http://arj.sourceforge.net/
Code:

[MS-DOS] The COPY command
Syntax:

    COPY /Y /A/B [d:][path]filename /A/B [d:][path][filename] /V

Options

    /Y - Replace existing files without any confirmation prompt.
    /-Y - Displays a confirmation prompt before overwriting the existing files.
    /A - Copy ASCII files
    /B - Copy Binary files
    /V - Check if file was properly copied 


Code:
CSIDL.PERSONAL = 5    'My Documents Folder

myDocuments$ = GetSpecialfolder$(CSIDL.PERSONAL)

print "My Documents folder location is: "
print myDocuments$

if right$(myDocuments$,1)<>"\" then
    myDocuments$=myDocuments$+"\"
end if

open myDocuments$ + "testxxxx.txt" for output as #f
print #f, "Test"
close #f

end

Function GetSpecialfolder$(CSIDL)
    struct IDL,cb As Long, abID As short
    calldll #shell32, "SHGetSpecialFolderLocation",_
        0 as long, CSIDL as long, IDL as struct, ret as long
    if ret=0 then
        Path$ = Space$(512)
        id=IDL.cb.struct
        calldll #shell32, "SHGetPathFromIDListA",id as long, Path$ as ptr, ret as long
        GetSpecialfolder$ = Left$(Path$, InStr(Path$, Chr$(0)) - 1)
    else
        GetSpecialfolder$ = "Error"
    end if
    End Function 
« Last Edit: Jan 11th, 2016, 12:30am by metro » User IP Logged

Win10 64 HP laptop + desktop Mint Linux 64bit
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5543
xx Re: Copying a database
« Reply #4 on: Jan 11th, 2016, 02:49am »

Some times you are better staying within Liberty especially if you wish to catch errors. Unless you pipe the .bat results to a file you will never know if the file copy was successful.

Also Liberty has NAME command

NAME a$ AS b$

NAME StringExpr1 AS StringExpr2

Which allows files to be copied or renamed.

The thing about databases is that if you copy whole databases you are inevitably copying the error. So you need to keep multiple time stamped copies so you can go back in time.

This also leads you to record and save all of the database transactions in similar order so that you can backtrack to when things were ok and go forward transaction by transaction. So if there has been a lot of activity you don't have the whole days transactions to reenter.

I would write the transaction records to two files as I go rather than hope there is an error free file at the end of the day to copy.
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2280
xx Re: Copying a database
« Reply #5 on: Jan 11th, 2016, 11:51am »

I've got code lying around that can be modified to copy a whole folder instead of just one file. Let me look for it and get back to ya.
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
LBcode
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 101
xx Re: Copying a database
« Reply #6 on: Jan 11th, 2016, 1:02pm »

Thanks guys. I have to admit some of these things are over my head but I am trying hard and testing things to figure it all out. I have learned so much from you guys in such a short time and I really do appreciate all your help. Thanks a lot.
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2280
xx Re: Copying a database
« Reply #7 on: Jan 11th, 2016, 8:18pm »

Here's an example that uses the Windows Shell API to do the copy for us.

The only thing I'll note is that you MUST use full paths to files to do this. That's why I use the built-in DefaultDir$ variable.

Code:
srcPath$ = DefaultDir$ + "\bmp"
dstPath$ = DefaultDir$ + "\bmpcopy"
a =  CopyFolder(srcPath$, dstPath$)
If a = 0 then 
    print "Copy successful!"
Else
    print "Uh oh, something went wrong."
End If

Function CopyFolder(src$, dest$)
    FO.COPY = 2
    FOF.SILENT = 4
    FOF.NOCONFIRMATION = 16
    FOF.NOERRORUI = hexdec("400")
    FOF.NOCONFIRMMKDIR = hexdec("200")
    FOF.NO.UI = FOF.SILENT or FOF.NOCONFIRMATION _
        or FOF.NOERRORUI or FOF.NOCONFIRMMKDIR

    struct SHFILEOPSTRUCT,_
        hWnd as ulong,_
        wFunc as ulong,_
        pFrom$ as ptr,_
        pTo$ as ptr,_
        fFlags as long,_
        fAnyOperationsAborted as long,_
        hNameMappings as long,_
        lpszProgressTitle$ as long

    SHFILEOPSTRUCT.hWnd.struct = 0
    SHFILEOPSTRUCT.wFunc.struct = FO.COPY
    SHFILEOPSTRUCT.pFrom$.struct = src$ + chr$(0) + chr$(0)
    SHFILEOPSTRUCT.pTo$.struct = dest$ + chr$(0) + chr$(0)
    SHFILEOPSTRUCT.fFlags.struct = FOF.NO.UI
    SHFILEOPSTRUCT.hNameMappings.struct = 0
    SHFILEOPSTRUCT.lpszProgressTitle$.struct = ""

    CallDLL #shell32, "SHFileOperationA",_
    SHFILEOPSTRUCT as struct,_
    CopyFolder as long
End Function 
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
LBcode
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 101
xx Re: Copying a database
« Reply #8 on: Jan 12th, 2016, 04:29am »

Thanks Chris. I will work on it.
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2280
xx Re: Copying a database
« Reply #9 on: Jan 12th, 2016, 5:03pm »

Let us know if you have any questions, or if you need anything else!
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
LBcode
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 101
xx Re: Copying a database
« Reply #10 on: Jan 12th, 2016, 7:34pm »

Chris, You are the LB Maestro. Worked perfectly first time.
My database has 741 files in it and it copied them all in a flash.
Thank you!
« Last Edit: Jan 12th, 2016, 7:37pm by LBcode » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls