Hi Romano,
In the Python Quick Start add-in you can find this example:
### Description: This script show how to perform insert, update, and delete operation on a MapInfo Table
### Category: Catalog
from os.path import abspath, join, dirname
try:
worldcap = pro.Catalog.OpenTable(abspath(join(dirname(get_current_module_path()), r"..\Data\World\worldcap.TAB")), "worldcap")
if worldcap:
print("Initial RowCount: {}".format(worldcap.RowCount()))
# insert a new row
do("Insert Into {} Values (\"Test\", \"Test\", 0)".format(worldcap.Alias))
print("RowCount: {}".format(worldcap.RowCount()))
# update a newly inserted row
do("Update {} Set Cap_Pop = 2000 where Capital = \"Test\"".format(worldcap.Alias))
# save table edits
do("Commit Table {}".format(worldcap.Alias))
print("RowCount: {}".format(worldcap.RowCount()))
# delete newly inserted row from table
do("Delete From {} where Capital = \"Test\"".format(worldcap.Alias))
do("Commit Table {}".format(worldcap.Alias))
# pack the table
do("Pack Table {} Graphic Data".format(worldcap.Alias))
print("Final RowCount: {}".format(worldcap.RowCount()))
worldcap.Close()
except Exception as e:
print("Error: {}".format(e))
This is a basic way where you from Python use the do method to execute MapBasic statements.
If you check out the Table class in the MapInfo Pro Extensibility Reference Help, you may find some other ways to do this too.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------