Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CursorAdapter and PostgreSQL Problem
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00840453
Message ID:
00841823
Views:
34
Hi Simon,

I just took a look at my ca code and noticed I was using the ODBC provider
that postgresql maintains. I suppose as long as the database back end
provides an ODBC, ca would be able to connect to it so that an existing VFP
client/server app should be able to move its data to the back end server and
run basically unchanged.

If OLE DB eventually become the industrial standard, I foresee some major
headache because, of a need to perform VFP client/server re-writes

Here is ca code I wrote right after ca was introduced. It worked great with
postgresql.
*:******************************************************************************
*:
*: Procedure File D:\SQL_DEMO\CA.PRG
*:
*: Documented using Visual FoxPro Formatting wizard version  .05
*:******************************************************************************
*:   CA

oConn = 0
the_cno='0'
Connstring = "DATABASE=vfp2pg;SERVER=www.smvfp.com; port=5432;UID=VfP2Pg;pwd=HelloWorld;provider=MSDASQLR;DRIVER=postgreSQL;"

oConn = Sqlstringconnect(Connstring)

If oConn < 1

    =Aerror(the_oCA)
    cMessageTitle = "Error - Connection Error"
    cMessageText = "The following error occurred:"+Chr(13)+Chr(13)+;
        "Error Number:  "+Str(the_oCA(1))+Chr(13)+;
        "Error Message: "+the_oCA(2)
    nDialogType = 0 + 16 + 0
    *   0 = Ok
    *  16 = Stop
    *   0 = Default to OK
    nAnswer = Messagebox(cMessageText, nDialogType, cMessageTitle)

Else


    Define Popup leechoice Font 'arial',12 Style 'N' From 10,40 Margin shortcut Title [SELECT INDEX]
    Define Bar  1 Of leechoice Prompt " \<1. Select all records"
    Define Bar  2 Of leechoice Prompt " \<2. Parameterized Cursor"
    On Selection Popup leechoice Deactivate Popup leechoice
    Activate Popup leechoice
    Release Popup leechoice
    the_prompt=Substr(Prompt(),1,2)

    Do Case
    Case the_prompt=' 1'

        the_select = "select arcurrah.CNO, arcurrah.TYPE, arcurrah.BILLCAT, arcurrah.DESCRIPT, "+;
            "arcurrah.INVOICE, arcurrah.TRANDATE, arcurrah.AMOUNT, arcurrah.THEUNIQUE, "+;
            "arcurrah.THETIME from arcurrah where arcurrah.cno > -1 order by arcurrah.theunique"

        wait window 'please be patient while I fetch around 16,500 rows.' nowait noclear
        got_all=.T.

    Case the_prompt=' 2'

        the_select = "select arcurrah.CNO, arcurrah.TYPE, arcurrah.BILLCAT, arcurrah.DESCRIPT, "+;
            "arcurrah.INVOICE, arcurrah.TRANDATE, arcurrah.AMOUNT, arcurrah.THEUNIQUE, "+;
            "arcurrah.THETIME from arcurrah where arcurrah.cno = ?the_cno order by arcurrah.theunique"
        got_all = .F.
    Otherwise

        the_select = "select arcurrah.CNO, arcurrah.TYPE, arcurrah.BILLCAT, arcurrah.DESCRIPT, "+;
            "arcurrah.INVOICE, arcurrah.TRANDATE, arcurrah.AMOUNT, arcurrah.THEUNIQUE, "+;
            "arcurrah.THETIME from arcurrah where arcurrah.cno = ?the_cno order by arcurrah.theunique"
        got_all = .F.

    Endcase



    the_Cursor_Schema = "CNO N(10, 0), TYPE C(2), BILLCAT N(10, 0), DESCRIPT C(20), INVOICE N(10, 0), TRANDATE D, AMOUNT B(2), THEUNIQUE I, THETIME T"

    the_UpdatableFieldList = "CNO, TYPE, BILLCAT, DESCRIPT, INVOICE, TRANDATE, AMOUNT"

    the_UpdateNameList = "CNO arcurrah.CNO, TYPE arcurrah.TYPE, BILLCAT arcurrah.BILLCAT, DESCRIPT arcurrah.DESCRIPT, INVOICE arcurrah.INVOICE, TRANDATE arcurrah.TRANDATE, AMOUNT arcurrah.AMOUNT, THEUNIQUE arcurrah.THEUNIQUE"

    oCA = Createobject('CursorAdapter')
    With oCA
        .Name               = 'oCA'
        .Alias              = 'arcur'
        .AllowUpdate        = .T.
        .AllowDelete        = .T.
        .AllowInsert        = .T.
        .DataSourceType     = 'ODBC'
        .Datasource         = oConn
        .SelectCmd          = the_select
        .Tables             = 'arcurrah'
        .CursorSchema       = the_Cursor_Schema
        .KeyFieldList       = "THEUNIQUE"
        .UpdatableFieldList = the_UpdatableFieldList
        .UpdateNameList     = the_UpdateNameList
        .AllowUpdate        = .T.
        .SendUpdates        = .T.
        .UpdateType         = 1 && update
        .UseDeDataSource    = .T.
        .WhereType          = 1 && key field only
        .BufferModeOverride = 5
        prep = .CursorFill()
        If !prep
            =Aerror(the_oCA)
            cMessageTitle = "Error - CursorFill Method"
            cMessageText = "The following error occurred:"+Chr(13)+Chr(13)+;
                "Error Number:  "+Str(the_oCA(1))+Chr(13)+;
                "Error Message: "+the_oCA(2)
            nDialogType = 0 + 16 + 0
            *   0 = Ok
            *  16 = Stop
            *   0 = Default to OK
            nAnswer = Messagebox(cMessageText, nDialogType, cMessageTitle)

        Endif
    Endwith

    wait clear
    Do Form lee

    SQLDISCONNECT(oCA.Datasource)

