Files
org.ccalm.asdc/app/src/main/java/tools/TCTableTools2.java

53 lines
1.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tools;
import android.database.Cursor;
import java.io.OutputStream;
import tctable.TCField;
import tctable.TCTable;
public class TCTableTools2 {
public static int convertType(int type)
{
int result;
if (type == Cursor.FIELD_TYPE_NULL) { //Такого типа у меня нет
result=TCField.BD_NULL;
} else if (type == Cursor.FIELD_TYPE_BLOB) {
result=TCField.BD_BLOB_4;
} else if (type == Cursor.FIELD_TYPE_FLOAT) { //Похоже что это почти в SQLITE но перед вставкой преобразуется в нужный тип
result=TCField.BD_SFLOAT8;
} else if (type == Cursor.FIELD_TYPE_INTEGER) {
result=TCField.BD_SINT8;
} else if (type == Cursor.FIELD_TYPE_STRING) {
result=TCField.BD_UTF8_4;
}
else result=TCField.BD_UTF8_4;
return result;
}
//Записать таблицу в OutputStream из курсора андроида
public static boolean getTCTableFromCursor(String name, int id, Cursor cursor, OutputStream os) {
TCTable tbl = new TCTable(name, id);
String[] columnNames = cursor.getColumnNames();
boolean first=true;
while (cursor.moveToNext()) {
if(first){
for (int i = 0; i < columnNames.length; i++) {
TCField field = new TCField(columnNames[i], TCTableTools2.convertType(cursor.getType(i)));
tbl.addField(field);
}
tbl.getHeader(os);
first=false;
}
for (int i = 0; i < columnNames.length; i++) {
tbl.fields.get(i).setValue(cursor.getString(i));
}
tbl.getCol(os);
}
return true;
}
}