Necesito ayuda con Append From

Necesito ayuda con Append From

Postby Magdielgh » Fri Sep 12, 2008 1:36 pm

Hola.

Necesito importar un archivo de texto, delimitado con pipes y estoy intentandolo con el append from.

La sintaxis que estoy usando es:

Append from ("D:\Import\proveeds.txt") DELIMITED WITH "|"

Y todo compila. Al momento de ejecutar indica un error

Error description: Error BASE/1082 Argument error: -
Args:
[ 1] = N 30850.15
[ 2] = U

Alguien puede señalarme lo que estoy haciendo mal.???

De antemano, les agradezco.

Mag
Magdielgh
 
Posts: 2
Joined: Fri Sep 12, 2008 1:21 pm

Postby Marco Augusto » Fri Sep 12, 2008 1:46 pm

YO LE QUITARIA PARENTESIS Y COMILLAS:

Append from D:\Import\proveeds.txt DELIMITED WITH "|"
Marco Augusto Rodriguez Manzo
FWH January 2020 Xharbour 1.2.3
MySQL 5.0.19 Fastreport

PERZO SOFT
Sistemas Personalizados
User avatar
Marco Augusto
 
Posts: 141
Joined: Wed Oct 12, 2005 1:03 pm
Location: Cuernacava, Morelos Mexico

Postby karinha » Fri Sep 12, 2008 1:53 pm

Code: Select all  Expand view
Syntax

     APPEND FROM <xcFile>
        [FIELDS <idField list>]
        [<scope>] [WHILE <lCondition>] [FOR <lCondition>]
        [SDF | DELIMITED [WITH BLANK | <xcDelimiter>] |
        [VIA <xcDriver>]]
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Necesito ayuda con Append From

Postby FranciscoA » Fri Sep 12, 2008 2:30 pm

DELIMITED identifies an ASCII text file where character fields are
enclosed in double quotation marks (the default delimiter). Note that
delimiters are not required and CA-Clipper correctly APPENDs character
fields not enclosed in them. Fields and records are variable length.

DELIMITED WITH BLANK identifies an ASCII text file in which fields
are separated by one space and character fields are not enclosed in
delimiters.

DELIMITED WITH <xcDelimiter> identifies a delimited ASCII text file
where character fields are enclosed using the specified delimiter. You
can specify <xcDelimiter> as a literal character or as a character
expression enclosed in parentheses.


Saludos.
User avatar
FranciscoA
 
Posts: 2110
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Postby carlos vargas » Fri Sep 12, 2008 2:53 pm

haceunos meses tuve necesidad de una rutina que importara el contenido de un txt de 40mb aprox, no recuerdo quien posteo esta necesidad, me dispuse a ayudarlo y con una sencilla app permitia importar el txt a una dbf con el append from, pero este fallaba, no agregando todos los campos disponibles, lo que hice fue hacer la misma cosa pero en vfp y esta funciono sin drama. (aca use exactamente la misma instruccion append que en xharbour)

recuerdo que usaba el DELIMITED WITH ";" y este fallaba.
ya que si bien agregaba los xxx numeros de registro la info de los campos falla.

"001",,,,,,
"002",0,.t.,"20080901"

por ejemplo.

les recuerdo que el txt era muy grande.