Endif

Return
It would be nice if the VFP team could supply a native driver to each of the
back end databases it chose to support, but that would be asking to much of a
compnay postured within Microsoft. In the mean time we must work with
whatever the back end database company provides for connecting to its
database.


Postgresql just recently release an new ODBC driver.


Here is the email announcement:



===========================================================

I'm happy to announce the release of psqlODBC 07.03.0200, the lastest
version of the official PostgreSQL ODBC driver.

Project Homepage:
http://gborg.postgresql.org/project/psqlodbc/projdisplay.php

Downloads:
http://gborg.postgresql.org/project/psqlodbc/genpage.php?downloads

This version includes the following changes:

- Fix a memory leak in case of updatable KEYSET_DRIVEN cursors.
- Change SQLMoreResults to initialize the cursor position.
- Hopefully, SQLDescribeCol() returns a more appropriate error
code(SQLSTATE).
- Correct the return info for SQLGetInfo(.., SQL_CURSOR_COMMIT
(ROLLBACK)_BEHAVIOR) call.
- Explictly reject the SQLBrowseConnect call.
- Serialize the connection use for communication(multi-thread).
- Let escape strings case-insensitive.
- Fix a bug when handling data_at_execution parameter array reported by
Jol Valentine jolv@genaware.com.
- Fix a bug on SQLSetStmtAttr(.., SQL_CONCURRENCY) reported by Shachar
Shemesh.
- Apply a patch to changes the storage type of the debug "func"
variables to be stored in the constant area of the program(Shachar
Shemesh).
- Correct the column size in case of bytea as LO.
- Distinguish the rowset size for SQLFetch(Scroll) from that for
SQLExtendedFetch.
- Implement SQLGetDiagFieldW() for the Unicode driver.
- Improve SQLGetDiagField so that an MFC appliaction reports error
messages properly(bug report from Silvio Scarpati).
- Add quotes around table names to use ::regclass in parse.c .
- Change SQLGetFunctions to contain ODBC3 APIs.
- Improve the SQL_C_VARBOOKMARK type handling.
- Cleanup copy_and_convert_field() a little.
- Set an error number and an error message for
SQLAllocHandle(SQL_HANDLE_DESC).
- Fix a bug about a bookmark handling in SQLBulkOperaitons(SQL_ADD,..)
- Remove date cast(::date) from the conversion of {d escape before 7.3
servers. 7.2 servers are poor in implicit cast from date - timestamp
without time zone.
- Corrent the handling of bookmark in SQLBulkOperations.
- Correct the calculation of a global index in SC_pos_add.
- Cleanup global/rowset/resultset index handling a little.
- Correct a handling of offset in SQLBulkOperations.
- Fix a crash bug in SQLDriverConnect().
- Revert a *int8 as* DSN option to *numeric* for MS Jet.
- Add a SQL_CA2_SENSITIVITY_ADDTIONS mask to the reply for
SQLGetInfo(.., SQL_ATTR_KEYSET_DRIVEN_CURSOR_ATTRIBUTES2) which would
make a little OpenOffice happy.
- Fix a bug in SQLGetInfo(.., SQL_ATTR_ROW_NUMBER) for keyset_driven
cursors.

Regards, Dave.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

==========================================================
Leland F. Jackson, CPA
Software - Master (TM)
smvfp@mail.smvfp.com
Software Master TM
Previous
Reply
Map
View

Click here to load this message in the networking platform