MapInfo Pro Developers User Group

 View Only
  • 1.  Display linked PG table on MapInfo Pro 2023

    Posted 24 days ago

    Hi there,

    I'm trying to rewrite some old MapBasic extensions with Python on MapInfo Pro 2023. In our old codes, below MapBasic commands played super important role and I'm trying to keep it that way (to keep it as a linked table out of PG). 

        Server hdbc Link Table sql
        Toolkit "ODBC"
        Into "TABLE_A"
        File PathName + "table_a.TAB"
    I have been looking for Python alternatives for this code for almost 2 weeks, but I haven't been able to find any that's even close to what the above code does. 
    Is there a way of doing this with Python? Or do I really have to figure out a way and use "do()" command from Python and call above MapBasic commands to achieve? 
    Please kindly share your thoughts or sample codes for either way. Thank you so much. 


    ------------------------------
    Ferhad Pakzat
    RF/GIS Design & Data Management, FPE
    Bc Hydro And Power Author
    Burnaby BC
    ------------------------------


  • 2.  RE: Display linked PG table on MapInfo Pro 2023

    Employee
    Posted 23 days ago

    Hey Ferhad

    pro.Catalog has this method, which may be what you are looking for:

    OpenTable(IDataSource, TableDefinition)

    Opens a table using the TableDefinition and IDataSource objects identified by the tableDef and dataSourceparameters

    I often use pro.RunMapBasicCommandEx() to execute MapBasic code from Python. This generally works well, too.

    You can't do everything directly through Python, so some things still require MapBasic code.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 3.  RE: Display linked PG table on MapInfo Pro 2023

    Posted 18 days ago

    Thank you so much Peter for the answer. I'm still trying hard to make it work. My question does involve opening the tables (your suggestions would perfectly work for that part) but it was more about downloading data (and saving as .tab files) from our PG server using python preferably. I can still try MapBasic way. It's just the interactions part between them is giving me a little hard time. 

    Is there any way that I can retrieve the results from pro.RunMapBasicCommandEx()? For instance, is it possible to get the hdbc (the handle for odbc conneciton built by MapBasic function server_connect())? 

    Would this work from Python side? 

    hdbc = pro.RunMapBasicCommandEx("Server_Connect(connection parameters here)")



    ------------------------------
    Ferhad Pakzat

    Bc Hydro And Power Author
    Burnaby BC
    ------------------------------



  • 4.  RE: Display linked PG table on MapInfo Pro 2023

    Employee
    Posted 17 days ago

    Hey Ferhad

    To call a MapBasic function from Python, you can use pro.EvalMapBasicCommandEx:

    hdbc = pro.EvalMapBasicCommandEx("Server_Connect(connection parameters here)")

    That will return the handle to the variable hdbc.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------



  • 5.  RE: Display linked PG table on MapInfo Pro 2023

    Posted 16 days ago

    Thank you so much. The command worked. I'll continue my work and let you know if I encounter any other issues or difficulties. 



    ------------------------------
    Ferhad Pakzat

    Bc Hydro And Power Author
    Burnaby BC
    ------------------------------