Previous Topic

Next Topic

ctSQLImportTable

Imports a table to the c-treeSQL data dictionaries.

Declaration

The function prototype is as follows:

NINT ctSQLImportTable(pCTSQLIMPOPTS pctsqlimpopts);

Description

The caller passes the address of a CTSQLIMPOPTS structure, which specifies the table import options:

typedef struct tagCTSQLIMPOPTS {
     pTEXT     tblnam;          /* name of table to import                        */
     pTEXT     symnam;          /* symbolic table name                            */
     pTEXT     dbsnam;          /* name of c-treeSQL database (default: ctreeSQL) */
     pTEXT     srvnam;          /* c-treeSQL Server name (default: FAIRCOMS)      */
     pTEXT     usrnam;          /* userid for connecting to c-treeSQL Server      */
     pTEXT     usrpwd;          /* password for authentication                    */
     pTEXT     tblown;          /* assign table owner                             */
     SQLCBF    clbkfn;          /* callback function                              */
     NINT      chkfld;          /* skip fields that don't comply with             */
                                /* conventional SQL identifier rules              */
     NINT      skpidx;          /* skip indices                                   */
     NINT      rmlink;          /* unlink table from database                     */
} CTSQLIMPOPTS, *pCTSQLIMPOPTS;

The clbkfn field can be used to specify a callback function called by ctSQLImportTable() in certain situations. If no callback function address is specified, c-tree uses the default callback function SQLLinkCallback() found in ctsqlimp.c. This default callback function prompts the user for input in some situations. To avoid these prompts, developers can implement their own version of this function and can pass the address of this function to ctSQLImportTable() by setting the clbkfn field to the address of the custom callback function.

ctSQLImportTable() is implemented using c-treeDB API functions. An application using only ISAM or low-level functions can call ctSQLImportTable() provided the application #includes the c-treeDB header file ctdbsdk.h and links with a c-tree client library that is built with c-treeDB C API support.

Returns

Value

Symbolic Constant

Explanation

0

NO_ERROR

Successful operation.

12

FNOP_ERR

Could not open file. Either file does not exist, filnam points to incorrect file name, or file is locked by another process. Check sysiocod for the system-level error. For ISAM functions, check isam_fil for the specific file number.

For the client/server model only, if a file open returns FNOP_ERR, check sysiocod. If sysiocod = FCNF_COD, (-8), the file exists but there is file mode conflict preventing the file from being opened. For example, requesting an ctEXCLUSIVE open when the file is already open ctSHARED.

The failure to open the file with system error 32 could happen due to third-party backup software having the file open even if it does not lock regions of the file.

For example, if the software has the file open in exclusive mode, an attempt by c-tree to open the file in shared or exclusive mode will fail. If the software has the file open in shared mode, an attempt by c-tree to open the file in exclusive mode will fail.

See c-tree Plus Error Codes for a complete listing of valid c-tree Plus error values.

Example


NINT rc;
CTSQLIMPOPTS	impopts;

ctsfill(&impopts, 0, sizeof(impopts));
impopts.tblnam = ".\\qasqlimp.dat";
impopts.symnam = "inventory";
impopts.dbsnam = "ctreeSQL";
impopts.srvnam = "FAIRCOMS@localhost";
impopts.usrnam = "ADMIN";
impopts.usrpwd = "ADMIN";
impopts.clbkfn = mySQLLinkCallback;

if (!(rc = ctSQLImportTable(&impopts)))
     ctrt_printf("Import ok\n");
else
     ctrt_printf("Import failed: %d\n", rc);