View Table

Named table resources can be defined by a view (query of the data) using an MI SQL statement against a table. This uses the MapinfoSQLDataSourceDefinition to specify the SQL query and the name of the table used in the query. You can define a view table in two ways: define both the definition to the table and the query or specify an existing named table and the query.

The named views are based on named tables and they should publish a primary key if the named table has a primary key. Following are the pre-conditions to publish a primary key:
  • The Select clause should have primary key column
  • The Simple query should be without a Join
  • The named table should have primary key metadata

Example

In the following example, the table used in the query is defined (a TAB file data source named World123) and then the query is defined (named View123). When calling this named view table, the name of the MapinfoSQLDataSourceDefinition is used (View123).

In this example, the definition uses the following token:

  • @filedir@ the directory on the file system where the table file is located


<?xml version="1.0" encoding="UTF-8"?>
<NamedDataSourceDefinition version="MXP_WorkSpace_1_5" xmlns="http://www.mapinfo.com/mxp">
	<ConnectionSet>
        <NamedConnectionRef resourceID="/Samples/NamedConnections/SampleData">
            <ConnectionName>SampleData</ConnectionName>
        </NamedConnectionRef>
    </ConnectionSet>
	<DataSourceDefinitionSet>
		<TABFileDataSourceDefinition id="id2" readOnly="false">
			<DataSourceName>World123</DataSourceName>
			<FileName>@filedir@/world.tab</FileName>
		</TABFileDataSourceDefinition>
		<MapinfoSQLDataSourceDefinition id="id3" readOnly="false">
			<DataSourceName>View123</DataSourceName>
			<MapinfoSQLQuery>
				<Query>SELECT Country,Capital,Pop_1994,Pop_Male,Pop_Fem, Obj FROM World123 WHERE Country IN ('India','Canada','Vietnam','Brazil','China','Japan')</Query>
			</MapinfoSQLQuery>
		</MapinfoSQLDataSourceDefinition>
	</DataSourceDefinitionSet>
	<DataSourceRef ref="id3"/>
</NamedDataSourceDefinition>	

In the following example, the table used in the query is an existing named table which has already been defined in the repository. You must specify the named table using a NamedDataSourceDefinitionRef to the full path of the table within the repository. The query is then defined using this named table (also specify the entire path to the named table). When calling this named view table, the name of the MapinfoSQLDataSourceDefinition is used (View123).

<?xml version="1.0" encoding="UTF-8"?>
<NamedDataSourceDefinition version="MXP_NamedResource_1_5" xmlns="http://www.mapinfo.com/mxp" >
	<ConnectionSet>
        <NamedConnectionRef resourceID="/Samples/NamedConnections/SampleData">
            <ConnectionName>SampleData</ConnectionName>
        </NamedConnectionRef>
    </ConnectionSet>
	<DataSourceDefinitionSet>
		<NamedDataSourceDefinitionRef id="id0" resourceID="/NamedTables/WorldTable"/>
		<MapinfoSQLDataSourceDefinition id="id3" readOnly="false">
			<DataSourceName>View123</DataSourceName>
			<MapinfoSQLQuery>
				<Query>SELECT * from "/NamedTables/WorldTable"</Query>
			</MapinfoSQLQuery>
		</MapinfoSQLDataSourceDefinition>
	</DataSourceDefinitionSet>
	<DataSourceRef ref="id3"/>
</NamedDataSourceDefinition>