fbpx
Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1
  • 2

TOPIC: VFP9 with CDX concerns ?

[ SOLVED ] VFP9 with CDX concerns ? 1 month 6 days ago #12765

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Hello all!

Tried VFP solution and it's great! I just have some inquiries and concerns :

1. Does DBF with CDX working ? because DBF created with VFP9 with CDX getting corrupted
once I issued a replace command on a field. the corrupted DBF cant be open in VFP9 but I
open it on VFP5.

2. Any tuts links how to maniputate DBF files directly in C# using XSharp library.

Many thanks ^_^Y
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

Last edit: by DexterZ. Reason: [ SOLVED ]

VFP9 with CDX concerns ? 1 month 6 days ago #12778

  robert's Avatar robert Offline Posts: 1502
Dexter,
We could really use some more info w.r.t. #1. Do you have example code ?
For #2: No tutorials yet

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12779

  wriedmann's Avatar wriedmann Away Posts: 2123
Hi Dexter,

Any tuts links how to maniputate DBF files directly in C# using XSharp library.

I have some small sample applications that use DBF files from X# Core dialect.
What do you need? A WinForms application that can access DBF files?
Only read access or also write? Using a DataTable object is enough?
Wolfgang
P.S. my background is Clipper and VO, not VFP
Wolfgang Riedmann
Meran, South Tyrol, Italy

www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12786

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Inquiry 1 : Here's my test code

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text

FUNCTION Start() AS VOID STRICT
    
    SELECT 0 
    USE "C:\TEMP\TESTDB.DBF" SHARED
    
    APPEND BLANK
    *   
    Replace DOC_TYPE with "RR"  ,;
            DOC_NO   with "12345"    
    
    WAIT "Press a key to exit ^_^"
    
RETURN

The Problem :

1, Using the above code accessing TESTDB.DBF "without" CDX it's ok


2. But if I put a CDX tag on DBF, it appended a blank records only
and did not replace the value both fields are still empty.

ex: INDEX ON DOC_TYPE+DOC_NO TAG DOC_NO

Inquiry 2 : XSharp in C#

I tried the following code inside C# and working correctly but that it :) I can't find the Replace command.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using XSharp;
using XSharp.Core;
using XSharp.RT;
using XSharp.VFP;

using XDb = XSharp.CoreDb;

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            XDb.SetSelect(1);
            XDb.UseArea(true, "DBFVFP", @"C:\TEMP\TESTDB.DBF", "TESTDB", true, false);            
            XDb.Append(true);
            
        }
    }
}


Thank you WriedMan+Robert ^_^y

Dex
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12787

  Chris's Avatar Chris Offline Posts: 1668
Could you please send also the dbf and cdx files so we can reproduce the problem here? Thanks!
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12788

  robert's Avatar robert Offline Posts: 1502
Dexter,

Dex,

1) What happens if you close the file properly at the end of your code ?

2) To write values with the CoreDb layer you need to call FieldPut() with the column number and value.. Also don't forget to commit the changes and close the dbf.:
XDb.Commit()
XDb.CloseArea()


Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12789

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Thanks Chris! The attached zipped file includes TestDb.DBF and TestDb.CDX
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/
Attachments:

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12790

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Cool! I'll play with it more, many thanks Robert !
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 6 days ago #12799

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
YAY! Many thank's Robert the code below works like a charm even in share mode side by side with VFP9 and records with CDX also reflects in VFP9! ^_^y

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using XSharp;
using XSharp.Core;
using XSharp.RT;
using XSharp.VFP;

using XDb = XSharp.CoreDb;

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {

            //--> Table work area
            //
            XDb.SetSelect(1);
           
            //-> Open table in shared mode
            //
            if (! XDb.UseArea(true, "DBFVFP", @"C:\TEMP\TESTDB.DBF", "TESTDB", true, false) )
            {
                MessageBox.Show("Unable to open table TESTDB.DBF");
            }
            else
            {
                //--> Add blank record
                //
                XDb.Append(true);

                //-->  Update fields value
                //
                XDb.FieldPut(1, "DM");       // DOC_TYPE
                XDb.FieldPut(2, "DM-12345"); // DOC_NO

                //--> Write to disk 
                //
                XDb.CommitAll();

                //--> Close table
                //
                XDb.CloseArea();
            }
          
        }
    }
}
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 5 days ago #12815

  lumberjack's Avatar lumberjack Offline Posts: 641
Hi Dexter,

DexterZ wrote: YAY! Many thank's Robert the code below works like a charm even in share mode side by side with VFP9 and records with CDX also reflects in VFP9! ^_^y

