Page 1 of 1

Backup-Restore MariaDB

Posted: Tue May 01, 2018 7:19 pm
by jorge.posadas
Grupo

Actualmente estoy haciendo una apliacación sencilla, para un cliente usando HMG + MariaDB, y me surgen varias dudas:
1. Cuando creo una base de datos ¿en que directorio se crea físicamente esa base de datos?
2. Lleno algunas tablas con datos iniciales,para el funcionamiento de dicha aplicación, y ahora deseo "llevarme" esa base de datos a instalara con el cliente, ¿existe la posibilidad de hacer un COPY-PASTE? (por ejemplo con SQLite, puedo copiar una base de datos y simplemente "pegarla" en la PC de mi cliente sin problema alguno?
3. En el equipo de mi cliente, ¿es necesario instalar un administrador de base de datos, como HEADISQL o Navicat?
4. ¿Es posible que sin instalar algun administrador (vease inciso 3) se pueda correr mi aplicación en la pc de mi cliente?


Mucho agradeceré me auxilien con esas respuestas, de antemano agradezco la ayuda.

Re: Backup-Restore MariaDB

Posted: Wed May 02, 2018 2:14 am
by martingz
Jorge en Mariadb
1.- C:\Program Files (x86)\MariaDB 10.1\data o C:\Program Files\MariaDB 10.1\data

2.- En maria db y Mysql ,si usas el navicat puedes hacer un Dump sql file y ahi le dices que la estructura o la estructura y los datos, te genera un archivo .sql el cual posteriormente puedes ejecutar en el mismo navicat en la base de datos que quieras.

3.- te recomiendo instalar algun administrador, solo si puedes conectarte por fuera por medio del navicat para dar soporte no lo instales en el equipo local

4.- Si es posible, pero debes de tener las bases de datos y los usuarios dados de alta ( puedes hacerlo por fuera )

cualquier duda con todo gusto te ayudo

saludos

Re: Backup-Restore MariaDB

Posted: Wed May 16, 2018 11:49 pm
by edufloriv
Saludos amigos,

Vi su post y me interesó porque estoy realizando un primer proyecto con HMG + MariaDb. Me pregunto si podrían compartir una rutina de actualización de stock de un producto, tengo duda como se realiza el LOCK() de un registro, lei por alli que debo usar un campo auxiliar en la base de productos para poder realizar un UPDATE de forma segura.

Algo así como esto:

Code: Select all

PROC UpdateItemProd( cQueCode )

IF ProductoLibre( cQueCode )

   IF ProductoLock( 1 )

     ActualizarStock()
     ActualizarKardex()
     ...  // <- mas operaciones

     ProductoLock( 0 )

   ENDIF

ENDIF


FUNC ProductoLock( nSwitch )

   qSave := "UPDATE MAESARTI SET MA_LOCK VALUES ("+VALSTR(nSwitch)+") WHERE COD_ARTI = '"+cQueCode+"' "
   oSave := oServer:Query( qSave )
   IF oSave:NetErr()												
      MsgStop ( oSave:Error() )
      RETURN(.F.)
   ENDIF
   oSave:Destroy()

RETURN( .T. )


FUNC ProductoLibre( cQueCode )

LOCAL lLibre := .F.

   qRead := "SELECT MA_LOCK FROM MAESARTI WHERE COD_ARTI = '"+cQueCode+"'"
   oRead := oServer:Query( qSave )
   IF oRead:NetErr()
      MsgStop ( oRead:Error() )
      RETURN(lLibre)
   ENDIF
   oRow := oRead:GetRow(1)
   IF oRow:fieldGet("ma_lock") = 0
      lLibre := .T.
   ENDIF
   oRead:Destroy()

RETURN( lLibre )
¿ Es este enfoque correcto ?. Agradeceré sus indicaciones al respecto.


Saludos cordiales,

Re: Backup-Restore MariaDB

Posted: Thu May 17, 2018 5:47 am
by dragancesu
Just UPDATE like

Code: Select all

UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';
Lock table is not necessary

Re: Backup-Restore MariaDB

Posted: Thu May 17, 2018 4:21 pm
by jorge.posadas
Eduardo,

Yo apenas estoy haciendo mi primer proyecto con HMG+MariaDB, he trabajo con MS-SQL (de microsoft) y en cuanto a hacer un LOCK a un registro el que sabe mucho de eso es martingz, él puede ayudarte mucho en eso, sin embargo yo estoy pensando hacer una función que "simule" un lock, aun no lo tengo bien desarrollado pero es mi intención hacerlo para este proyecto que estoy haciendo.

Re: Backup-Restore MariaDB

Posted: Thu May 17, 2018 11:44 pm
by martingz
edufloriv , primero que nada debes usar el engine Innodb que es el mejor para bloqueos
y en tus prg, este ejemplo recore un grid de factura de compra, selecciona el articulo y lo bloquea, hasta que hacemos el update del registro


sQuery:=oServer:Query( "Start Transaction" ) inicia transacciones
If sQuery:NetErr()
MsgStop(sQuery:Error())
Return .f.
Endif
for y = 1 to altaentradas.Grid_1.ItemCount
aValues:=altaentradas.grid_1.item(y)
varexiste:=0
nQuery:=oServer:Query( "Select nombre,existencia,no_linea From Articulos where clave = '" + alltrim(aValues[1]) + "' for update" )
If nQuery:NetErr()
MsgStop(nQuery:Error())
rQuery:=oServer:Query( "Rollback" ) si hya error hace el rollback
If rQuery:NetErr()
MsgStop(rQuery:Error())
Return Nil
Endif
Return Nil
Endif
nRow:=nQuery:GetRow(1)
varexiste:=nRow:fieldGet("existencia") + val(aValues[3])
oQuery:=oServer:Query( "UPDATE Articulos SET existencia = " + str(varexiste) + " WHERE clave = '" + alltrim(aValues[1]) + "'" )
If oQuery:NetErr()
MsgStop(oQuery:Error())
rQuery:=oServer:Query( "Rollback" )
If rQuery:NetErr()
MsgStop(rQuery:Error())
Return Nil
Endif
rQuery:Destroy()
return nil
endif
oQuery:Destroy()
next
rQuery:=oServer:Query("Commit")

Re: Backup-Restore MariaDB

Posted: Fri May 18, 2018 3:19 am
by Rathinagiri
If you want to backup your database inside the program, you can use the following code, which creates a dump/big sql file. It also assumes that oDB is a public variable with a valid MySQL/MariaDB connection. It also uses the HMGMySQL Bridge library.

Code: Select all

#include <hmg.ch>


function backup_db( cFname )
   local aTable := {}
   local aTables := {}
   local tables := {}
   local structarr := {}
   local aData := {}
   local aRow := {}
   default cFName := 'backup.sql'
   tables := sql( oDB,"show tables")
   for i := 1 to len(tables)
      aadd(aTables,alltrim(tables[i,1]))
   next i
   i := 0
   tottables := len(aTables)
   set alter to &cFName
   set alter on

   for i := 1 to tottables
      WAIT WINDOW "Processing Table - " + aTables[ i ] + '( ' + alltrim( str( i ) ) + '/' + alltrim( str( tottables ) ) + ' )'   NOWAIT
      aTable := sql( oDB, 'show create table ' + aTables[ i ] )
      cCreateCommand := aTable[ 1, 2 ]
      ? alltrim( cCreateCommand ) + ';'
      aTable := sql( oDB, "show columns from " + aTables[ i ] )
      asize(structarr,0)
      for j := 1 to len(aTable)
         aadd( structarr, alltrim( aTable[ j, 1 ] ) )
      next j
      adata := {}
      adata := sql( oDB, "select * from " + alltrim( atables[i] ) )
      totrecords := len(aData)
      for j := 1 to totrecords
         cQStr := ''
         WAIT WINDOW "Now backing up Table - " + aTables[ i ] + '( ' + alltrim( str( i ) ) + '/' + alltrim( str( tottables ) ) + ' )' + ' Record ' + alltrim( str( j ) ) + ' of ' + alltrim( str( totrecords ) ) NOWAIT
         cQstr := cQstr + "insert into "+alltrim(aTables[i])+" ("
         for k := 1 to len(structarr)
            cQstr := cQstr + alltrim( structarr[ k ] )
            if k < len(structarr)
               cQstr := cQstr + ","
            endif
         next k
         cQstr := cQstr + ") values "
         aRow := aData[ j ]
         cQstr := cQstr + "("
         for k := 1 to len(aRow)
            cQstr := cQstr + c2sql(aRow[k])
            if k < len(aRow)
               cQstr := cQstr + ","
            endif
         next k
         cQstr := cQstr + ");"
         ? cQStr
      next j
      ?
   next i
   wait clear
   set alter to
return nil

Re: Backup-Restore MariaDB

Posted: Fri May 18, 2018 12:50 pm
by ASESORMIX
Estos ejemplos me caen del Cielo.
Gracias amigos por compartir sus conocimientos.