-
Mailing-Liste
Inhalt
Information about opened tables and columns in tables
10.09.2001
 
A couple of utility functions to make MapBasic Life easier

MAPINFO-L    

' **************************************************************************
'       A couple of utility functions to make MapBasic Life easier.
'       dcOpenTable( Path, Name ) -- opens a table if it's not already open
'       dcCheckOrCreateColumn ( Table, ColName, ColType ) -- create a column if it doesn't exist
'
'       Designed to be linked to your program.
'       Include "dctabl.def" in your main routine to define the functions.
'
include "mapbasic.def"
Include "c:\projects\bes pfp\pfptools\dctabl.def"
' ======================================================================
'       dcIsTableOpen
' ======================================================================

Function dcIsTableOpen(ByVal sTableName as String) as Logical
Dim     l as Logical

        OnError goto NotOpen
        l = TableInfo(sTableName, TAB_INFO_READONLY)
        OnError Goto 0
        dcIsTableOpen = TRUE
        Exit Function
NotOpen:
        OnError goto 0
        dcIsTableOpen = FALSE
        Exit Function

End Function

' ======================================================================
'       dcOpenTable
'               Path      The file path, not including tablename
'                         of the physical location of the table in case
'                         it needs to be opened.  If the table is already
'                         open there is no promise that it came from this
'                         location.
'               Name      The name of the *.TAB file.
'               Alias     The Alias used to open the file.
' ======================================================================
Function dcOpenTable(sPathName As String,  ByVal sTabName as String, ByVal
sAlias as String) As Logical
Dim     Username as String
  
  OnError Goto NotOpen
  Dim l As Logical

'       print "Request is: " + sPathName + sTabname + " as " + sAlias
  l = TableInfo(sAlias, TAB_INFO_READONLY)

  dcOpenTable = TRUE
  Exit Function
OpenTable:
  OnError goto NoTable
  If Right$(sPathName, 1) <> "\" then
        sPathName = sPathName + "\"
  End If
  UserName = sPathName + sTabName
DlgName:
'       print "Trying to open " + Username + " as " + sAlias
  Open Table Username as sAlias
  OnError goto 0
  sPathName = PathToDirectory$(UserName)
  dcOpenTable = TRUE
  Exit Function 
NotOpen:
'       print "Not open..."
  dcOpenTable = FALSE
  Resume OpenTable
NoTable:
'       print "Unable to open..."
  UserName = FileOpenDLG(sPathName, sTabName, "TAB", "Please locate table: "
+ sAlias + " (" + sPathName + sTabname + ")" )
  If Username = "" Then
        dcOpenTable = FALSE
        Exit Function
  Else
        Resume DlgName
  End If
End Function
' ======================================================================
'
'
' ======================================================================
Function dcIsColumnThere(ByVal sTabName as String, sColName as String) as
Logical
Dim NumCols as Integer
Dim LoopCount as Integer
Dim ColQuery as String
Dim ColName as String

        dcIsColumnThere = FALSE
        '       See if the column name exists...
        NumCols = TableInfo (sTabName, TAB_INFO_NCOLS)

        For LoopCount = 1 to NumCols
                ColQuery = "Col" + LTrim$(str$(LoopCount))
                ColName = ColumnInfo(sTabname, ColQuery, COL_INFO_NAME)
                If ColName = sColName then
                        dcIsColumnThere = TRUE
                        Exit Function
                End IF                  

        Next

End Function
' ======================================================================
'       dcCheckOrCreateColumn
'               TableName               The alias of the table containing
the column
'               ColName         The name of the column to check for
'               ColType         The data type if the column needs to be
created.
'
'       Assumes the table is open...
'       Further, does not check to see that the data type matches if the
column
'               already exists.
'
' ======================================================================
Function dcCheckOrCreateColumn( ByVal sTabName as string, ByVal sColname as
string, ByVal SColType as String ) as Logical
Dim     AlterTableText as String

        If NOT dcIsColumnThere (sTabName, sColname) Then
        '       The column name does not exist.
                Commit Table sTabName
                AlterTableText = "Alter Table " + sTabname + " (Add " +
sColname + " " + sColType + ")"
                Run Command AlterTableText
        End If
        dcCheckorCreateColumn = TRUE
End Function
================================================================
============ here's the content of dctabl.def ==================
Declare Function dcOpenTable(sPathName as String, ByVal sTabName As String,
ByVal sAlias as String) As Logical
Declare Function dcCheckOrCreateColumn( ByVal sTabname as String, ByVal
sColname as string, ByVal sColType as string) as Logical
Declare Function dcIsTableOpen(ByVal sTable as String) as Logical
Declare Function dcIsColumnThere(ByVal sTable as String, sColName as String)
as Logical


Dazu Literaturtips bei unserem Partner, amazon.de:
INSIDE MapInfo Professional 6.0 - Neuerscheinung 2001!
Minding your Business with MapInfo
MapBasic Developer's Guide - derzeit evt. vergriffen
Quelle: MAPINFO-L , Cautley, David/PDX

 

Neuigkeiten und Anregungen senden Sie bitte an gis-news.de!

Literatur
Buch des Monats:

Geoinformation im Internet

GeoIT-Shop

Suche

www.strato.de -> hier klicken
RSS FULL