Create Method for LCConnection

This method creates a metadata object. Each connector supports only certain object types. Refer to the documentation for the specific connector to determine the object types it supports.

For the Connector for DB2®, this method creates an object in DB2®. Only LCOBJECT_METADATA and LCOBJECT_INDEX are supported for DB2®.

Defined In

LCConnection

Syntax

Call lcConnection.Create(objectType, srcFieldlist)

Parameters

Parameter

Description

objectType

Long. Type of object. Valid types and associated behavior include the following (refer to the documentation for the specific connector to determine which of the following are supported):

LCOBJECT_SERVER Creates a server object (obtaining the name from the SERVER property). Additional information may be provided in connector-specific properties. Not supported for DB2®.

LCOBJECT_DATABASE Creates a database object (obtaining the name from the DATABASE property, and optionally the server name from the SERVER property). Additional information may be provided in connector-specific properties. Not supported for DB2®.

LCOBJECT_METADATA Creates a metadata object (obtaining the name from the METADATA property). The fields in the new metadata will have the same order, types, and names as fields in the fieldlist. Fields with the flag LCFIELDF_NO_CREATE are skipped. For example, this creates a table in DB2®.

LCOBJECT_INDEX Creates an index object (the metadata being indexed is in METADATA property, the index name to create is in INDEX property). The key fields for the new index are fields in the fieldlist with the LCFIELD_KEY flag set. For example, this creates an index in DB2®.

LCOBJECT_FIELD Creates a field object (the metadata being appended to is in METADATA property). The fields to append to the metadata will have the same order, types, and names as fields in the fieldlist. Fields with the flag LCFIELDF_NO_CREATE are skipped. Not supported in DB2®.

srcFieldlist

LCFieldlist. Fieldlist from whose metadata or key fields the object is created. This parameter is ignored for object types SERVER and DATABASE.

Example

Option Public
Option Explicit
Uselsx "*lsxlc" 
Sub Initialize
  Dim src As New LCConnection ("db2") 
  Dim fldLstRecord As New LCFieldList
  Dim fld As LCField

  ' build the table definition
  ' note the use of the 'MaxLength' parameter
  ' this is used to more closely control the datatype creation
  ' within the connection -- in this case DB2
  ' in DB2, a text stream with a MaxLength of 64 will be created
  ' as VARCHAR(64). if the flag LCSTREAMF_FIXED was used
  ' the column would be CHAR(64). The field flag LCFIELDF_NO_NULL
  ' would add NOT NULL to the column definition

  Call FldLstRecord.Append ("ACCOUNTMANAGER", LCTYPE_INT)
  Set fld = FldLstRecord.Append ("CONTACTNAME", LCTYPE_TEXT)
  Call fld.SetFormatStream (0, 64, LCSTREAMFMT_LMBCS)
  Set fld = FldLstRecord.Append ("COMPANYNAME", LCTYPE_TEXT)
  Call fld.SetFormatStream (0, 64, LCSTREAMFMT_LMBCS)
  Set fld = FldLstRecord.Append ("COMPANYADDRESS", LCTYPE_TEXT)
  Call fld.SetFormatStream (0, 64, LCSTREAMFMT_LMBCS)
  Set fld = FldLstRecord.Append ("COMPANYCITY", LCTYPE_TEXT)
  Call fld.SetFormatStream (0, 64, LCSTREAMFMT_LMBCS)
  Set fld = FldLstRecord.Append ("COMPANYSTATE", LCTYPE_TEXT)
  Call fld.SetFormatStream (0, 64, LCSTREAMFMT_LMBCS)
  Set fld = FldLstRecord.Append ("COMPANYPHONE", LCTYPE_TEXT)
  Call fld.SetFormatStream (0, 32, LCSTREAMFMT_LMBCS)

  ' set properties to connect to both data sources
  src.Database = "Gold"
  src.Userid = "JDoe"
  src.Password = "xyzzy"
  src.Metadata = "customer"

  src.Connect
 ' create it based on the metadata property already set
  On Error LCFAIL_DUPLICATE Goto tableexists
  Call src.Create (LCOBJECT_METADATA, fldLstRecord)
  Print "The '" & src.Metadata & "' table was created."
  End

tableexists:
  Print "The '" & src.Metadata & "' table exists."
  End
End Sub

Example Output

The 'customer' table was created.