jsqlite.TableResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spatialite-android Show documentation
Show all versions of spatialite-android Show documentation
Vector map library written in Java - running on Android and Desktop.
package jsqlite;
import java.util.Vector;
/**
* Class representing an SQLite result set as
* returned by the
* Database.get_table
* convenience method.
*
* Example:
*
*
* ...
* SQLite.Database db = new SQLite.Database();
* db.open("db", 0);
* System.out.print(db.get_table("select * from TEST"));
* ...
*
* Example output:
*
*
* id|firstname|lastname|
* 0|John|Doe|
* 1|Speedy|Gonzales|
* ...
*
*/
public class TableResult implements Callback {
/**
* Number of columns in the result set.
*/
public int ncolumns;
/**
* Number of rows in the result set.
*/
public int nrows;
/**
* Column names of the result set.
*/
public String column[];
/**
* Types of columns of the result set or null.
*/
public String types[];
/**
* Rows of the result set. Each row is stored as a String array.
*/
public Vector rows;
/**
* Maximum number of rows to hold in the table.
*/
public int maxrows = 0;
/**
* Flag to indicate Maximum number of rows condition.
*/
public boolean atmaxrows;
/**
* Create an empty result set.
*/
public TableResult() {
clear();
}
/**
* Create an empty result set with maximum number of rows.
*/
public TableResult(int maxrows) {
this.maxrows = maxrows;
clear();
}
/**
* Clear result set.
*/
public void clear() {
column = new String[0];
types = null;
rows = new Vector();
ncolumns = nrows = 0;
atmaxrows = false;
}
/**
* Callback method used while the query is executed.
*/
public void columns(String coldata[]) {
column = coldata;
ncolumns = column.length;
}
/**
* Callback method used while the query is executed.
*/
public void types(String types[]) {
this.types = types;
}
/**
* Callback method used while the query is executed.
*/
public boolean newrow(String rowdata[]) {
if (rowdata != null) {
if (maxrows > 0 && nrows >= maxrows) {
atmaxrows = true;
return true;
}
rows.addElement(rowdata);
nrows++;
}
return false;
}
/**
* Make String representation of result set.
*/
public String toString() {
StringBuffer sb = new StringBuffer();
int i;
for (i = 0; i < ncolumns; i++) {
sb.append(column[i] == null ? "NULL" : column[i]);
sb.append('|');
}
sb.append('\n');
for (i = 0; i < nrows; i++) {
int k;
String row[] = (String[]) rows.elementAt(i);
for (k = 0; k < ncolumns; k++) {
sb.append(row[k] == null ? "NULL" : row[k]);
sb.append('|');
}
sb.append('\n');
}
return sb.toString();
}
}