In article <urqtjZNNIHA.1192@news-server>, ich@hier.de says...
> Please find attached a Word document with information on
> - how to create an ODBC DSN for text files
> - how to use text files from dBASE
> - Understanding schema.ini and data types
>
> Roland
Roland,
Many thanks for putting this together. I've bookmarked it for future
reference because I'm sure it will be handy some day. It looks like it
does quite a lot.
Just for your future reference <g>, dbase.knowledgebase is meant for
messages concerning the dBI KnowledgeBase on their web site.
dbase.shared-code might be a better bet next time. :-)
--
Geoff Wass [dBVIPS]
Montréal, Québec, Canada
.|.|.| dBASE info at http://geocities.com/geoff_wass |.|.|.
.|.|.| ---------------------------------------------------------- |.|.|.
|
On Mon, 03 Dec 2007 09:48:47 +0000, in dbase.knowledgebase,
Subject: Re: Using the Microsoft text driver from dBASE,
Message-ID: <ZPYA9QZNIHA.2004@news-server>,
Bruce Beacham <bbeacham@beacham.no-spam.co.uk> wrote:
>I'm toying in my mind with the question of whether some process using
>the ODBC text driver can be devised to replace the XDML APPEND FROM xx
>DELIMITED|SDF which will become impossible after ADO arrives, without
>using the file class.
>
>And the COPY TO xx DELIMITED also.
>
>The main need will be to point the ODBC connection to a directory where
>the text file exists or is to exist. It may be that there should be a
>fixed directory on the user's machine to or from which the text file is
>copied for the purpose.
>
Bruce,
You can do it right now with ADO, so why should it not be possible when ADO
arrives?
Try the two files below my signature. First run demomakeTab.prg which creates a
tab-separated file
demoTab.txt from the Fish table and a schema.ini. In other words it could
replace
COPY..To..DELIMITED.
Then run demogetTab.prg which appends three records to an empty Fish table, i.e.
it could replace
APPEND..FROM..DELIMITED
I admit demomakeTab.prg uses the file class. It could be replaced by the ADO
stream class, but I
have not yet figured out hoe to do it ;-)
Ivar B. Jessen
//----- Save as demomakeTab.prg -----
#define adCmdText 1
#define adClipString 2
clear
con=new oleautoclient( "ADODB.Connection")
con.open("Driver={Microsoft dBase Driver
(*.dbf)};DBQ=D:\programmer\dbase\plus221\samples;DriverID=533")
rst = new oleautoclient( "ADODB.Recordset" )
rst.open('select ID, Name, Species, "Length CM" from Fish', con,
adCmdText)
cHdr = ""
for i = 0 to rst.fields.count() - 2
cHdr += rst.fields(i).name + chr(9)
next i
cStr = rst.getstring(2, 100000, chr(9), chr(10)+chr(13))
cHdr += ["] + rst.fields(i).name + ["] + chr(10)
cFile = cHdr + cStr
release object rst; release rst
f = new file()
f.create("demoTab.txt")
f.open("demoTab.txt", "W")
f.write(cFile)
f.close()
release object f; release f
set proc to :duflp:ini.cc
in = new ini("D:\vdbproj\ADO\ADOdemoTAB\Schema.ini")
in.SetValue("demoTAB.txt","ColNameHeader",
"true")
in.SetValue("demoTAB.txt","CharacterSet", "ANSI")
in.SetValue("demoTAB.txt","Format",
"TABDelimited")
in.SetValue("demoTAB.txt","DecimalSymbol", ["."])
in.SetValue("demoTAB.txt","*MaxScanRows", "0")
in.SetValue("demoTAB.txt","Col1", "ID Short")
in.SetValue("demoTAB.txt","Col2", "Name Char Width
30")
in.SetValue("demoTAB.txt","Col3", "Species Char Width
40")
in.SetValue("demoTAB.txt","Col4", ["Length CM"
Float])
in.release()
close procedure :duflp:ini.cc
//-----
//----- Save as demogetTab.prg -----
#define adCmdText 1
#define adOpenStatic 3
close all
clear
con=new oleautoclient( "ADODB.Connection.2.7")
con.open("Driver={Microsoft Text Driver (*.txt;
*.csv)};DBQ=D:\vdbproj\ADO\ADOdemoTAB;Extensions=asc,csv,tab,txt;HDR=YES;FMT=CSV
Delimited")
rst = new oleautoclient( "ADODB.Recordset" )
rst.open('select * from [demoTab.txt] where ID between 3 and 5 order by ID',
con, adOpenStatic,
adCmdText)
copy table :dbasesamples:Fish to Fish
set safety off
use Fish excl
zap
use
set safety on
?
q = new query()
q.sql = 'select * from Fish'
q.active = true
q.rowset.first()
rst.moveFirst()
for j = 1 to rst.recordcount()
q.rowset.beginAppend()
for i = 1 to rst.fields.count() - 1
q.rowset.fields[i+1].value := rst.fields(i).value
next i
rst.moveNext()
next j
q.rowset.save()
release object rst; release rst
q.active = false
use Fish
browse
//-----
|