hb_dbDrop clarification

277 views
Skip to first unread message

Luigi Ferraris

unread,
Feb 11, 2016, 2:56:05 PM2/11/16
to Harbour Users
Hi guys,
I need a clarification as per subject. I'll assume to use rdd as parameter, but related with DBFNTX: give me a cent for this.

1st scenario.
There are (they exist) two files:path_filename.dbf and path_filename.ntx. I have used hb_DbDrop( path_filename.dbf, NIL, cRdd ).
It works fine: all files are removed.

2nd scenario.
There is (it exist) one file:path_filename.dbf. I have used hb_DbDrop( path_filename.dbf, NIL, cRdd ).
It works fine: the file is removed.

3rd scenario: I know can be considered strange, unusual... anyway
There is (it exists) one file:path_filename.ntx. I have used hb_DbDrop( path_filename.ntx, NIL, cRdd ).
It doesn't works: the file is not removed.

Is this the normal behaviour? I repeat: the third scenario can be unusual.

TIA
Luigi Ferraris

Luigi Ferraris

unread,
Feb 11, 2016, 2:59:49 PM2/11/16
to Harbour Users
A little errata corrige (copy&paste error)


Il giorno giovedì 11 febbraio 2016 20:56:05 UTC+1, Luigi Ferraris ha scritto:


3rd scenario: I know can be considered strange, unusual... anyway
There is (it exists) one file:path_filename.ntx. I have used hb_DbDrop( path_filename.ntx, NIL, cRdd ).
It doesn't works: the file is not removed.


There is (it exists) one file:path_filename.ntx. I have used hb_DbDrop( path_filename.dbf, NIL, cRdd ).
take a look to the file extension.

TIA
Luigi

Maurizio la Cecilia

unread,
Feb 12, 2016, 6:46:18 AM2/12/16
to harbou...@googlegroups.com
Hi Luigi,
I think that your third scenario needs a generic file deletion command/function.
dbDrop is a table based function and correctly ignore an index/memo file when not linked to a dbf.
Just my personal opinion.
--
Maurizio
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Przemyslaw Czerpak

unread,
Feb 12, 2016, 7:12:13 AM2/12/16
to harbou...@googlegroups.com
Hi Luigi,

This is [hb_]dbDrop() syntax:

hb_dbDrop( <cTableName> [, <cOrdBagName>] ;
[, <cRDD>] [, <hConnection>] ) -> <lRemoved>

If you want to remove indexes then you should use:

hb_dbDrop( "mydbf", "myindex1", "DBFNTX" )
hb_dbDrop( "mydbf", "myindex2", "DBFNTX" )
...

If you want to remove table, memo file and production
indexes then you should use:

hb_dbDrop( "mydbf",, "DBFNTX" )

In all cases I suggest to not use file name extensions and
allow RDD to use default ones. Such code is portable and
can work with any RDDs. In generic code you can also ignore
3-rd parameter above - if "DBFNTX" is not given then default
RDD set by rddSetDefault() is used.

Please note that when you remove index you should also pass
table name. In case of DBF* RDDs it's ignored by some other
RDDs may need table name to find index, i.e. such situation
happens in SQL RDBMs. Passing index name as first parameter
to [hb_]dbDrop() is a programmer bug. Some RDDs may try to
open table just to locate index storage and they will report
table corruption error or table does not exists.

Similar syntax is used by [hb_]dbExists().

best regards,
Przemek


On Thu, 11 Feb 2016, Luigi Ferraris wrote:
> Hi guys,
> I need a clarification as per subject. I'll assume to use rdd as parameter,
> but related with DBFNTX: give me a cent for this.
>
> 1st scenario.
> There are (they exist) two files:path_filename.dbf and path_filename.ntx. I
> have used hb_DbDrop( path_filename.dbf, NIL, cRdd ).
> It works fine: all files are removed.
>
> 2nd scenario.
> There is (it exist) one file:path_filename.dbf. I have used hb_DbDrop(
> path_filename.dbf, NIL, cRdd ).
> It works fine: the file is removed.
>
> 3rd scenario: *I know can be considered strange, unusual... anyway*
> There is (it exists) one file:path_filename.ntx. I have used hb_DbDrop(
> path_filename.ntx, NIL, cRdd ).
> It doesn't works: the file is not removed.
>
> Is this the normal behaviour? I repeat: the third scenario can be unusual.
>
> TIA
> Luigi Ferraris
>

Luigi Ferraris

unread,
Feb 12, 2016, 7:22:11 AM2/12/16
to harbou...@googlegroups.com
Il 12/02/2016 13.12, Przemyslaw Czerpak ha scritto:
> best regards,
> Przemek
and
Il 12/02/2016 12.45, Maurizio la Cecilia ha scritto:
> I think that your third scenario needs a generic file deletion
> command/function.
many thanks.

I will follow suggestions.
Regards
Luigi

Przemyslaw Czerpak

unread,
Feb 12, 2016, 7:48:50 AM2/12/16
to harbou...@googlegroups.com
On Fri, 12 Feb 2016, Luigi Ferraris wrote:

Hi,

> Il 12/02/2016 12.45, Maurizio la Cecilia ha scritto:
> >I think that your third scenario needs a generic file deletion
> >command/function.
> many thanks.
>
> I will follow suggestions.

Just to clarify.
Using generic file io functions to delete index files is not
good idea for portable programs. If you know table name then
use:
hb_dbDrop( cTablePathName, cIndexPathName )
If you do not know table name then use:
hb_dbDrop( , cIndexPathName )

best regards,
Przemek

Maurizio la Cecilia

unread,
Feb 12, 2016, 6:40:10 PM2/12/16
to harbou...@googlegroups.com
Thanks, Przemek.
I wasn't aware of all the hb_dbDrop() parameters.
Best regards.
--
Maurizio

Luigi Ferraris

unread,
Dec 2, 2016, 12:34:15 PM12/2/16
to Harbour Users
Hi Przemek


Il giorno venerdì 12 febbraio 2016 13:48:50 UTC+1, druzus ha scritto:

If you do not know table name then use:
   hb_dbDrop( , cIndexPathName )


it seems this doesn't works as espected (do not remove index file ). I have used this workaround

FOR EACH cNtxName IN aListOfIndex
   IF hb_fileExists( <cDbfName> )
      hb_dbDrop( <cDbfName>, <cNtxName> )
   ELSE
      hb_vfErase( <cNtxName> )
   END IF
NEXT


I'm investingating more.
Luigi
 

Luigi Ferraris

unread,
Dec 2, 2016, 12:49:51 PM12/2/16
to harbou...@googlegroups.com
Il 02/12/2016 18.34, Luigi Ferraris ha scritto:
it seems this doesn't works as espected (do not remove index file ). I have used this workaround

FOR EACH cNtxName IN aListOfIndex
   IF hb_fileExists( <cDbfName> )
      hb_dbDrop( <cDbfName>, <cNtxName> )
   ELSE
      hb_vfErase( <cNtxName> )
   END IF
NEXT


lost a piece of code, sorry:


FOR EACH cNtxName IN aListOfIndex
   IF hb_fileExists( <cDbfName> )
      hb_dbDrop( <cDbfName>, <cNtxName> )
   ELSE
      hb_vfErase( <cNtxName> )
   END IF
NEXT
hb_dbDrop( <cDbfName> )

else .dbf is not removed

Luigi
Reply all
Reply to author
Forward
0 new messages