Product: MapXtreme 2004/2005
Version: 6.0, 6.1, 6.2, 6.5
Platform: Not Platform Related
Category: Data Access
Summary:
Can a feature be added to an Oracle table added through TableInfoServer?
Question:
In the documentation for TableInfoServer, it says:
For a currently open server table, this class provides read-only information about the table. Use this class to define a server table as well. Defining a server table is different from creating a new table on a remote database server. Creating new server tables is currently not supported.
Does this mean that it isn't possible to add new features to a database table which was added through TableInfoServer in MapXtreme 2004/2005? When trying to add a feature to an Oracle table added through TableInfoServer, the following error is received:
private void button1_Click(object sender, System.EventArgs e)
{
MIConnection Connection =new MIConnection ();
Connection.Open() ;
TableInfoServer ti = new TableInfoServer("StateCapXY",
"SRVR=sol9ir2_pangea;UID=mipro;PWD=mipro","Select * from usa_caps",MapInfo.Data.ServerToolkit.Oci );
MapInfo.Data.Table StateCapXY = Connection.Catalog.OpenTable(ti);
mapControl1.Map.Load(new MapTableLoader(StateCapXY ));
}
private void button2_Click(object sender, System.EventArgs e)
{
MIConnection Connection =new MIConnection ();
Connection.Open() ;
Table table = Session.Current.Catalog.GetTable ("StateCapXY");
MapInfo.Geometry.FeatureGeometry g = new MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys (), -81.350833, 28.725556);
MapInfo.Data.MICommand micomm=Connection.CreateCommand ();
micomm.CommandText="insert into " + table.Alias + " (obj,mi_prinx) values(@obj,@id)";
micomm.Parameters.Add("@obj",g);
micomm.Parameters.Add("@id",300);
micomm.ExecuteNonQuery ();
}
The error occurs at the Table.InsertFeature line - error message is "insert into "Gangyta"(obj, MI_Style) values(@0, @1): Unable to perform requested modification"
[MIException: Error executing statement : insert into "Gangyta"(obj, MI_Style) values(@0, @1): Unable to perform requested modification.]
MapInfo.Data.MICommand.ExecuteNonQuery()
MapInfo.Data.Table.InsertFeature(Feature feature)
Tekis.Map.Web.MapXtreme.MapGmSvg.Button1_Click(Object sender, EventArgs e) in c:\decerno stuff\edrive\project\tekis.map\web\mapxtreme\ltf1\mapmx.aspx.cs:807
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain() |
|
Answer:
The documentation snippet above means that MapXtreme 2004/2005 does not support the creation of new tables on the server (e.g. it's possible to construct a new TableInfoServer instance to open an existing server table but it isn't possible to use it to a call to CreateTable to create a new table in the database).
When opening a remote database table through TableInfoServer, MapXtreme 2004/2005 does support Insert, Update, and Delete operations. The error message received can mean it's failing because either the Obj column or mi_style columns are read only. The style column might be read only if the table does not use per-record styles. If the query that was used joins two tables, it won't be possible to insert a feature into this table. If there are any data readers against this table that have not been properly closed then modifications will not be allowed. An easy way to test for this is to call Table.BeginAccess(TableAccessMode.Write) to see if this passes or fails. If it passes make sure to call EndAccess.
Regarding the code above, it is necessary to add the style when inserting a feature into a table. If the code is modified to insert the style, then the error message won't be received. Here's an example of inserting an airplane symbol into to the map. This assumes that usa_caps is open in the catalog.
C# Code:
private void button2_Click(object sender, System.EventArgs e)
{
MIConnection Connection =new MIConnection ();
Connection.Open() ;
Table table = Session.Current.Catalog.GetTable ("StateCapXY");
MapInfo.Geometry.FeatureGeometry g = new MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys (), -81.350833, 28.725556);
MapInfo.Styles.CompositeStyle MyStyle;
MyStyle = new MapInfo.Styles.CompositeStyle();
MapInfo.Styles.FontPointStyle FSymbol = new MapInfo.Styles.FontPointStyle();
FSymbol.Code = 53; //Red airplane
FSymbol.Color = System.Drawing.Color.Red;
FSymbol.Font = new MapInfo.Styles.Font("MapInfo.Symbols",48.0);
FSymbol.Angle = 0; //degrees in 10ths of a degree. 90 degrees being 900
FSymbol.SetApplyAll();
FSymbol.Attributes = MapInfo.Styles.StylesAttribute.PointAttributes.BaseAll;
MyStyle.SymbolStyle = FSymbol;
MapInfo.Data.MICommand micomm=Connection.CreateCommand ();
micomm.CommandText="insert into " + table.Alias + " (OBJECT,mi_prinx,MI_STYLE) values(@obj,@id,@MyStyle)";
micomm.Parameters.Add("@obj",g);
micomm.Parameters.Add("@id",300);
micomm.Parameters.Add("@MyStyle",MyStyle);
micomm.ExecuteNonQuery ();
}
VB.NET:
Dim Connection As New MIConnection()
Connection.Open()
Dim table As Table = Session.Current.Catalog.GetTable("StateCapXY")
Dim g As New MapInfo.Geometry.Point(mapControl1.Map.GetDisplayCoordSys(), - 81.350833, 28.725556)
Dim MyStyle As MapInfo.Styles.CompositeStyle
MyStyle = New MapInfo.Styles.CompositeStyle()
Dim FSymbol As New MapInfo.Styles.FontPointStyle()
FSymbol.Code = 53 'Red airplane
FSymbol.Color = System.Drawing.Color.Red
FSymbol.Font = New MapInfo.Styles.Font("MapInfo.Symbols", 48.0)
FSymbol.Angle = 0 'degrees in 10ths of a degree. 90 degrees being 900
FSymbol.SetApplyAll()
FSymbol.Attributes = MapInfo.Styles.StylesAttribute.PointAttributes.BaseAll
MyStyle.SymbolStyle = FSymbol
Dim micomm As MapInfo.Data.MICommand = Connection.CreateCommand()
micomm.CommandText = "insert into " + table.Alias + " (OBJECT,mi_prinx,MI_STYLE) values(obj,id,MyStyle)"
micomm.Parameters.Add("obj", g)
micomm.Parameters.Add("id", 300)
micomm.Parameters.Add("MyStyle", MyStyle)
micomm.ExecuteNonQuery()
Last Modified: 08/24/2006 10:01:46 AM
|