summaryrefslogtreecommitdiffstats
path: root/sqlite-jdbc/src/main/java/SQLite/TableResult.java
diff options
context:
space:
mode:
Diffstat (limited to 'sqlite-jdbc/src/main/java/SQLite/TableResult.java')
-rw-r--r--sqlite-jdbc/src/main/java/SQLite/TableResult.java86
1 files changed, 56 insertions, 30 deletions
diff --git a/sqlite-jdbc/src/main/java/SQLite/TableResult.java b/sqlite-jdbc/src/main/java/SQLite/TableResult.java
index 1a7fb57..14337aa 100644
--- a/sqlite-jdbc/src/main/java/SQLite/TableResult.java
+++ b/sqlite-jdbc/src/main/java/SQLite/TableResult.java
@@ -60,11 +60,32 @@ public class TableResult implements Callback {
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();
+ clear();
+ }
+
+ /**
+ * Create an empty result set with maximum number of rows.
+ */
+
+ public TableResult(int maxrows) {
+ this.maxrows = maxrows;
+ clear();
}
/**
@@ -72,10 +93,11 @@ public class TableResult implements Callback {
*/
public void clear() {
- column = new String[0];
- types = null;
- rows = new Vector();
- ncolumns = nrows = 0;
+ column = new String[0];
+ types = null;
+ rows = new Vector();
+ ncolumns = nrows = 0;
+ atmaxrows = false;
}
/**
@@ -83,8 +105,8 @@ public class TableResult implements Callback {
*/
public void columns(String coldata[]) {
- column = coldata;
- ncolumns = column.length;
+ column = coldata;
+ ncolumns = column.length;
}
/**
@@ -92,7 +114,7 @@ public class TableResult implements Callback {
*/
public void types(String types[]) {
- this.types = types;
+ this.types = types;
}
/**
@@ -100,11 +122,15 @@ public class TableResult implements Callback {
*/
public boolean newrow(String rowdata[]) {
- if (rowdata != null) {
- rows.addElement(rowdata);
- nrows++;
- }
- return false;
+ if (rowdata != null) {
+ if (maxrows > 0 && nrows >= maxrows) {
+ atmaxrows = true;
+ return true;
+ }
+ rows.addElement(rowdata);
+ nrows++;
+ }
+ return false;
}
/**
@@ -112,22 +138,22 @@ public class TableResult implements Callback {
*/
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();
+ 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();
}
}