no se si a estas alturas se habra corregido el problema. :-(

salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1683
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Postby Mayor_Valenzuela » Fri Sep 12, 2008 4:16 pm

Mira tube un problema similar pues cuando las txt eran demasiado extensas cada cierta cantidad de datos algunos me importaban el CHR(10), debido a esto tube que cambiar las fuentes de harbour y enlazarlas como una funcion mas dentro de mis aplicaciones... esto es..

#include "hbcommon.ch"
#include "fileio.ch"
#include "error.ch"

#define AppendEOL( handle ) FWRITE( handle, CHR( 13 ) + CHR( 10 ) )
#define AppendEOF( handle ) FWRITE( handle, CHR( 26 ) )
#define AppendSep( handle, cSep ) FWRITE( handle, cSep )

*..............................................................................................................................*
FUNCTION dbAppFrom( lExport, cFile, cDelimArg, aFields, bFor, bWhile, nNext, nRecord, lRest )
LOCAL index, handle, lWriteSep, cFileName := cFile, nStart, nCount, oErr
LOCAL cSeparator := ","
LOCAL cDelim := CHR( 34 )
//------------------
local Pos:=0
local nPosFl:=0
local nDimBuff:=65535
local cByte :=""
local lunghezze:={}
local eol:=chr(13)+chr(10)
local contacamp:=0
local primariga:=.t.
local offset:=0
local rig:=0
local cont_r:=""
local Lfinefile:=.f.
local nFileLen
local cCharEol:=HB_OSNewLine()
local nLenEol:=LEN(cCharEol)
local nPosLasteol
local lcisonoeol

lRest := IIf( lRest != Nil, lRest, .f. )
//------------------
// Process the delimiter argument.
IF !EMPTY( cDelimArg )
IF UPPER( cDelimArg ) == "BLANK"
cDelim := ""
cSeparator := " "
ELSE
cDelim := LEFT( cDelimArg, 1 )
END IF
END IF

// Process the file name argument.
index := RAT( ".", cFileName )
IF index > 0
// The file name might include a file extension.
IF RAT( "/", cFileName ) > index ;
.OR. RAT( "\", cFileName ) > index
// No, the file extension is in a directory name.
index := 0
END IF
END IF
IF index <= 0
// No file name extension, so provide the default.
cFileName += ".txt"
END IF

// Determine where to start and how many records to process.
IF nRecord != NIL
// The RECORD clause has the highest priority.
nStart := nRecord
nCount := 1
ELSEIF nNext != NIL
// The NEXT clause has the next highest priority.
nStart := -1
nCount := nNext
ELSEIF bWhile != NIL .OR. lRest
// The WHILE and REST clauses have equal priority.
nStart := -1
nCount := -1
ELSE
// Followed by the FOR clause or the ALL clause.
nStart := 0
nCount := -1
END IF
IF EMPTY( bFor )
// This simplifies the test that determines whether or not to
// use (i.e., import or export) any given processed record.
bFor := {||.T.}
END IF

IF lExport
// COPY TO DELIMITED
handle := FCREATE( cFileName )
IF handle == -1
oErr := ErrorNew()
oErr:severity := ES_ERROR
oErr:genCode := EG_CREATE
oErr:subSystem := "DELIM"
oErr:subCode := 1002
oErr:description := HB_LANGERRMSG( oErr:genCode )
oErr:canRetry := .T.
oErr:canDefault := .T.
oErr:fileName := cFileName
oErr:osCode := FERROR()
Eval(ErrorBlock(), oErr)
ELSE
IF nStart > -1
// Only reposition if a starting record was specified or implied.
IF nStart == 0
GO TOP
ELSE
GO (nStart)
END IF
END IF
IF EMPTY( bWhile )
// This simplifies the looping logic.
bWhile := {||.T.}
END IF
// Set up for the start of the first record.
lWriteSep := .F.
// Process the records to copy delimited.
WHILE EVAL( bWhile ) .AND. ( nCount == -1 .OR. nCount > 0 ) ;
.AND. !BOF() .AND. !EOF()
IF EVAL( bFor )
IF EMPTY( aFields )
// Process all fields.
FOR index := 1 TO FCOUNT()
IF lWriteSep
AppendSep( handle, cSeparator )
END IF
lWriteSep := ExportVar( handle, FIELDGET( index ), cDelim )
NEXT index
ELSE
// Process the specified fields.
FOR index := 1 TO LEN( aFields )
IF lWriteSep
AppendSep( handle, cSeparator )
END IF
lWriteSep := ExportVar( handle, FIELDGET( FIELDPOS( aFields[ index ] ) ), cDelim )
NEXT index
END IF
// Set up for the start of the next record.
AppendEOL( handle )
lWriteSep := .F.
END IF
IF nCount != -1
nCount--
END IF
SKIP
END WHILE
AppendEOF( handle )
FCLOSE( handle )
END IF
ELSE
// APPEND FROM DELIMITED
handle := FOPEN( cFileName )
IF handle == -1
oErr := ErrorNew()
oErr:severity := ES_ERROR
oErr:genCode := EG_OPEN
oErr:subSystem := "DELIM"
oErr:subCode := 1001
oErr:description := HB_LANGERRMSG( oErr:genCode )
oErr:canRetry := .T.
oErr:canDefault := .T.
oErr:fileName := cFileName
oErr:osCode := FERROR()
Eval(ErrorBlock(), oErr)
ELSE
IF EMPTY( bWhile )
// This simplifies the looping logic.
bWhile := {||.T.}
ENDIF
// ---------------------------------------
// Please fill with the other test here
// Marco Braida 2002
// marcobra@elart.it
// ---------------------------------------

nFileLen:=FSEEK(handle,0,FS_END)
nDimBuff:=min(nFileLen,nDimBuff)
cByte:=space(nDimBuff)
FSEEK(handle,0)
// cCharEol:=chr(13)
nPosLastEol:=0
do while .not. lFineFile
fseek(handle,nPoslastEol,FS_SET) // forward the pointer
//we must not go after the eof
if nPosLastEol + nDimBuff > nFileLen
// change the buffer size
nDimBuff:=nFileLen-nPosLastEol
cByte:=space(nDimBuff)
Lfinefile:=.t.
endif
// fill the buffer
cByte:=space(nDimBuff)
fread(handle,@cByte,nDimBuff)
// with +1 there is a problem on large import of data
// for now we keep it remmed
// please test and test and test
nPoslastEol+=rat(cCharEol,cByte) // +1
//do this if in the buffer there are eol char
lcisonoeol:=.t.
do while lcisonoeol
// the position of the first eol
nposfl:=at(cCharEol,cByte)
lcisonoeol:=(nPosfl>0)
if lcisonoeol
// cut the row
Pos:=1
cont_r:=substr(cByte,Pos,nposfl-Pos)
AppendData(cont_r,cSeparator,cDelim)
// skipping the line feed and now we are on a good char
pos:=nposfl+nLenEol
cont_r:=""
//cut the row
cByte:=substr(cByte,Pos)
endif
enddo
enddo
FCLOSE( handle )
END IF

END IF
RETURN ( Nil )

*..............................................................................................................................*
STATIC FUNCTION ExportVar( handle, xField, cDelim )
DO CASE
CASE VALTYPE( xField ) == "C"
FWRITE( handle, cDelim + TRIM( xField ) + cDelim )
CASE VALTYPE( xField ) == "D"
FWRITE( handle, DTOS( xField ) )
CASE VALTYPE( xField ) == "L"
FWRITE( handle, iif( xField, "T", "F" ) )
CASE VALTYPE( xField ) == "N"
FWRITE( handle, LTRIM( STR( xField ) ) )
OTHERWISE
RETURN .F.
END CASE
RETURN .T.

*..............................................................................................................................*
STATIC FUNCTION AppendData(row,cSeparator,cDelim)
local lenrow:=len(row)
local aStruct:=DBSTRUCT()
local aMyVal:={}
local ii:=1
local nPosSep:=0, nPosNextSep:=0
local nDBFFields
local cBuffer, cUPbuffer
local vRes
local nPos1Deli, nPos2Deli
//if there is one field only there is no Separator and i put...
row:=row+cSeparator
nPosSep:=1
nPosNextSep:=at(cSeparator,row) // seek the first Separator eg. ,
nPos1Deli:=at(cDelim,row) // seek the first delimiter "
nPos2Deli:=at(cDelim+cSeparator,row,nPos1Deli+1) // seek the second delimiter "
if nPos1Deli > 0 .and. nPos2Deli > 0
if nPosNextSep>nPos1Deli .and. nPosNextSep<nPos2Deli
nPosSep:=nPos1Deli
nPosNextSep=nPos2Deli+1
endif
endif
aadd( aMyval,substr(row,nPosSep,nPosNextSep-1) )
nPosSep:=nPosNextSep
do while .t.
nPosNextSep:=at(cSeparator,row,nPosSep+1)
if nPosNextSep=0
exit
endif
nPos1Deli:=at(cDelim,row,nPosSep) // seek the first delimiter "
nPos2Deli:=at(cDelim+cSeparator,row,nPos1Deli+1) // seek the second delimiter "
if nPos1Deli > 0 .and. nPos2Deli > 0
if nPosNextSep>nPos1Deli .and. nPosNextSep<nPos2Deli
nPosSep=nPos1Deli
nPosNextSep=nPos2Deli+1
endif
endif
aadd( aMyVal,substr(row,nPosSep+1,nPosnextSep-nPosSep-1) )
nPosSep:=nPosNextSep
if nPosSep>lenrow
exit
endif
enddo
nDBFfields:=min(len(aMyVal),len(aStruct))
append blank

for ii:=1 to nDBFfields
cBuffer:=strtran(aMyval[ii],cDelim,'')
DO CASE
CASE aStruct[ ii,2 ] == "D"
vRes := HB_STOD( cBuffer )
CASE aStruct[ ii,2 ] == "L"
cUPbuffer:=upper(cBuffer)
vRes := iif( cUPBuffer == "T" .or. cUPBuffer== "1" .or. cUPBuffer=="Y",.T.,.F. )
CASE aStruct[ ii,2 ] == "N"
vRes := VAL( cBuffer )
OTHERWISE
vRes := cBuffer // Cuando se marca el final del buffer con CHR(10) en caso de archivos extensos
If ( ii = 1 ) // el primer campo de a agregar a la base es mas grande que la longitud de misma
If ( Len(vRes) > aStruct[ii,3] ) // es por esto que solo se valida el campo primero y si este resulta ser mas ancho
vRes := SpaceLeft(aStruct[ii,3], Alltrim(vRes)) // se quita el Chr(10) y se deja del mismo tamaño.
EndIf
EndIf
END CASE

FIELDPUT(ii,vRes)

next

return .T.
*..............................................................................................................................*
Static Function SpaceLeft(Arg1,Arg2)
Local Local1

Arg2 := Alltrim( Arg2 )
Local1 := Repl(' ', Arg1)
Local1 := Local1 + Arg2

Return Right(Local1,Arg1)
*..............................................................................................................................*

Las unicas anotaciones en español son las modificaciones, la sentencia para diferenciarla del Append from es:

Agrega Desde F:\Softland\Datos\Hyt\Items.prn Delimitado


y el archivo de cabecera es:

/*
En reemplazo de APPEND FROM función extraida de __dbDelim y mejorada
por Mario Valenzuela M. 16/10/2006
*/

#command AGREGA [DESDE <(file)>] [DELIMITADO [CON <*delim*>]] ;
[FIELDS <fields,...>] ;
[FOR <for>] ;
[WHILE <while>] ;
[NEXT <next>] ;
[RECORD <rec>] ;
[<rest:REST>] ;
[ALL] ;
=> ;
dbAppFrom( .F., <(file)>, <(delim)>, { <(fields)> }, ;
<{for}>, <{while}>, <next>, <rec>, <.rest.> )


/*
En reemplazo de TOTAL ON función extraida de __dbTotal y mejorada
por Mario Valenzuela M. 04/12/2007, Para la suma de no en otra tabla
sino en una matriz.
*/


#command TOTAL [EN <(file)>] [CON <key>] ;
[ARRAY <aArray,...>] ;
[CAMPOS <fields,...>] ;
[FOR <for>] ;
[WHILE <while>] ;
[NEXT <next>] ;
[RECORD <rec>] ;
[<rest:REST>] ;
[ALL] ;
;
=> dbTotalis( ;
<(file)>, <{key}>, { <(fields)> }, { <(aArray)> }, ;
<{for}>, <{while}>, <next>, <rec>, <.rest.> ;
)

Ojala te sirva de algo, por lo menos a mi no me proboco mas problemas....
User avatar
Mayor_Valenzuela
 
Posts: 62
Joined: Tue Jul 08, 2008 4:27 pm
Location: Santiago, Chile

Postby Armando » Fri Sep 12, 2008 4:31 pm

Amigos:

Tal vez una alternativa a esos problemas sea la clase TTxtFile()

Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3061
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Encontre otro camino

Postby Magdielgh » Sat Sep 13, 2008 5:48 pm

Hola a todos.

Les agradezco el apoyo. Lo estuve intentando a mas no poder y al parecer el detalle estaba en el formato de la fecha con que importaba los datos a mi dbf.

No me fue posible formatear los datos de mi archivo individualmente, asi que cambie de estrategia.

Cargue los datos a un arreglo multidimensional. Luego, con APPEND BLANK y REPLACE hice los inserts.

Esto me permitio formatear los datos individualmente y poder cargarlos.

Gracias!

Magg
Magdielgh
 
Posts: 2
Joined: Fri Sep 12, 2008 1:21 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 80 guests

cron