View Table

Example

Named table resources can be defined by a view (query of the data) using a 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.

In this 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 tokens:


<?xml version="1.0" encoding="UTF-8"?>
<NamedDataSourceDefinition version="MXP_WorkSpace_1_5" xmlns="http://www.mapinfo.com/mxp">
	<ConnectionSet>
        <NamedConnectionRef resourceID="/Samples/NamedConnections/FileNamedConnection">
            <ConnectionName>FileNamedConnection</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 this 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/FileNamedConnection">
            <ConnectionName>FileNamedConnection</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>