Xbasic

SQL::ImportStatement Object

Syntax

IMPORT WITH APPEND | REPLACE ] INTO ' Target_Table_Name ' | : Table_Argument [ DBFDEFINITION ' Database_Definition ' | : Database_Argument ] ( FROM Source_Table_Name ) | Select_Statement

Arguments

Target_Table_Name

The full path and table name of an Alpha Anywhere .DBF table that will receive the data.

Table_Argument

An argument that provides a full path and table name of an Alpha Anywhere .DBF table.

Database_Definition

A series of field names and specifications in the format: FieldName, Type, Length, DecimalPlaces. DBFDEFINITION can override column names and precision, but must map positionally to an appropriate type.

Database_Argument

An argument that provides a series of field names and specifications in the format: FieldName, Type, Length, DecimalPlaces.

Source_Table_Name

The specification for an external (non-Alpha Anywhere) table that will provide the data.

Select_Statement

A SQL SELECT statement that retrieves data from an external (non-Alpha Anywhere) table. The syntax parsed for the SELECT statement (as with other statements) is portable SQL. The connection passed into the execute function determines the syntax executed.

Description

The SQL::ImportStatement object parses and executes an Alpha Anywhere Portable SQL import statements of the general form.

The SQL::ImportStatement object appends or replaces records in an Alpha Anywhere .DBF table. The object may optionally use a reference table to define the target table's structure or it may define the target table's field structure in-line.

 Syntax Examples

In these three cases the target table is created to match the requirements of the imported data.

import with replace into 'c:\test.dbf' select * from customers where city = :city"
import with replace into 'c:\test.dbf' FROM customers"
import with replace into :targettable DBFDEFINITION :dbfDefinition FROM customers

In these two cases the target table is created to the specifications included in the statements.

import with replace into :targettable DBFDEFINITION ' CUSTOMER_ID,C,15,0 COMPANYNAME,C,40,0 CONTACTNAME,C,30,0 ' FROM customers
import with replace into 'c:\test.dbf' DBFDEFINITION ' CUSTOMER_ID,C,15,0 COMPANYNAME,C,40,0 CONTACTNAME,C,30,0 ' FROM customers

 Examples

Example usage

dim c as SQL::connection
dim i as SQL::importstatement 
if c.open("{a5api=access,filename=c:\northwind.mdb,username=admin}")
    if i.parse(importsyntax)
        i.Arguments.set("targettable", TargetTableName)
        i.Arguments.set("dbfdefinition", DBFDefinition)
        i.Arguments.set("city", "London")
        EventScript = GetEventScript(TargetTableName)
        if i.executewithevents(c, EventScript)
            ? success handling code
        else
            ? error handling code
        end if
    else
        ? error handling code
    end if
    ? error handling code
end if

Using the ::PARSE() method.

dim import as SQL::ImportStatement
import.Parse("import with replace into 'c:\test.dbf' select * from customers where city = :city")

Using the ::EXECUTE() method.

dim import as SQL::ImportStatement
dim stat as C
 
stat = "import with replace into 'c:\test.dbf' select * from customers where city = :city""
import.Execute( stat )
import.ExecuteWithEvents(c, EventScript)

Using the ::ExecuteWithEvents() method.

dim import as SQL::ImportStatement
dim stat as C
dim EventScript as C
stat = "import with replace into 'c:\test.dbf' select * from customers where city = :city""
import.ExecuteWithEvents(stat, EventScript)

The SQL::ImportStatement object supports UpdateBegin(), UpdateEnd(), and UpdateProgress().

Properties

Arguments SQL::Arguments

Read Only. Arguments for the current query.

CallResult SQL::CallResult

Read Only. Call results.

ColumnReferences ReferenceList of SQL::Query::ColumnReference

Read Only. An array of all column references in the query (including nested occurrences).

Connection SQL::Connection

Read Write. Current open connection

DBFDefinition C

Read Write An optional definition for the local table (can override size and name, but must be type compatible with the corresponding column data type being imported)

ErrorColumn N

Read Only. The column number of the last error reported by the parser.

ErrorText C

Read Only. The text of the last parser error reported.

FunctionReferences ReferenceList of SQL::Query::ValueExpression

Read Only. An array of all function calls. Behaves the same way as the SelectTableReference object.

ObjectDefinitions C

Read Only. For Debugging Returns a string description of the mapping between the ANTLR grammar and the Xbasic objects.

ParseTree Character

Read Only. For Debugging A string description of the underlying parse tree.

SQLStatement Character

Read Write. A variable that can be assigned a syntax string without parsing it. If no value is passed to the Parse() method, this value is used.

ReplaceOption SQL::Query::ReplaceOption

Read Write Append or Replace

Table Character

Read Write. The table to be imported into.

TokenTypeName Character

Mode E. For SQL::Query, this property returns "Query".

Source SQL::SelectStatement Or SQL::Query::TableReference

Read Write The table reference or the select statement that defines the source of the data.

XML Character

Read Write Creates XML from the parse tree or recreates the tree from the XML.

Methods

Execute Method

Execute the current statement using the current or passed connection.

ExecuteWithEvents Method

Execute the current statement using the current or passed connection handling events with the script provided.

Format Method

Format the original source (by default, lines are broken at significant keywords)..

OpenConnection Method

Generate a native SQL statement using the selected syntax associated with the current or passed connection.

Parse Method

Parse the SQLStatement passed (or the value previously set into the SQLStatement property).

ReleaseConnection Method

Clear out the connection property.

Reset Method

Reset the query as if it had just been created.

Validate Method

Execute the current statement using the current or passed connection.

See Also