<HTML><HEAD><TITLE>Re: [Gvsig_desarrolladores] como aadir una linea a un dbf que no es de un shape en mobile</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.17023" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText36329>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Hola.</FONT></DIV>
<DIV> </DIV>
<DIV>Añadir una fila a un DBF implica tamién modificar la cabecera del archivo DBF (no es solamente añadir cosas al final), así que no creo que sea fácil añadir una línea a un DBF en una PDA sin reescribir todo el archivo. </DIV>
<DIV> </DIV>
<DIV>Si has de manejar en la PDA archivos DBF que no son muy pequeños, lo lógico sería:</DIV>
<DIV> </DIV>
<DIV>- Cargar el DBF en memoria (eso ya lo estás haciendo)</DIV>
<DIV>- Modificar (en memoria) el DBF varias veces durante la sesión de trabajo</DIV>
<DIV>- Una vez terminado el trabajo, almacenar en disco el DBF, escribiéndolo completamente</DIV>
<DIV> </DIV>
<DIV>¿Esto no es posible en tu caso? ¿De qué tamaño es tu DBF? ¿Puedes explicar un poco como usas los DBF? (desde el punto de vista de un usuario)</DIV>
<DIV> </DIV>
<DIV>Saludos,</DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3></FONT> </DIV></DIV>
<DIV id=idSignature10991>
<DIV><FONT face="Courier New" size=2><FONT face="Times New Roman" size=3>Juan Lucas Domínguez Rubio<BR></FONT>---</FONT></DIV>
<DIV><FONT face="Courier New" size=2><FONT face="Courier New" size=2><FONT face="Courier New" size=2>Prodevelop SL, Valencia (España)</FONT></DIV>
<DIV>
<DIV><FONT face="Courier New" size=2>Tlf.: 96.351.06.12 -- Fax: 96.351.09.68<BR></FONT><A href="http://www.prodevelop.es/"><FONT face="Courier New" size=2>http://www.prodevelop.es</FONT></A><BR><FONT face="Courier New" size=2>---</FONT></DIV></FONT></DIV></FONT></DIV>
<DIV><BR>
<HR>
<FONT face=Tahoma size=2><B>De:</B> gvsig_desarrolladores-bounces@listserv.gva.es en nombre de agirrearri<BR><B>Enviado el:</B> mié 09/06/2010 12:01<BR><B>Para:</B> gvsig_desarrolladores@listserv.gva.es<BR><B>Asunto:</B> Re: [Gvsig_desarrolladores] como añadir una linea a un dbf que no es de un shape en mobile<BR></FONT><BR></DIV>
<DIV><BR>
<P><FONT size=2>Yo solo quiero que meta la linea y no que lo escriba de nuevo. Y por lo que<BR>he entendido la forma en lo que me has dicho se escribe toda la tabla. Al<BR>ser una aplicacin de pda y eso afectara mucho segn vaya creciendo la<BR>tabla.<BR>Ahora tengo esto, lo cope de este foro a uno que tena el mismo problema.<BR><BR>public void addFila(String idapoyo, String idInci, boolean cerradaCheck,<BR> String descVis, String fotoVisita, String fechaVisita) {<BR> // Funcin que aada una fila a una tabla.<BR> // ENTRADA: newRow => hashmap con los datos de la fila a insertar.<BR> // fName => ruta completa del dbf<BR> //tine un problema:tiene que reescribir toda la tabla y eso<BR> //supone un gasto de memoria y tiempo<BR><BR> Object newLinea[] = new Object[9];<BR> newLinea[0] = new Integer(0);//gid<BR> newLinea[1] = new Integer(0);//idcor<BR> newLinea[2] = new Double(idapoyo);//id<BR> newLinea[3] = new Double(idInci);//idinci<BR> newLinea[4] = fechaVisita;//fechacor<BR> if (cerradaCheck) {//corregida<BR> newLinea[5] = new Integer(0);//Integer.getInteger("0");<BR> } else {<BR> newLinea[5] = new Integer(-1);//Integer.getInteger("-1");<BR> }<BR> newLinea[6] = descVis;//correccion<BR> newLinea[7] = fotoVisita;//fotovisita<BR> if (cerradaCheck) {//corregida<BR> newLinea[8] = new Integer(0);//Integer.getInteger("0");<BR> } else {<BR> newLinea[8] = new Integer(-1);//Integer.getInteger("-1");<BR> }<BR><BR><BR> <BR> try {<BR> File f;<BR> f = new File(nombre_dbf);<BR> DbfMemoryDataSource drv;<BR> drv = new DbfMemoryDataSource(f);<BR> drv.start();<BR><BR> int numFilas = (int) drv.getRowCount();<BR> int numCols = drv.getFieldCount();<BR><BR> DbaseFileHeaderNIO myHeader;<BR> myHeader = DbaseFileHeaderNIO.createDbaseHeader(drv);<BR> numFilas++;<BR> myHeader.setNumRecords(numFilas);<BR><BR> OrderFileOutputStream outStream = new OrderFileOutputStream(f);<BR> DbaseFileWriterNIO dbfWrite = new DbaseFileWriterNIO(myHeader,<BR> outStream);<BR><BR> FeatureTemp fea = new FeatureTemp();<BR> fea.setFieldNames(drv.getFieldNames());<BR><BR> for (int j = 0; j < numFilas - 1; j++) {<BR><BR> fea.setValues(drv.getRow(j));<BR> Object[] record = fea.getValues();<BR> dbfWrite.write(record);<BR> }<BR><BR> Object[] record = new Object[numCols];<BR><BR> for (int k = 0; k < numCols; k++) {<BR> // record to string obj to string zan<BR> record[k] = ValueFactory.createValueByType(newLinea[k]<BR> .toString(), drv.getFieldType(k));<BR> }<BR> dbfWrite.write(record);<BR> dbfWrite.close();<BR> outStream.close();<BR><BR> } catch (Exception e) {<BR> // TODO Auto-generated catch block<BR> e.printStackTrace();<BR> }<BR><BR> }<BR><BR>Hay posibilidad de aadir un registro sin tener que escribirlo de nuevo?<BR><BR>pd. yo utilizo javaDBF en para leer unos dbf-s en gvsig mobile y funciona en<BR>pda.<BR><BR>Gracias, atentamente Eaut.<BR>--<BR>View this message in context: <A href="http://osgeo-org.1803224.n2.nabble.com/como-a-adir-una-linea-a-un-dbf-que-no-es-de-un-shape-en-mobile-tp5154700p5157624.html">http://osgeo-org.1803224.n2.nabble.com/como-a-adir-una-linea-a-un-dbf-que-no-es-de-un-shape-en-mobile-tp5154700p5157624.html</A><BR>Sent from the gvSIG desarrolladores mailing list archive at Nabble.com.<BR>_______________________________________________<BR>gvSIG_desarrolladores mailing list<BR>gvSIG_desarrolladores@listserv.gva.es<BR><A href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</A><BR></FONT></P></DIV></BODY></HTML>