Upload
trinhthien
View
221
Download
1
Embed Size (px)
Citation preview
Every connection is a new opportunity™
MapBasic & spatiale databaser
Peter Horsbøll Møller
Systems Engineer
Marts 2012 Every connection is a new opportunity™
Every connection is a new opportunity™
DBMS Sample
[CONNECTIONS]
NUM_CONNECTIONS=4
[CONNECTION_1]
DESCRIPTION=DSN using FileDSN
CONNECTIONTYPE=FILEDSN
FILEDSN=SQL2008.DSN
TRUSTED_CONNECTION=1
[CONNECTION_2]
DESCRIPTION=DSN using DSN
CONNECTIONTYPE=DSN
DSN=OKGIS
TRUSTED_CONNECTION=0
USERNAME=AdminUser
PASSWORD=Admin
[CONNECTION_3]
DESCRIPTION=Connection String
CONNECTIONTYPE=CONNECTIONSTRING
CONNECTIONSTRING=DSN=OKGIS;Trusted_Connection=Yes
[CONNECTION_4]
DESCRIPTION=Connection String 2
CONNECTIONTYPE=CONNECTIONSTRING
CONNECTIONSTRING=DRIVER=SQL Server Native Client
10.0;SERVER=localhost\sqlexpress;DATABASE=OKGIS2008
TRUSTED_CONNECTION=0
USERNAME=MI_MGR
PASSWORD=MI_MGR
Every connection is a new opportunity™
DBMS Sample
Every connection is a new opportunity™
Forudsætning
• Vi har en spatial database, her SQL Server 2008
• Databasen indeholder MapInfo.MapInfo_MapCatalog
tabellen
• Der er spatiale tabeller i databasen, som også er registreret
i MapCatalog
Every connection is a new opportunity™
Åbne en tilslutning
Server_Connect( toolkit, connect_string )
toolkit is a string value identifying the remote interface, for
example, "ODBC", "ORAINET". Valid values for toolkit can be obtained
from the Server_DriverInfo( ) function.
connect_string is a string value with additional information
necessary to obtain a connection to the database.
Dim nConnection As Integer
nConnection = Server_Connect(“ODBC”, “DSN=GIS2008”)
connect_string kan være en lang række “ting” som angiver hvilken database og bruger man ønsker at tilslutte til og som. “Værdierne” kan angives via en datakilde eller direkte i connect_string
Every connection is a new opportunity™
Åbne en tilslutning
MS Access database
Fil datakilde
Every connection is a new opportunity™
Åbne en tilslutning
System datakilde
Tilslutningsstreng
Every connection is a new opportunity™
Lukke en tilslutning
Server ConnectionNumber Disconnect
ConnectionNumber is an integer value that identifies the specific
connection.
Server 1 Disconnect
Server nConnection Disconnect
Every connection is a new opportunity™
Egenskaber på en tilslutning
Server_ConnectInfo( ConnectionNo, Attr )
ConnectionNumber is the integer returned by the Server_Connect( ) function that
identifies the database connection.
Attr is a code indicating which information to return.
Every connection is a new opportunity™
Sende kommandoer til databasen
Server_Execute( ConnectionNumber, server_string )
ConnectionNumber is an integer value that identifies the specific connection.
server_string is any valid SQL statement supported by the connected server.
Refer to the SQL language guide of your server database for information on
valid SQL statements.
....
Every connection is a new opportunity™
Analysere tabeller/tabelstruktur
Server_NumCols( StatementNumber )
StatementNumber is an integer value that identifies information about an SQL
statement.
Every connection is a new opportunity™
Analysere tabeller/tabelstruktur
Server_ColumnInfo( StatementNumber, ColumnNo, Attr )
StatementNumber is an integer value that identifies information
about an SQL statement.
ColumnNo is the number of the column in the table, starting at 1
with the leftmost column.
Attr is a code indicating which aspect of the column to return.
Every connection is a new opportunity™
Analysere tabeller/tabelstruktur
Every connection is a new opportunity™
Åbne sammenkædet tabel fra databasen
Server Link Table
SQLQuery
Using ConnectionString
Into TableName
Toolkit Toolkitname
[ File FileSpec ]
[ ReadOnly ]
[ Autokey { Off | On }]
ConnectionNumber is an integer value that identifies an existing connection.
SQLQuery is a SQL query statement (in native SQL dialect plus object keywords)
that generates a result set. The MapInfo linked table is linked to this result
set.
ConnectionString is a string used to connect to a database server. See
Server_Connect( ) function.
TableName is the alias of the MapInfo table to create.
FileSpec is an optional tab filename. If the parameter is not present, the tab
filename is created based on the alias and current directory. If a FileSpec is
given and a tab file with this name already exists, an error occurs.
ReadOnly indicates that the table should not be edited.
Toolkitname is a string indicating the type of connection, ODBC or ORAINET.
Server ConnectionNumber Link Table
SQLQuery
Toolkit toolkitname
Into TableName
[ File FileSpec ]
[ ReadOnly ]
[ Autokey { Off | On }]
Every connection is a new opportunity™
Åbne sammenkædet tabel fra databasen
Every connection is a new opportunity™
Åbne direkte tabel fra databasen
Register Table source_file
Type ODBC Connection { Handle connection_number | connection_string }
Toolkit toolkit_name
Cache { ON | OFF }
[ Autokey { ON | OFF }]
Table SQLQuery
[ Versioned { ON | OFF }]
[ Workspace Workspace_name ]
[ ParentWorkspace ParentWorkspace_name ]
source_file is a string that represents the name of an existing database, spreadsheet, text
file, raster, or grid image. If you are registering an Access table, this argument must
identify a valid Access database.
connection_number is an integer value that identifies an existing connection to an ODBC
database.
connection_string is a string used to connect to a database server.
toolkit_name is "ODBC" or "ORAINET."
SQLQuery is the SQL query used to define the MapInfo table.
Versioned indicates if the table to be opened is a version-enabled (ON) table or not (OFF).
Workspace_name is the name of the current workspace in which the table will be operated.
The name is case sensitive.
ParentWorkspace_name is the name of parent workspace of the current workspace.
Efterfølgende skal den ”registrerede” tabel åbnes via Open Table
Every connection is a new opportunity™
Åbne direkte tabel fra databasen
Every connection is a new opportunity™
Spørgsmål?
Peter Horsbøll Møller
Every connection is a new opportunity™
Every connection is a new opportunity™