Database Programming Interface       

Description:
DbTkXml allows you to write custom programs or issue low level
database commands to performs automated or custom database tasks.
You can either use the DbScript utility to execute these commands
or the C++ interface to write custom database applications.

Upon completion of the command the return value indicates the status:
>= 0   successful completion
< 0     error
Also an array of strings is returned with details about error or status conditions.

DbTkXml Commands (in alphabetical order):
Arguments are separated by the pipe symbol '|', the command case does not matter.
Analyze {in} Analyze the input file 'in' - has to be csv/dbf/txt or xml format
CreateDb  
CsvExort [out [|from [|to ]]] Exports data in CSV format for the current table, if no output file 'out' is
specified it will write to "table.csv".
Optionally you can specify the sequential record range to export (1 based):
Example:
csvexport
will export to table.csv all records
DbfExport [out [|from [|to ]]]

 

Exports data in DBF format for the current table, if no output file 'out' is
specified it will write to "table.dbf".
Optionally you can specify the sequential record range to export (1 based):
Example: dbf
export new.dbf|10|
will export to new.dbf and new.dbt starting at record#10
DbLoad [in] Imports data into the database.
If no input is specified the current table in TXT format is used (table.txt)
The input data format is defined by the file extension:
data.csv    = CSV format (Comma seperated values)
data.xml    = XML format
data.txt     = TXT tab demilited format (default)
See dbload.exe for more details
Example:
dbload Employees.csv
imports CSV format from Employees.csv
ExeSql [sql [|na Execute a SQL or Query
sql     = SQL filename
name= query name
Example:
exesql CreateTable.sql|Newtable
Saves CreateTable.sql as a new query Newtable in database and
executes the SQL query.
HtmlExport [out [|from [|to ]]] Exports data in HTML format for the current table, if no output file 'out' is
specified it will write to "table.htm".
Optionally you can specify the sequential record range to export (1 based):
Example: html
export new.htm
will export to new.htm  all records
(see SETFONT)
List {tables|Columns|Data} Display tables or
columns of the current table  or
all records (pipe delimited) of the current table
OpenDb [-res] DB opens access to the specified database filename (DB) (*.mdb or *.dbf)
the previous database will be closed
If the database is read-only you will be prompted to make it writable
(DbTkXml will also check your DB.dbt DBF database file for read-only)
-r    opens in read-only mode
-e   opens in exclusive mode
-s   use silent mode (no read-only check)
returns the list of tables
Example:
opendb sample.mdb
opendb sample_db4.dbf
RunSql [sql [|name [|out [|fmt ]]]] Runs and exports a SQL or Query
sql     = SQL filename
name= query name
out    = export output file (if not defined use name.fmt or sql.fmt)
fmt    = export format (XML, CSV, TXT or HTM) (default is TXT)
Example:
runsql EmpSales.sql|EmpSales|X1.csv|CSV
Saves EmpSales.sql as a new query EmpSales in database and
exports in CSV format to X1.csv

runsql |Catalog||XML
Exports existing query Catalog to Catalog.XML/DTD
SetFont {font} Define a new font for HTML Export.
Example:
setfont Courier New
Table {Tab} Open access to specified table TAB (table name)
You can also specify sequential table number #3 = 3rd table in database
Example:
table Employees    or   table #4
TxtExport [out [|from [|to ]]] Exports data in TXT format for the current table, if no output file 'out' is
specified it will write to "table.txt". (TAB delimited)
Optionally you can specify the sequential record range to export (1 based):
Example:
txtexport new.xml|10|50
will export to new.txt at record#10 until record #50
XmlExport [out [|from [|to ]]] Exports data in XML format for the current table, if no output file 'out' is
specified it will write to "table.xml".
Optionally you can specify the sequential record range to export (1 based):
Example:
xmlexport new.xml|10|
will export to new.xml and new.dtd starting at record#10

Date Format
Dates are exported as MM/DD/YYYY as defined in the INI file (like Db2Xml.ini):
[FORMAT]
To switch to 2 digit year dates use: "DATE=%m/%d/%y"
or European date format "DATE=%d/%m/%Y"

C++ Programming

To demonstrate how easily you can integrate the DbTkXml into your application,
we have created a small sample program:

DbSample.cpp    = Application Code
DbSample.dsp    = Project file
DbSample.dsw    = Works Space
StdAfx.cpp/h        = Standard Includes
DbXmlTool.s.LIB= Libray to link against
DbXmlTools.DLL=DLL to keep with the utilities

#include "stdafx.h"
#include "DbXmlTools.h"

...
//====== INITIALIZE DBTKXML INTERFACE =============
CDbXmlTools *pDbTkXml = new CDbXmlTools;

//====== RUN SAMPLE COMMANDS ======================
CStringArray strResult;
CString strCmd;
int nRet;
do {
   strCmd.Format("opendb ../sample.mdb");
   ret_ = pDbTkXml->ExecCmd(strCmd,&strResult);
   ShowMsg(strResult);
   if (ret_ < 0)
      break;

   strCmd.Format("table Employees");
   ret_ = pDbTkXml->ExecCmd(strCmd,&strResult);
   ShowMsg(strResult);
   if (ret_ < 0)
      break;

   strCmd.Format("XMLExport Emp.XML");
   ret_ = pDbTkXml->ExecCmd(strCmd,&strResult);
   ShowMsg(strResult);
   } while (FALSE);
delete pDbTkXml;

//====== SHOW MESSAGE(S) =================================
void ShowMsg(CStringArray &strResult)
{
   int nMax = strResult.GetSize();
   for (int iPos=0; iPos < nMax; iPos++)
   {
      if (nMax > 1) printf("%3d: %s\n",iPos+1,strResult.GetAt(iPos));
      else printf("%s\n",strResult.GetAt(iPos));
   }

 

Link with the DbXmlTools.LIB library.and execute with the DbXmlTools.DLL module.

 


DbTkXml,DbXml,Database,Export,Import,DBF,SQL,MDB,XML,DTD,HTML,CSV,Access,Toolkit,
Table,Column,Field,Record,Index,Query, Analyze,Csv2Db,Xml2Db,Txt2Db,Dbf2Db,
External Data,Save As,merge,synchronize,explorer,ASCII,distribution,
Db2XML,Db2CSV,Db2Txt,Db2Html,DbLoad,DbExplorer,DbSql,DbQuery,DbScript,
Conversion,Automate,API,Windows,Microsoft,utilities,file,management,administration,
command,line,batch scipts, shareware