And the $1m effort to convert that to X#... :cheer:
using System
using System.Collections.Generic
using System.Linq
using System.Threading.Tasks
using System.Windows.Forms

using XSharp.VFP
using XDb = XSharp.CoreDb

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread];
FUNCTION Start() AS VOID
    //--> Table work area
    XDb.SetSelect(1)
    //-> Open table in shared mode
    if ! XDb.UseArea(true, "DBFVFP", @"C:\TEMP\TESTDB.DBF", "TESTDB", true, false)
        MessageBox.Show("Unable to open table TESTDB.DBF")
    else
         //--> Add blank record
         XDb.Append(true)
         //-->  Update fields value
         XDb.FieldPut(1, "DM");       // DOC_TYPE
         XDb.FieldPut(2, "DM-12345"); // DOC_NO
         //--> Write to disk 
         XDb.CommitAll()
         //--> Close table
         XDb.CloseArea()
     endif
RETURN
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

Last edit: by lumberjack.

VFP9 with CDX concerns ? 1 month 5 days ago #12826

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Nyaha,

I tried using X# VFP dialoect solution but FAILED ( see my code in X# on VFP dialect from my post ), and I tried calling it directly to C# and has no problem : - )

My I idea is to write a library that can manipulate Dbf using X# any dialects will do as Im very familiar in dBase,Clipper,Harbor,FoxBase and VFP 2.5 to 9 : ) and call that library to any .NET application C#,VB,F# ^_^Y

Cheers Sir Johan ^_^y
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12838

  lumberjack's Avatar lumberjack Offline Posts: 641
Hi Dexter,

DexterZ wrote: I tried using X# VFP dialoect solution but FAILED ( see my code in X# on VFP dialect from my post ), and I tried calling it directly to C# and has no problem : - )
My I idea is to write a library that can manipulate Dbf using X# any dialects will do as Im very familiar in dBase,Clipper,Harbor,FoxBase and VFP 2.5 to 9 : ) and call that library to any .NET application C#,VB,F# ^_^Y

Only real problem I see with your original code is the REPLACE command.

If you FieldPut("ColName", ColValue) you should be fine. And just add a COMMIT afterwards.
______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12843

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Hello Johan,

[ "Only real problem I see with your original code is the REPLACE command" ]

If I run the code below using Foxpro Console Application solution with the attached DBF/CDX ( kindly use my attachement replied to Chris) and browse it, the data is still empty, because it failed the reason I tried to use C# directly.

FUNCTION Start() AS VOID STRICT
    
    SELECT 0 
    USE "C:\TEMP\TESTDB.DBF" SHARED
    
    APPEND BLANK
    *   
    Replace DOC_TYPE with "RR"  ,;
            DOC_NO   with "12345"    
    
    WAIT "Press a key to exit ^_^"
    
RETURN


[ "If you FieldPut("ColName", ColValue) you should be fine. And just add a COMMIT afterwards." ]

I don't think FieldPut has a "field name" overloads? it only accept "field index"

Dex
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12845

  Karl-Heinz's Avatar Karl-Heinz Offline Posts: 502
Hi Dex,

simply add a COMMIT and CLOSE command, similar you´re already doing in you C# app ;-)
FUNCTION Start() AS VOID STRICT
    
    SELECT 0 
    USE "C:\TEMP\TESTDB.DBF" SHARED
    
    APPEND BLANK
    *   
    Replace DOC_TYPE with "RR"  ,;
            DOC_NO   with "12345"   

   commit  // <-------------

   close  // <--------------
    
    WAIT "Press a key to exit ^_^"
    
RETURN

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12848

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
YAY! You hit the nail on the head Karl! ^_^Y

The thing is COMMIT and CLOSE are not necessary in FoxBase/FoxPro/VFP to reflect the changes, the reason I didn't think to add commit and close ; ) good to know it's needed in X#

Thank you guyz for all the help,

Dex

[ CASE CLOSED ]
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12850

  FoxProMatt's Avatar FoxProMatt Offline Posts: 346
Indeed, in VFP we do not use any commands to "commit" data changes to the current row, *EXCEPT* if we have enabled Table Buffering. In this case, you have to call TableUpdate() to write the changes.

I know that a LOT of people use Table Buffering in VFP apps, so X# will have to address this issue for full FoxPro compatibility.

Here are the main functions involved in Table Buffering:

*-- Specifies property settings for a Visual FoxPro table or a cursor.
CURSORSETPROP( cProperty [, eExpression] [,cTableAlias | nWorkArea])

*-- Retrieves the current property settings for a Visual FoxPro table or a cursor.  
CURSORGETPROP(cProperty [, nWorkArea | cTableAlias])

