|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--litebase.LitebaseConnection
This class is the one used to issue SQL commands. Read Litebase Companion chapters for more information.
| Field Summary | |
boolean |
aspdb
|
protected java.lang.Object |
bag
|
static int |
LOG_LEVEL_MAX
Maximum log level. |
static int |
LOG_LEVEL_NONE
Default logging level: 0 (no logs generated). |
static int |
version
|
static java.lang.String |
versionStr
|
| Method Summary | |
void |
closeAll()
Close all catalogs, so that they are immediately written to disk (at desktop) or release the file handles (at device). |
void |
convert(java.lang.String tableName)
Convert from stream (.pdb) to plain file. |
static int |
deleteLogFiles()
Deletes all log files found in the device. |
void |
execute(java.lang.String sql)
Used to execute a create table or
create index SQL commands.
|
ResultSet |
executeQuery(java.lang.String sql)
Used to execute queries in a table. |
int |
executeUpdate(java.lang.String sql)
Used to execute updates in a table (insert, delete, update, alter table, drop). |
boolean |
exists(java.lang.String tableName)
Returns if the given table already exists. |
int |
getCurrentRowId(java.lang.String tableName)
Returns the current rowid for a given table. |
static LitebaseConnection |
getInstance(java.lang.String appCrid)
Creates a LitebaseConnection for the given creator id, storing the database in main memory, and as flat file. |
static LitebaseConnection |
getInstance(java.lang.String appCrid,
java.lang.String params)
Creates a LitebaseConnection for the given creator id and with the given connection paramList. |
static java.lang.String |
getLogName()
Returns the name of the catalog used to store the logs, or null if log is disabled. |
int |
getRecordCount(java.lang.String tableName)
Returns the total number of records for a table, which includes the deleted rows, but excluding the record 0, which is used to store the table metadata. |
int |
getRowCount(java.lang.String tableName)
Returns the number of valid rows in a table. |
RowIterator |
getRowIterator(java.lang.String tableName)
Gets an iterator for a table. |
PreparedStatement |
prepareStatement(java.lang.String sql)
Creates a pre-compiled statement with the given sql. |
static LitebaseConnection |
processLogs(java.lang.String[] sql,
java.lang.String params,
boolean debug)
This is a handy method that can be used to reproduce all commands of a log file. |
int |
purge(java.lang.String tableName)
Used to delete physically the records of the given table. |
static void |
setLogLevel(int newLogLevel)
Sets the current log level. |
void |
setRowInc(java.lang.String tableName,
int inc)
Set the row increment used when creating or updating big amounts of data. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected java.lang.Object bag
public static final java.lang.String versionStr
public static final int version
public static final int LOG_LEVEL_NONE
public static final int LOG_LEVEL_MAX
public boolean aspdb
| Method Detail |
public static LitebaseConnection getInstance(java.lang.String appCrid)
appCrid - The creator id, which may (or not) be the same one of your application's.
public static LitebaseConnection getInstance(java.lang.String appCrid,
java.lang.String params)
appCrid - The creator id, which may be the same one of your application's.params - There are two parameters that can be used, one at a time, in lowercase please!
oncard: (on Palm OS devices only - ignored in other platforms) specifies that the
database will be stored in the memory card.
The card used will always be the last card number. Most PDAs will only have one card, but others, like
the Tungsten T5, can have more than one. So, you have to store the databases in the last card slot.
The directory in the card from where the tables will be read and written is \PALM\PDBDATA.
Note that databases belonging to multiple applications can be stored in the same path, since all tables
are prefixed by the application's creator id.
If the pda don't support cards, the databases will be stored in main memory.
aspdb: (on Palm OS devices that have flash memory and desktop application (applet or win32)!):
specifies that a pdb file will be created instead of a flat
file. Note that this settings is applied to all open LitebaseConnection instances, I.E., setting an instance
aspdb will overwrite any other instance's settings. Note also that after setting it aspdb, its impossible
to set it back to use flat files on further instances.
See the Litebase Companion for more information.Due to the slownes of a memory card, all queries will be stored in main memory; only tables and indexes will be stored in the card.
getInstance(String)public void execute(java.lang.String sql)
create table or
create index SQL commands.
Examples:
driver.execute("create table PERSON (NAME CHAR(30), SALARY DOUBLE, AGE INT, EMAIL CHAR(50))");
driver.execute("CREATE INDEX IDX_NAME ON PERSON(NAME)"); // the index name is ignored but must be given
The index can be created after data was added to the table.
An AlreadyCreatedException may be thrown if the index/table was already created.public int executeUpdate(java.lang.String sql)
try {driver.executeUpdate("drop table person");} // will drop also the indexes
catch (DriverException e) {}
try {driver.executeUpdate("drop index * on person");} // will drop all indexes
catch (DriverException e) {}
try {driver.executeUpdate("drop index name on person");} // will drop index for the "name" column
catch (DriverException e) {}
driver.executeUpdate("ALTER TABLE person DROP primary key");
driver.executeUpdate("update person set age=44,salary=3200.5 where name='guilherme campos hazan'");
driver.executeUpdate("delete person where name like 'g%'");
driver.executeUpdate("insert into person (age,salary,name,email) values"+
"(32,2000,'guilherme campos hazan','guich@superwaba.com.br')");
public ResultSet executeQuery(java.lang.String sql)
ResultSet rs = driver.executeQuery("select rowid,name,salary,age from person where age != 44");
rs.afterLast();
while (rs.prev())
Vm.debug(rs.getString(1)+". "+rs.getString(2)+" - "+rs.getInt("age")+" years");
public PreparedStatement prepareStatement(java.lang.String sql)
PreparedStatementpublic int getCurrentRowId(java.lang.String tableName)
public int getRowCount(java.lang.String tableName)
getRecordCount(java.lang.String)
public void setRowInc(java.lang.String tableName,
int inc)
-1 as the
inc argument. Without doing this last step, you may loose data because some writes will be delayed
until you call it with -1. Another good optimization on bulk insertions is to drop the indexes and then
create them afterwards. So, to correctly use setRowInc, you must:
driver.setRowInc("table", totalNumberOfRows);
// fetch the data and insert them
driver.setRowInc("table", -1);
Using prepared statements on insertion makes it another couple of times faster.public void convert(java.lang.String tableName)
public boolean exists(java.lang.String tableName)
public void closeAll()
public int purge(java.lang.String tableName)
Important: the rowid of the records is NOT changed with this operation.
tableName - The table name to purge.public int getRecordCount(java.lang.String tableName)
public RowIterator getRowIterator(java.lang.String tableName)
public static void setLogLevel(int newLogLevel)
LitebaseConnection.setLogLevel(LitebaseConnection.LOG_LEVEL_MAX)To delete all log files, use the
deleteLogFiles method.
At device, the logs are stored in a PDB file named "LITEBASE_YYYYMMDDHHMMSS.CRTR.LOGS",
where CRTR is the Litebase creator id passed on the getInstance method.
At desktop, the log is sent directly to the console.public static int deleteLogFiles()
public static java.lang.String getLogName()
public static LitebaseConnection processLogs(java.lang.String[] sql,
java.lang.String params,
boolean debug)
String []sql =
{
"new LitebaseConnection(MBSL,null)",
"create table PRODUTO (IDPRODUTO int, IDPRODUTOERP char(10), IDGRUPOPRODUTO int, IDSUBGRUPOPRODUTO int, IDEMPRESA char(20), DESCRICAO char(100), UNDCAIXA char(10), PESO float, UNIDADEMEDIDA char(3), EMBALAGEM char(10), PORCTROCA float, PERMITETROCA int)",
"create index IDX_PRODUTO_1 on PRODUTO(IDPRODUTO)",
"create index IDX_PRODUTO_2 on PRODUTO(IDGRUPOPRODUTO)",
"create index IDX_PRODUTO_3 on PRODUTO(IDEMPRESA)",
"create index IDX_PRODUTO_4 on PRODUTO(DESCRICAO)",
"closeAll",
"new LitebaseConnection(MBSL,null)",
"insert into PRODUTO values(1,'19132',2,1,'1,2,3','ABSORVENTE SILHO ABAS','5',13,'PCT','20X30',10,0)",
};
LitebaseConnection.processLogs(sql,true);
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||