Page 2 of 2

Re: questions manage dbf

PostPosted: Thu Oct 04, 2018 4:05 pm
by Silvio.Falconi
should I use tdatabase or mysql or ads?
I do not have to manage large archives for which it is necessary in my opinion mysql or ads, now I have the only need to use archives that I can open from another part because I explain you I created a function that sends messages on Telegram, to inform teachers of the school, and this function ( on a application) is always active because at a time interval it reads the requests on telegram and responds automatically, so it needs to read information from two archives that could be used by the same application by an operator in an office.

Re: questions manage dbf

PostPosted: Thu Oct 04, 2018 6:05 pm
by James Bott
I agree, you do not need to use SQL for small workgroups. I suggest that you start with TDatabase then you may want to upgrade to my TData class. TData adds some features like automatic sequential IDs and reuse of deleted records.

I will put together some sample code to get you started.

James

Re: questions manage dbf

PostPosted: Fri Oct 05, 2018 12:02 am
by James Bott
OK, here is a sample program showing how easy it is to create and use database objects. We are not using TDatabase directly, but rather creating a customer class which inherits from TDatabase. Later I will show you how to create multiple database objects that eliminate repetitive code. -James

Code: Select all  Expand view
/*
Purpose  : Sample OOP using TDatabase
Program  : Test05.prg
Author   : James Bott, jbott@compuserve.com
Date     : 10/04/2018 04:49:55 PM
Company  : Intellitech
Copyright: Copyright © 2017 Intellitech. All rights reserved.
Language : Fivewin/xHarbour
Updated  :
Notes    : Use the customer.dbf in the FWH\samples directory

*/


#include "fivewin.ch"


Function Main()
   Local oCustomer

   // Houekeeping
   REQUEST DBFCDX
   rddsetdefault( "DBFCDX" )
   SET EXCLUSIVE OFF
   SET(_SET_AUTOPEN, .T. )
   SET default to ".\"
   
   // Opens the dbf shared
   // New workarea is automaticlly selected
   // Loads all fields of the first record into an array
   // No scatter/gather routines needed
   oCustomer:= TCustomer():New()
   
   msgInfo(oCustomer:First)  
   
   // Replace the data in the array for this field
   oCustomer:First := "
Silvio"
   
   // lock record, save buffer, and unlock  
   // oCustomer:save()
   
   msgInfo(oCustomer:First)
   oCustomer:skip()
   msgInfo(oCustomer:First)
   
   oCustomer:end()

Return nil

//---------------------------------------------------------------------------//

CLASS TCustomer from TDatabase
   Method New()
Endclass

Method New() CLASS TCustomer
   Super:New(,"
customer","DBFCDX",.t.)
   ::use()
   // Note: Since you are using DBFCDX, the index file is automatically opened
   // and the first index is selected and it is at the first record.
Return self

//---------------------------------------------------------------------------//

// EOF