*-- Commits changes made to a buffered row, a buffered table, cursor, or cursor adapter.
TABLEUPDATE( [nRows [, lForce]] [, cTableAlias | nWorkArea] [, cErrorArray] )

 *-- Discards changes made to a buffered row or a buffered table or cursor and restores the OLDVAL( ) data for remote cursors and the current disk values for local tables and cursors.
TABLEREVERT( [lAllRows [, cTableAlias | nWorkArea] ] )


Here is an example which shows several of the functions that are in play when Table Buffering is used:

*---------------------------------------------------------------*
*  If any changes have been made to the table or record, prompt the
*  user to save the changes.  If the user says 'yes,' all changes
*  are saved.  Any changes made to the data by other users after
*  this user made the change and before the change was committed
*  will be lost.
*
*  RETURNS NUMERIC VALUES:
*    0 -- No Changes Made to the Current Values
*    1 -- Successfully Made All User Changes
*	 2 -- Unable to Write One or More User-Specifed Changes to Table
*---------------------------------------------------------------*

* Declare constants & variables
#define SAVECHG_LOC 'Do you want to save your changes?'
#define SAVECHG2_LOC 'Save Changes'
#define NOBUFF_LOC2 'Data buffering is not enabled.'

LOCAL lnChoice, llMadeChange, lnSuccess
m.llMadeChange = .F.
m.lnSuccess = 0

* If the user has changed anything, prompt to save or discard changes
DO CASE
	CASE INLIST(CURSORGETPROP('Buffering'), 2,3) && Row Buffering
		IF '2' $ GETFLDSTATE(-1)
			m.llMadeChange = .T.
		ENDIF
	CASE INLIST(CURSORGETPROP('Buffering'), 4,5) && Table Buffering
		IF GETNEXTMODIFIED(0) > 0
			m.llMadeChange = .T.
		ENDIF
	OTHERWISE
		WAIT WINDOW NOBUFF_LOC NOWAIT
ENDCASE

IF m.llMadeChange
	m.lnChoice = MESSAGEBOX(SAVECHG_LOC, 4+32, SAVECHG2_LOC)
	IF m.lnChoice = 6 && Yes
		m.lnSuccess = IIF(TABLEUPDATE(.T.,.T.), 1, 2)
	ELSE
		=TABLEREVERT(.T.)
	ENDIF
ENDIF	
RETURN m.lnSuccess

Please Log in or Create an account to join the conversation.

Last edit: by FoxProMatt.

VFP9 with CDX concerns ? 1 month 4 days ago #12855

  Karl-Heinz's Avatar Karl-Heinz Offline Posts: 502
Matt,

it´s been ages ago that i used DBF commands. Just to be more precise, the current behaviour is: Doing it without a COMMIT and without a CLOSE the values are not written. But the values are written when i do either a COMMIT or a CLOSE.

BTW. Fox knows the command FLUSH, isn ´t that the same as COMMIT ?

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12856

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Hi Matt,

The problem is if I use a DBF file without a CDX file, I don't need to add COMMIT and CLOSE. the REPLACE command reflect the changes to the DBF.

The problem only arises when I used a DBF file that has a CDX file, REPLACE command is not suffice.
and I need add to COMMIT and CLOSE it just to reflect the changes T_T


Thank's for the tip on buffering, I think I know how table/storage buffering works in VFP but I preferred to use FLUSH command ( OS related disk caching ) over VFP table buffering ( VFP table/storage buffering ).

Whether using Replace, Insert, Tableupdate or any saving commands... if you pull the machine's power plug some data will be lost, unless you issue FLUSH command after any saving/update commands.

On my experience VFP running on Windows 7 to 10 needs FLUSH it has some disk caching delay on this latest MS OS : )

Many thanks,

Dex
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 4 days ago #12857

  DexterZ's Avatar Topic Author DexterZ Offline Posts: 28
Hi Karl,

FLUSH is more on OS disk caching, while COMMIT is internal to application saving scheme ^_^y

Dex
No other languages can run like a Fox! long live xBase!
Dexter Zamora, Manila
ManagedDbf.Blogspot.com/

Please Log in or Create an account to join the conversation.

VFP9 with CDX concerns ? 1 month 3 days ago #12859

  robert's Avatar robert Offline Posts: 1502
Dex,

DexterZ wrote: The problem is if I use a DBF file without a CDX file, I don't need to add COMMIT and CLOSE. the REPLACE command reflect the changes to the DBF.

The problem only arises when I used a DBF file that has a CDX file, REPLACE command is not suffice.
and I need add to COMMIT and CLOSE it just to reflect the changes T_T


I'll check why the program does not automatically commit the changes at shutdown.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2