is this doable code for writing the the csv to a palm db?
Mainly is the section on writing the record correct logically?
----------------------------
package sample.textcond;
import palm.conduit.*;
import java.io.*;
/**
* Simple example of a java conduit which reads text from a | (pipe)
separated
* file on the desktop and writes them to a Palm DB.
* Implements the palm.conduit.Conduit interface, its name is specified
* when registered with HotSync Manager. It is instantiated
* and run during a HotSync process.
*/
public class TextWrite implements Conduit
{
/** Opens and runs the sample text conduit which writes Records from
* a desktop file and writes them out into a palm db
*
*/
public void open(SyncProperties props)
{
char chr,
lineSep = System.getProperty("line.separator").charAt(0);
DbList list[];
FileInputStream in;
int count,
db,
FieldsPerRow = 3,
i,
ii;
MemoRecord rec;
desc = new StringBuffer(20);
// Tell the log we are starting
Log.startSync();
try
{
// Create our input file
in = new FileInputStream("c:/temp/dean.csv");
// Open our Pilot DB
db = SyncManager.openDB(props.remoteNames[0], (short)0,
(byte)(SyncManager.OPEN_READ |
SyncManager.OPEN_WRITE | SyncManager.OPEN_EXCLUSIVE));
// Find out how many memo records there are in the MemoDB
count = SyncManager.getDBRecordCount(db);
// create reusable record
rec = new MemoRecord();
// Dean: Set the record to zero so it will append the
// the existing Palm DB
rec.setIndex(0);
// Dean: Delete all existing records
for (i = 0; i < count; i++)
{
// Delete the records
deleteRecord(db, i);
} // end of for (i...
// read till end of csv file
while(true)
{
for (ii = 1; ii < FieldsPerRow; ++ii)
{
while ((chr = in.readChar() != ',')
{
desc.append(chr);
}
// write the records text in the Palm DB
rec.setMemo(desc);
// write the record to the Palm DB
writeResourceRec(db, rec);
// Dean: wipe out desc string
desc = "";
}
while ((chr = in.readChar() != lineSep)
{
desc.append(chr);
}
// Dean: write the records text in the Palm DB
rec.setMemo(desc);
// write the record to the Palm DB
writeResourceRec(db, rec);
// Dean: wipe out desc string
desc = "";
} // end of while(true)
// Close DB
SyncManager.closeDB(db);
// Close file
in.close();
// Single Log we are successful
Log.AddEntry("OK TextWriteuit", Log.TEXT, false);
Log.endSync();
} catch (Throwable t)
{
// If there was an error, dump the stack trace
// and tell the log we failed
t.printStackTrace();
Log.abortSync();
}
} // end of public void open(SyncProperties props)
/** Returns a String representation of the conduit name.
*/
public String name()
{
return "TextWrite";
}
/** Entry point for conduit configuration through HS Manager.
* UI code allowing user to configure conduit goes here.
*/
public int configure(ConfigureConduitInfo info)
{
return 0;
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Richard
Burmeister
Sent: Thursday, May 24, 2001 11:44 AM
To: Palm Developer Forum
Subject: RE: Question about syncing comma separated file
> From: Dean Rochester
>
> I have looked through the Java Conduit tutorial and there are samples for
> reading a text file, but that is not quite what I am doing. How do I
> convert this comma separated file file into a DB if I have to?
>
A database on a Palm OS device consists of a collection of records, each one
being < 64K, each containing whatever you want to put there (a single
string, a bunch of UInt's, whatever bytes you want). A CSV is just a text
file in which each line (record) contains some fields, and commas are used
to separate the fields. So, on a Palm device, you could store each record
from the CSV as a string in one record of a Palm database, or you could
parse the fields into separate fields and store all the fields in one
record, with each field stored as the appropriate datatype. Note the Palm
OS does not directly support relational databases. If you want to create a
relational DB, with multiple related tables that each contain fields, you
have to program that yourself (or use one of the third party apps like
SatForms, etc.)
> I looked at ThinkDB and it has a way of reading comma separated
> files in to
> its thinkdb databases on the palm. Since there are no Files on the palm,
> how do I locate this comma separated listing once I do get it to the palm?
>
Under the Palm OS, there are no files. Everything is stored as a resource
database. Your app is a resource database that contains code, the DBs your
app creates and uses are databases, etc. If you want to find a DB someone
else put on your device, use DmGetNextDatabaseByTypeCreator() with 0 for the
type and creator. Or, if you just want to see what DBs are on your device,
but your app doesn't need to look them up, use a program like Insider.
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/