mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.7.3.1
This commit is contained in:
@@ -36,7 +36,7 @@ public class Db_cmd_mode {
|
||||
case Tid_ignore: // must mark for update
|
||||
case Tid_update: // return self
|
||||
return Tid_update;
|
||||
default: throw Exc_.new_unhandled(cur);
|
||||
default: throw Err_.new_unhandled(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class Db_conn_info_pool {
|
||||
Db_conn_info prototype = (Db_conn_info)regy.Get_by(url_tid);
|
||||
return prototype.New_self(raw, m);
|
||||
}
|
||||
catch(Exception exc) {throw Exc_.new_parse_exc(exc, Db_conn_info.class, raw);}
|
||||
catch(Exception exc) {throw Err_.new_parse_exc(exc, Db_conn_info.class, raw);}
|
||||
}
|
||||
public static final Db_conn_info_pool _ = new Db_conn_info_pool();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Db_conn_pool {
|
||||
public Db_conn Get_or_new(Db_conn_info url) {
|
||||
Db_conn rv = (Db_conn)conn_hash.Get_by(url.Xto_api());
|
||||
if (rv == null) {
|
||||
Db_engine prime = (Db_engine)engine_hash.Get_by(url.Tid()); if (prime == null) Exc_.new_("db engine prototype not found", "tid", url.Tid());
|
||||
Db_engine prime = (Db_engine)engine_hash.Get_by(url.Tid()); if (prime == null) Err_.new_wo_type("db engine prototype not found", "tid", url.Tid());
|
||||
Db_engine clone = prime.New_clone(url);
|
||||
rv = new Db_conn(clone);
|
||||
conn_hash.Add(url.Xto_api(), rv);
|
||||
|
||||
@@ -24,23 +24,23 @@ public class Db_rdr__basic implements Db_rdr {
|
||||
public String Sql() {return sql;} private String sql;
|
||||
public boolean Move_next() {
|
||||
try {return rdr.next();}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "move_next failed; check column casting error in SQL", "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "move_next failed; check column casting error in SQL", "sql", sql);}
|
||||
}
|
||||
@gplx.Virtual public byte[] Read_bry(String k) {try {return (byte[])rdr.getObject(k);} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Bry_.Cls_val_name);}}
|
||||
@gplx.Virtual public byte[] Read_bry_by_str(String k) {try {return Bry_.new_u8((String)rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", String_.Cls_val_name);}}
|
||||
@gplx.Virtual public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Exc_.new_unimplemented();}
|
||||
@gplx.Virtual public String Read_str(String k) {try {return (String)rdr.getObject(k);} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", String_.Cls_val_name);}}
|
||||
@gplx.Virtual public byte[] Read_bry(String k) {try {return (byte[])rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Bry_.Cls_val_name);}}
|
||||
@gplx.Virtual public byte[] Read_bry_by_str(String k) {try {return Bry_.new_u8((String)rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", String_.Cls_val_name);}}
|
||||
@gplx.Virtual public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Err_.new_unimplemented();}
|
||||
@gplx.Virtual public String Read_str(String k) {try {return (String)rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", String_.Cls_val_name);}}
|
||||
@gplx.Virtual public DateAdp Read_date_by_str(String k) {return DateAdp_.parse_iso8561(Read_str(k));}
|
||||
@gplx.Virtual public int Read_int(String k) {try {return Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Int_.Cls_val_name);}}
|
||||
@gplx.Virtual public long Read_long(String k) {try {return Long_.cast_(rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Long_.Cls_val_name);}}
|
||||
@gplx.Virtual public float Read_float(String k) {try {return Float_.cast_(rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Float_.Cls_val_name);}}
|
||||
@gplx.Virtual public double Read_double(String k) {try {return Double_.cast_(rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Double_.Cls_val_name);}}
|
||||
@gplx.Virtual public byte Read_byte(String k) {try {return Byte_.cast_(rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Byte_.Cls_val_name);}}
|
||||
@gplx.Virtual public boolean Read_bool_by_byte(String k) {try {return Byte_.cast_(rdr.getObject(k)) == 1;} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Bool_.Cls_val_name);}}
|
||||
@gplx.Virtual public Object Read_obj(String k) {try {return rdr.getObject(k);} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "key", k, "type", Object_.Cls_val_name);}}
|
||||
@gplx.Virtual public int Read_int(String k) {try {return Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Int_.Cls_val_name);}}
|
||||
@gplx.Virtual public long Read_long(String k) {try {return Long_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Long_.Cls_val_name);}}
|
||||
@gplx.Virtual public float Read_float(String k) {try {return Float_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Float_.Cls_val_name);}}
|
||||
@gplx.Virtual public double Read_double(String k) {try {return Double_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Double_.Cls_val_name);}}
|
||||
@gplx.Virtual public byte Read_byte(String k) {try {return Byte_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Byte_.Cls_val_name);}}
|
||||
@gplx.Virtual public boolean Read_bool_by_byte(String k) {try {return Byte_.cast_(rdr.getObject(k)) == 1;} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Bool_.Cls_val_name);}}
|
||||
@gplx.Virtual public Object Read_obj(String k) {try {return rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Object_.Cls_val_name);}}
|
||||
@gplx.Virtual public void Rls() {
|
||||
try {rdr.close();}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "close failed");}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "close failed");}
|
||||
if (stmt != null) stmt.Rls();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ public class Db_stmt_ {
|
||||
return conn.Stmt_new(Db_qry_sql.rdr_(sql));
|
||||
}
|
||||
public static Err err_(Exception e, Db_stmt stmt, String proc) {
|
||||
throw Exc_.new_exc(e, "db", "db stmt failed", "proc", proc);
|
||||
throw Err_.new_exc(e, "db", "db stmt failed", "proc", proc);
|
||||
}
|
||||
public static Err err_(Exception e, String tbl, String proc) {
|
||||
throw Exc_.new_exc(e, "core", "db call failed", "tbl", tbl, "proc", proc);
|
||||
throw Err_.new_exc(e, "core", "db call failed", "tbl", tbl, "proc", proc);
|
||||
}
|
||||
public static Db_stmt Rls(Db_stmt v) {if (v != null) v.Rls(); return null;}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Db_stmt_bldr {
|
||||
case Db_cmd_mode.Tid_update: if (update == null) update = conn.Stmt_update(tbl_name, flds_keys, flds_vals); return update;
|
||||
case Db_cmd_mode.Tid_delete: if (delete == null) delete = conn.Stmt_delete(tbl_name, flds_keys); return delete;
|
||||
case Db_cmd_mode.Tid_ignore: return Db_stmt_.Null;
|
||||
default: throw Exc_.new_unhandled(cmd_mode);
|
||||
default: throw Err_.new_unhandled(cmd_mode);
|
||||
}
|
||||
}
|
||||
public void Batch_bgn() {conn.Txn_bgn(tbl_name);}
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
Statement cmd = New_stmt_exec(sql);
|
||||
return cmd.executeUpdate(sql);
|
||||
}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "db.engine:exec failed", "url", conn_info.Xto_api(), "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "db.engine:exec failed", "url", conn_info.Xto_api(), "sql", sql);}
|
||||
}
|
||||
private DataRdr Exec_as_rdr(String sql) {
|
||||
try {
|
||||
@@ -50,7 +50,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
ResultSet rdr = cmd.getResultSet();
|
||||
return New_rdr(rdr, sql);
|
||||
}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "db.engine:rdr failed", "url", conn_info.Xto_api(), "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "db.engine:rdr failed", "url", conn_info.Xto_api(), "sql", sql);}
|
||||
}
|
||||
public void Ddl_create_tbl(Db_meta_tbl tbl) {Exec_as_int(tbl.To_sql_create());}
|
||||
public void Ddl_create_idx(Gfo_usr_dlg usr_dlg, Db_meta_idx... ary) {
|
||||
@@ -68,7 +68,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
Gfo_usr_dlg_.I.Plog_many("", "", "column added to table: db=~{0} tbl=~{1} fld=~{2}", conn_info.Database(), tbl, fld.Name());
|
||||
}
|
||||
catch (Exception e) { // catch error if column already added to table
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "column not added to table: db=~{0} tbl=~{1} fld=~{2} err=~{3}", conn_info.Database(), tbl, fld.Name(), Err_.Message_gplx(e));
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "column not added to table: db=~{0} tbl=~{1} fld=~{2} err=~{3}", conn_info.Database(), tbl, fld.Name(), Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
public void Ddl_delete_tbl(String tbl) {Exec_as_int(Db_sqlbldr__sqlite.I.Bld_drop_tbl(tbl));}
|
||||
@@ -89,21 +89,21 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
public void Conn_term() {
|
||||
if (connection == null) return; // connection never opened; just exit
|
||||
try {connection.close();}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "Conn_term failed", "url", conn_info.Xto_raw());}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "Conn_term failed", "url", conn_info.Xto_raw());}
|
||||
connection = null;
|
||||
}
|
||||
public Object New_stmt_prep_as_obj(String sql) {
|
||||
if (connection == null) connection = Conn_new(); // auto-open connection
|
||||
try {return connection.prepareStatement(sql);}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "New_stmt_prep failed", "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "New_stmt_prep failed", "sql", sql);}
|
||||
}
|
||||
private Statement New_stmt_exec(String sql) {
|
||||
if (connection == null) connection = Conn_new(); // auto-open connection
|
||||
try {return connection.createStatement();}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "New_stmt_exec failed", "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "New_stmt_exec failed", "sql", sql);}
|
||||
}
|
||||
protected Connection Conn_make_by_url(String url, String uid, String pwd) {
|
||||
try {return DriverManager.getConnection(url, uid, pwd);}
|
||||
catch (SQLException e) {throw Exc_.new_exc(e, "db", "connection open failed", "info", Conn_info().Xto_raw());}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "connection open failed", "info", Conn_info().Xto_raw());}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ public class Db_engine__mem implements Db_engine {
|
||||
public void Txn_end() {--txn_count;}
|
||||
public void Txn_cxl() {--txn_count;}
|
||||
public void Txn_sav() {this.Txn_end(); this.Txn_bgn("");}
|
||||
public Object Exec_as_obj(Db_qry qry) {throw Exc_.new_unimplemented();}
|
||||
public Object Exec_as_obj(Db_qry qry) {throw Err_.new_unimplemented();}
|
||||
public void Conn_open() {}
|
||||
public void Conn_term() {
|
||||
if (txn_count != 0) throw Exc_.new_("Conn_term.txns still open", "txn_count", txn_count);
|
||||
if (txn_count != 0) throw Err_.new_wo_type("Conn_term.txns still open", "txn_count", txn_count);
|
||||
}
|
||||
public Db_rdr New_rdr__rls_manual(Object rdr_obj, String sql) {throw Exc_.new_unimplemented();}
|
||||
public Db_rdr New_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {throw Exc_.new_unimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {throw Exc_.new_unimplemented();}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Exc_.new_unimplemented();}
|
||||
public Db_rdr New_rdr__rls_manual(Object rdr_obj, String sql) {throw Err_.new_unimplemented();}
|
||||
public Db_rdr New_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {throw Err_.new_unimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {throw Err_.new_unimplemented();}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Err_.new_unimplemented();}
|
||||
public void Ddl_create_tbl(Db_meta_tbl meta) {
|
||||
Mem_tbl mem_tbl = new Mem_tbl(meta);
|
||||
tbl_hash.Add_if_dupe_use_nth(meta.Name(), mem_tbl);
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Db_rdr__mem implements Db_rdr {
|
||||
public byte[] Read_bry(String k) {return (byte[])row.Get_by(k);}
|
||||
public String Read_str(String k) {return (String)row.Get_by(k);}
|
||||
public byte[] Read_bry_by_str(String k) {return Bry_.new_u8_safe((String)row.Get_by(k));} // NOTE: null b/c db can have NULL
|
||||
@gplx.Virtual public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Exc_.new_unimplemented();}
|
||||
@gplx.Virtual public void Save_bry_in_parts(Io_url url, String tbl, String fld, String crt_key, Object crt_val) {throw Err_.new_unimplemented();}
|
||||
public DateAdp Read_date_by_str(String k) {return DateAdp_.parse_iso8561((String)row.Get_by(k));}
|
||||
public byte Read_byte(String k) {return Byte_.cast_(row.Get_by(k));}
|
||||
public int Read_int(String k) {return Int_.cast_(row.Get_by(k));}
|
||||
|
||||
@@ -41,49 +41,49 @@ public class Db_stmt__mem implements Db_stmt {
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
|
||||
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
|
||||
@@ -94,7 +94,7 @@ public class Db_stmt__mem implements Db_stmt {
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.ios.Io_stream_rdr v, long rdr_len) {
|
||||
@@ -102,12 +102,12 @@ public class Db_stmt__mem implements Db_stmt {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
gplx.ios.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add("", Bool_.N, bfr.Xto_str_and_clear());
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public boolean Exec_insert() {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
if (tbl == null) throw Exc_.new_("must call Create_tbl", "tbl", qry.Base_table());
|
||||
if (tbl == null) throw Err_.new_wo_type("must call Create_tbl", "tbl", qry.Base_table());
|
||||
return tbl.Insert(this) == 1;
|
||||
}
|
||||
public int Exec_update() {
|
||||
@@ -118,13 +118,13 @@ public class Db_stmt__mem implements Db_stmt {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
return tbl.Delete(this);
|
||||
}
|
||||
public DataRdr Exec_select() {throw Exc_.new_unimplemented();}
|
||||
public DataRdr Exec_select() {throw Err_.new_unimplemented();}
|
||||
public Db_rdr Exec_select__rls_auto() {return this.Exec_select__rls_manual();}
|
||||
public Db_rdr Exec_select__rls_manual() {
|
||||
Mem_tbl tbl = engine.Tbls_get(qry.Base_table());
|
||||
return tbl.Select(this);
|
||||
}
|
||||
public Object Exec_select_val() {throw Exc_.new_unimplemented();}
|
||||
public Object Exec_select_val() {throw Err_.new_unimplemented();}
|
||||
private void Add(String k, boolean where, Object v) {
|
||||
if (k == Db_meta_fld.Key_null) return; // key is explicitly null; ignore; allows schema_2+ type definitions
|
||||
val_list.Add_if_dupe_use_1st(k, v); // NOTE: only add if new; WHERE with IN will call Add many times; fld_ttl IN ('A.png', 'B.png');
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Noop_engine implements Db_engine {
|
||||
public Db_rdr New_rdr__rls_manual (Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public Db_rdr New_rdr__rls_auto (Db_stmt stmt, Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public Db_stmt New_stmt_prep(Db_qry qry) {return Db_stmt_.Null;}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Exc_.new_unimplemented();}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Err_.new_unimplemented();}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
public void Txn_bgn(String name) {}
|
||||
public void Txn_end() {}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
}
|
||||
catch (ClassNotFoundException e) {throw Exc_.new_exc(e, "db", "could not load sqlite jdbc driver");}
|
||||
catch (ClassNotFoundException e) {throw Err_.new_exc(e, "db", "could not load sqlite jdbc driver");}
|
||||
loaded = true;
|
||||
}
|
||||
Sqlite_conn_info conn_info_as_sqlite = (Sqlite_conn_info)conn_info;
|
||||
@@ -56,31 +56,31 @@ public class Sqlite_engine extends Db_engine_sql_base {
|
||||
}
|
||||
public static final Sqlite_engine _ = new Sqlite_engine();
|
||||
}
|
||||
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "k", k, "type", Byte_.Cls_val_name);}}
|
||||
class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(String k) {try {return (byte)Int_.cast_(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "k", k, "type", Byte_.Cls_val_name);}}
|
||||
@Override public boolean Read_bool_by_byte(String k) {
|
||||
try {
|
||||
int val = rdr.getInt(k);
|
||||
return val == 1;
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "i", k, "type", Bool_.Cls_val_name);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", Bool_.Cls_val_name);}
|
||||
}
|
||||
@Override public long Read_long(String k) {
|
||||
try {
|
||||
long val = rdr.getLong(k);
|
||||
Number n = (Number)val;
|
||||
return n.longValue();
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "i", k, "type", Long_.Cls_val_name);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", Long_.Cls_val_name);}
|
||||
}
|
||||
@Override public float Read_float(String k) {
|
||||
try {
|
||||
Double val = (Double)rdr.getDouble(k);
|
||||
return val == null ? Float.NaN : val.floatValue();
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed:", "i", k, "type", Float_.Cls_val_name);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed:", "i", k, "type", Float_.Cls_val_name);}
|
||||
}
|
||||
@Override public DateAdp Read_date_by_str(String k) {
|
||||
try {
|
||||
String val = rdr.getString(k);
|
||||
return val == null ? null : DateAdp_.parse_fmt(val, "yyyyMMdd_HHmmss");
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "read failed", "i", k, "type", DateAdp_.Cls_ref_type);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", DateAdp_.Cls_ref_type);}
|
||||
}
|
||||
// @Override public DecimalAdp ReadDecimalOr(String key, DecimalAdp or) {
|
||||
// Object val = Read(key);
|
||||
|
||||
@@ -39,7 +39,7 @@ class TdbDbLoadMgr {
|
||||
else if (String_.Eq(name, TdbTableList.StoreTableName)) db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
else db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
}
|
||||
if (db.Files().Count() == 0) throw Exc_.new_("fatal error: db has no files", "connectInfo", db.DbUrl());
|
||||
if (db.Files().Count() == 0) throw Err_.new_wo_type("fatal error: db has no files", "connectInfo", db.DbUrl());
|
||||
}
|
||||
DataRdr MakeDataRdr(Io_url fil) {
|
||||
String text = Io_mgr.I.LoadFilStr(fil);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TdbEngine implements Db_engine {
|
||||
return wkr.Exec(this, qry);
|
||||
}
|
||||
public Db_stmt New_stmt_prep(Db_qry qry) {return new Db_stmt_sql().Parse(qry, Sql_qry_wtr_.I.Xto_str(qry, true));}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Exc_.new_unimplemented();}
|
||||
public Object New_stmt_prep_as_obj(String sql) {throw Err_.new_unimplemented();}
|
||||
public Db_rdr New_rdr__rls_manual(Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public Db_rdr New_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {return Db_rdr_.Empty;}
|
||||
public DataRdr New_rdr(java.sql.ResultSet rdr, String sql) {return DataRdr_.Null;}
|
||||
@@ -57,9 +57,9 @@ public class TdbEngine implements Db_engine {
|
||||
public void FlushTbl(TdbTable tbl) {
|
||||
saveMgr.SaveFile(db, tbl.File());
|
||||
}
|
||||
public void Ddl_create_tbl(Db_meta_tbl meta) {throw Exc_.new_unimplemented();}
|
||||
public void Ddl_create_idx(Gfo_usr_dlg usr_dlg, Db_meta_idx... ary) {throw Exc_.new_unimplemented();}
|
||||
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {throw Exc_.new_unimplemented();}
|
||||
public void Ddl_create_tbl(Db_meta_tbl meta) {throw Err_.new_unimplemented();}
|
||||
public void Ddl_create_idx(Gfo_usr_dlg usr_dlg, Db_meta_idx... ary) {throw Err_.new_unimplemented();}
|
||||
public void Ddl_append_fld(String tbl, Db_meta_fld fld) {throw Err_.new_unimplemented();}
|
||||
public void Ddl_delete_tbl(String tbl) {}
|
||||
public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
public void Env_db_detach(String alias) {}
|
||||
@@ -77,7 +77,7 @@ public class TdbEngine implements Db_engine {
|
||||
wkrs.Add(Db_qry_.Tid_flush, TdbFlushWkr.new_());
|
||||
}
|
||||
public static TdbEngine as_(Object obj) {return obj instanceof TdbEngine ? (TdbEngine)obj : null;}
|
||||
public static TdbEngine cast_(Object obj) {try {return (TdbEngine)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, TdbEngine.class, obj);}}
|
||||
public static TdbEngine cast_(Object obj) {try {return (TdbEngine)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TdbEngine.class, obj);}}
|
||||
}
|
||||
interface Db_qryWkr {
|
||||
Object Exec(Db_engine engine, Db_qry cmd);
|
||||
|
||||
@@ -27,5 +27,5 @@ public class TdbFile {
|
||||
}
|
||||
public static final int MainFileId = 1;
|
||||
public static TdbFile as_(Object obj) {return obj instanceof TdbFile ? (TdbFile)obj : null;}
|
||||
public static TdbFile cast_(Object obj) {try {return (TdbFile)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, TdbFile.class, obj);}}
|
||||
public static TdbFile cast_(Object obj) {try {return (TdbFile)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TdbFile.class, obj);}}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ class TdbInsertWkr implements Db_qryWkr {
|
||||
Sql_select_fld_list insertFlds = insert.Cols(); int insertFldsCount = insertFlds.Count();
|
||||
GfoFldList selectFldsForNewRow = null;
|
||||
try {selectFldsForNewRow = insertFlds.XtoGfoFldLst(tbl);}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to generate flds for new row");}
|
||||
if (insertFldsCount > selectFldsForNewRow.Count()) throw Exc_.new_("insert flds cannot exceed selectFlds", "insertFlds", insertFlds.XtoStr(), "selectFlds", selectFldsForNewRow.XtoStr());
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to generate flds for new row");}
|
||||
if (insertFldsCount > selectFldsForNewRow.Count()) throw Err_.new_wo_type("insert flds cannot exceed selectFlds", "insertFlds", insertFlds.XtoStr(), "selectFlds", selectFldsForNewRow.XtoStr());
|
||||
while (rdr.MoveNextPeer()) {
|
||||
count++;
|
||||
GfoNde row = GfoNde_.vals_(selectFldsForNewRow, new Object[insertFldsCount]);
|
||||
|
||||
@@ -21,7 +21,7 @@ import gplx.lists.*; /*ComparerAble*/ import gplx.stores.*; /*GfoNdeRdr*/
|
||||
class TdbSelectWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast_(engineObj); Db_qry__select_cmd cmd = (Db_qry__select_cmd)cmdObj;
|
||||
if (cmd.From().Tbls().Count() > 1) throw Exc_.new_w_type("gplx.tdbs", "joins not supported for tdbs", "sql", cmd.Xto_sql());
|
||||
if (cmd.From().Tbls().Count() > 1) throw Err_.new_("gplx.tdbs", "joins not supported for tdbs", "sql", cmd.Xto_sql());
|
||||
|
||||
TdbTable tbl = engine.FetchTbl(cmd.From().BaseTable().TblName());
|
||||
GfoNdeList rv = (cmd.Where() == Db_qry_.WhereAll && cmd.Limit() == Db_qry__select_cmd.Limit_disabled) ? rv = tbl.Rows() : FilterRecords(tbl, cmd.Where(), cmd.Limit());
|
||||
|
||||
@@ -50,16 +50,16 @@ public class TdbTable {
|
||||
layout = TdbStores.FetchLayout(rdr);
|
||||
GfoNdeRdr ndeRdr = GfoNdeRdr_.as_(rdr );
|
||||
if (ndeRdr != null) {
|
||||
if (ndeRdr.UnderNde() == null) throw Exc_.new_("ndeRdr.UnderNde is null", "name", rdr.NameOfNode());
|
||||
if (ndeRdr.UnderNde() == null) throw Err_.new_wo_type("ndeRdr.UnderNde is null", "name", rdr.NameOfNode());
|
||||
rows = ndeRdr.UnderNde().Subs();
|
||||
flds = ndeRdr.UnderNde().SubFlds();
|
||||
}
|
||||
else { // XmlRdr needs to load each row again...
|
||||
throw Exc_.new_invalid_op("TableLoad not implemented").Args_add("rdrType", ClassAdp_.NameOf_obj(rdr), "rdrName", rdr.NameOfNode());
|
||||
throw Err_.new_invalid_op("TableLoad not implemented").Args_add("rdrType", ClassAdp_.NameOf_obj(rdr), "rdrName", rdr.NameOfNode());
|
||||
}
|
||||
isLoaded = true;
|
||||
}
|
||||
DsvStoreLayout layout;
|
||||
public static TdbTable as_(Object obj) {return obj instanceof TdbTable ? (TdbTable)obj : null;}
|
||||
public static TdbTable cast_(Object obj) {try {return (TdbTable)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, TdbTable.class, obj);}}
|
||||
public static TdbTable cast_(Object obj) {try {return (TdbTable)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TdbTable.class, obj);}}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.lists.*; /*Ordered_hash_base*/ import gplx.stores.dsvs.*; /*DsvStore
|
||||
public class TdbTableList extends Ordered_hash_base {
|
||||
public TdbTable Get_by(String name) {return TdbTable.as_(Fetch_base(name));}
|
||||
public TdbTable Get_by_or_fail(String name) {
|
||||
TdbTable rv = TdbTable.as_(Get_by(name)); if (rv == null) throw Exc_.new_("could not find table; database file may not exist", "table", name);
|
||||
TdbTable rv = TdbTable.as_(Get_by(name)); if (rv == null) throw Err_.new_wo_type("could not find table; database file may not exist", "table", name);
|
||||
return rv;
|
||||
}
|
||||
public void Add(TdbTable dataTable) {Add_base(dataTable.Name(), dataTable);}
|
||||
|
||||
@@ -97,7 +97,7 @@ class Meta_fld_wkr__default extends Meta_fld_wkr__base {
|
||||
case Byte_ascii.Quote:
|
||||
case Byte_ascii.Apos:
|
||||
int bgn_pos = rdr.Pos() + 1;
|
||||
int end_pos = Bry_finder.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_finder.Not_found) throw Exc_.new_("unclosed quote", "snip", rdr.Mid_by_len_safe(40));
|
||||
int end_pos = Bry_finder.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_finder.Not_found) throw Err_.new_wo_type("unclosed quote", "snip", rdr.Mid_by_len_safe(40));
|
||||
default_val = Bry_.Mid(src, bgn_pos, end_pos);
|
||||
rdr.Pos_(end_pos + 1);
|
||||
break;
|
||||
@@ -107,7 +107,7 @@ class Meta_fld_wkr__default extends Meta_fld_wkr__base {
|
||||
default_val = rdr.Read_int_to_non_num();
|
||||
break;
|
||||
default:
|
||||
throw Exc_.new_("invalid field_default", "snip", rdr.Mid_by_len_safe(40));
|
||||
throw Err_.new_wo_type("invalid field_default", "snip", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
fld.Default_val_(default_val);
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ public class Meta_parser__fld {
|
||||
public Meta_type_itm Parse_type(Bry_rdr rdr) {
|
||||
rdr.Skip_ws();
|
||||
Object type_obj = type_trie.Match_bgn(rdr.Src(), rdr.Pos(), rdr.Src_len());
|
||||
if (type_obj == null) throw Exc_.new_("invalid fld type", "snip", rdr.Mid_by_len_safe(40));
|
||||
if (type_obj == null) throw Err_.new_wo_type("invalid fld type", "snip", rdr.Mid_by_len_safe(40));
|
||||
Meta_parser__fld_itm type_itm = (Meta_parser__fld_itm)type_obj;
|
||||
rdr.Pos_add(type_itm.Word().length);
|
||||
int paren_itms_count = type_itm.Paren_itms_count();
|
||||
int len_1 = Int_.MinValue, len_2 = Int_.MinValue;
|
||||
if (paren_itms_count > 0) {
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Paren_bgn);
|
||||
len_1 = rdr.Skip_ws().Read_int_to_non_num(); if (len_1 == Int_.MinValue) throw Exc_.new_("invalid fld len_1", "snip", rdr.Mid_by_len_safe(40));
|
||||
len_1 = rdr.Skip_ws().Read_int_to_non_num(); if (len_1 == Int_.MinValue) throw Err_.new_wo_type("invalid fld len_1", "snip", rdr.Mid_by_len_safe(40));
|
||||
if (paren_itms_count == 2) {
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Comma);
|
||||
len_2 = rdr.Skip_ws().Read_int_to_non_num(); if (len_2 == Int_.MinValue) throw Exc_.new_("invalid fld len_2", "snip", rdr.Mid_by_len_safe(40));
|
||||
len_2 = rdr.Skip_ws().Read_int_to_non_num(); if (len_2 == Int_.MinValue) throw Err_.new_wo_type("invalid fld len_2", "snip", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
rdr.Skip_ws().Chk_byte_or_fail(Byte_ascii.Paren_end);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class Meta_parser__fld {
|
||||
case Byte_ascii.Comma: return fld;
|
||||
case Byte_ascii.Paren_end: return fld;
|
||||
}
|
||||
Object type_obj = fld_trie.Match_bgn(src, rdr.Pos(), src_len); if (type_obj == null) throw Exc_.new_("invalid", "snip", rdr.Mid_by_len_safe(40));
|
||||
Object type_obj = fld_trie.Match_bgn(src, rdr.Pos(), src_len); if (type_obj == null) throw Err_.new_wo_type("invalid", "snip", rdr.Mid_by_len_safe(40));
|
||||
Meta_fld_wkr__base type_wkr = (Meta_fld_wkr__base)type_obj;
|
||||
switch (type_wkr.Tid()) {
|
||||
case Meta_fld_wkr__base.Tid_end_comma:
|
||||
|
||||
@@ -39,14 +39,14 @@ public class Meta_parser__tbl {
|
||||
private void Parse_flds() {
|
||||
byte[] src = rdr.Src();
|
||||
while (true) {
|
||||
Meta_fld_itm fld = fld_parser.Parse_fld(rdr); if (fld == null) throw Exc_.new_("unknown field", "src", rdr.Src());
|
||||
Meta_fld_itm fld = fld_parser.Parse_fld(rdr); if (fld == null) throw Err_.new_wo_type("unknown field", "src", rdr.Src());
|
||||
tbl.Flds().Add(fld);
|
||||
int pos = rdr.Pos();
|
||||
byte b = pos == rdr.Src_len() ? Byte_ascii.Nil : src[pos];
|
||||
byte b = pos == rdr.Src_len() ? Byte_ascii.Null : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Comma: rdr.Pos_add_one(); break;
|
||||
case Byte_ascii.Paren_end: rdr.Pos_add_one(); return;
|
||||
default: throw Exc_.new_("premature end of flds", "src", rdr.Mid_by_len_safe(40));
|
||||
default: throw Err_.new_wo_type("premature end of flds", "src", rdr.Mid_by_len_safe(40));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier()
|
||||
return Bry_.Mid(src, bgn, end);
|
||||
}
|
||||
@Override public Bry_rdr Skip_ws() {
|
||||
byte b_0 = pos < src_len ? src[pos] : Byte_ascii.Nil;
|
||||
byte bgn_1 = Byte_ascii.Nil;
|
||||
byte b_0 = pos < src_len ? src[pos] : Byte_ascii.Null;
|
||||
byte bgn_1 = Byte_ascii.Null;
|
||||
byte[] end_bry = null;
|
||||
switch (b_0) {
|
||||
case Byte_ascii.Dash: bgn_1 = Byte_ascii.Dash; end_bry = Comm_end_line; break;
|
||||
@@ -46,7 +46,7 @@ public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier()
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
byte b_1 = pos + 1 < src_len ? src[pos + 1] : Byte_ascii.Nil;
|
||||
byte b_1 = pos + 1 < src_len ? src[pos + 1] : Byte_ascii.Null;
|
||||
if (b_1 != bgn_1) return this;
|
||||
int end_pos = Bry_finder.Find_fwd(src, end_bry, pos + 2, src_len);
|
||||
if (end_pos == Bry_finder.Not_found) return this;
|
||||
|
||||
@@ -51,12 +51,12 @@ public class Db_qry__select_cmd implements Db_qry {
|
||||
public Sql_from From() {return from;} Sql_from from;
|
||||
public Db_qry__select_cmd From_(String tblName) {return From_(tblName, null);}
|
||||
public Db_qry__select_cmd From_(String tblName, String alias) {
|
||||
if (from != null) throw Exc_.new_("super table already defined", "from", from.Tbls().Count());
|
||||
if (from != null) throw Err_.new_wo_type("super table already defined", "from", from.Tbls().Count());
|
||||
from = Sql_from.new_(Sql_tbl_src.new_().JoinType_(Sql_join_itmType.From).TblName_(tblName).Alias_(alias));
|
||||
return this;
|
||||
}
|
||||
public Db_qry__select_cmd Join_(String name, String alias, Sql_join_itm... ary) {
|
||||
if (from == null) throw Exc_.new_("super table is not defined");
|
||||
if (from == null) throw Err_.new_wo_type("super table is not defined");
|
||||
Sql_tbl_src tbl = Sql_tbl_src.new_().JoinType_(Sql_join_itmType.Inner).TblName_(name).Alias_(alias);
|
||||
for (Sql_join_itm itm : ary)
|
||||
tbl.JoinLinks().Add(itm);
|
||||
@@ -118,7 +118,7 @@ public class Db_qry__select_cmd implements Db_qry {
|
||||
}
|
||||
public Sql_group_by GroupBy() {return groupBy;} Sql_group_by groupBy = null;
|
||||
public Db_qry__select_cmd GroupBy_(String... flds) {
|
||||
if (groupBy != null) throw Exc_.new_("group by already defined", "group", groupBy);
|
||||
if (groupBy != null) throw Err_.new_wo_type("group by already defined", "group", groupBy);
|
||||
groupBy = Sql_group_by.new_(flds);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Db_qry_flush implements Db_qry {
|
||||
|
||||
|
||||
public static Db_qry_flush as_(Object obj) {return obj instanceof Db_qry_flush ? (Db_qry_flush)obj : null;}
|
||||
public static Db_qry_flush cast_(Object obj) {try {return (Db_qry_flush)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, Db_qry_flush.class, obj);}}
|
||||
public static Db_qry_flush cast_(Object obj) {try {return (Db_qry_flush)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Db_qry_flush.class, obj);}}
|
||||
public static Db_qry_flush new_(String... ary) {
|
||||
Db_qry_flush rv = new Db_qry_flush();
|
||||
rv.tableNames = ary;
|
||||
|
||||
@@ -20,7 +20,7 @@ import gplx.dbs.sqls.*;
|
||||
public class Db_qry_sql implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_sql;}
|
||||
public boolean Exec_is_rdr() {return isReader;} private boolean isReader;
|
||||
public String Base_table() {throw Exc_.new_unimplemented();}
|
||||
public String Base_table() {throw Err_.new_unimplemented();}
|
||||
public String Xto_sql() {return sql;} private String sql;
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public static Db_qry_sql dml_(String sql) {return sql_(sql);}
|
||||
@@ -37,7 +37,7 @@ public class Db_qry_sql implements Db_qry {
|
||||
return rv;
|
||||
}
|
||||
public static Db_qry_sql as_(Object obj) {return obj instanceof Db_qry_sql ? (Db_qry_sql)obj : null;}
|
||||
public static Db_qry_sql cast_(Object obj) {try {return (Db_qry_sql)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, Db_qry_sql.class, obj);}}
|
||||
public static Db_qry_sql cast_(Object obj) {try {return (Db_qry_sql)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, Db_qry_sql.class, obj);}}
|
||||
public static String Gen_sql(Db_qry qry, Object... args) {
|
||||
byte[] src = Bry_.new_u8(Sql_qry_wtr_.Gen_placeholder_parameters(qry));
|
||||
int src_len = src.length;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setByte(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v, "sql", sql);}
|
||||
try {stmt.setByte(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
|
||||
@@ -50,7 +50,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setInt(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "int", "val", v, "sql", sql);}
|
||||
try {stmt.setInt(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
|
||||
@@ -58,7 +58,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setLong(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "long", "val", v, "sql", sql);}
|
||||
try {stmt.setLong(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
|
||||
@@ -66,7 +66,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setFloat(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "float", "val", v, "sql", sql);}
|
||||
try {stmt.setFloat(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
|
||||
@@ -74,7 +74,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setDouble(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);}
|
||||
try {stmt.setDouble(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
|
||||
@@ -82,7 +82,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
|
||||
try {stmt.setBigDecimal(++val_idx, v.Xto_decimal());} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
|
||||
@@ -90,7 +90,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setBytes(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte[]", v.length, sql);}
|
||||
try {stmt.setBytes(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", v.length, sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
|
||||
@@ -102,11 +102,11 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
if (k == Db_meta_fld.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Exc_.new_exc(e, "db", "failed to add value", "type", "String", "val", v, "sql", sql);}
|
||||
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v, "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.ios.Io_stream_rdr v, long rdr_len) {
|
||||
try {stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
try {stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public boolean Exec_insert() {
|
||||
@@ -114,7 +114,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
catch (Exception e) {
|
||||
this.Rls();
|
||||
Reset_stmt();
|
||||
throw Exc_.new_exc(e, "db_stmt", "insert failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
|
||||
throw Err_.new_exc(e, "db_stmt", "insert failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
|
||||
}
|
||||
}
|
||||
public int Exec_update() {
|
||||
@@ -122,7 +122,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
catch (Exception e) {
|
||||
this.Rls();
|
||||
Reset_stmt();
|
||||
throw Exc_.new_exc(e, "db_stmt", "update failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
|
||||
throw Err_.new_exc(e, "db_stmt", "update failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
|
||||
}
|
||||
}
|
||||
public int Exec_delete() {
|
||||
@@ -130,25 +130,25 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
catch (Exception e) {
|
||||
this.Rls();
|
||||
Reset_stmt();
|
||||
throw Exc_.new_exc(e, "db_stmt", "delete failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
|
||||
throw Err_.new_exc(e, "db_stmt", "delete failed", "url", engine.Conn_info().Xto_api(), "sql", sql);
|
||||
}
|
||||
}
|
||||
public DataRdr Exec_select() {
|
||||
try {DataRdr rv = engine.New_rdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
|
||||
try {DataRdr rv = engine.New_rdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
|
||||
}
|
||||
public Db_rdr Exec_select__rls_auto() {
|
||||
try {return engine.New_rdr__rls_auto(this, stmt.executeQuery(), sql);} catch (Exception e) {throw Exc_.new_exc(e, "db", "select failed", "sql", sql);}
|
||||
try {return engine.New_rdr__rls_auto(this, stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.new_exc(e, "db", "select failed", "sql", sql);}
|
||||
}
|
||||
public Db_rdr Exec_select__rls_manual() {
|
||||
try {return engine.New_rdr__rls_manual(stmt.executeQuery(), sql);} catch (Exception e) {throw Exc_.new_exc(e, "db", "select failed", "sql", sql);}
|
||||
try {return engine.New_rdr__rls_manual(stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.new_exc(e, "db", "select failed", "sql", sql);}
|
||||
}
|
||||
public Object Exec_select_val() {
|
||||
try {Object rv = Db_qry__select_cmd.Rdr_to_val(engine.New_rdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
|
||||
try {Object rv = Db_qry__select_cmd.Rdr_to_val(engine.New_rdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
|
||||
}
|
||||
public Db_stmt Clear() {
|
||||
val_idx = 0;
|
||||
try {stmt.clearBatch();}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to clear parameters", "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to clear parameters", "sql", sql);}
|
||||
return this;
|
||||
}
|
||||
public void Rls() {
|
||||
@@ -158,6 +158,6 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
stmt.close();
|
||||
stmt = null;
|
||||
}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to close command", "sql", sql);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to close command", "sql", sql);}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,49 +33,49 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
try {Add(k, Byte_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
try {Add(k, Byte_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
try {Add(k, Int_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
try {Add(k, Int_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
try {Add(k, Long_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
try {Add(k, Long_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
try {Add(k, Float_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
try {Add(k, Float_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
try {Add(k, Double_.Xto_str(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
try {Add(k, Double_.Xto_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, DecimalAdp v) {return Add_decimal(Bool_.N, k, v);}
|
||||
public Db_stmt Val_decimal(DecimalAdp v) {return Add_decimal(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, DecimalAdp v) {
|
||||
try {Add(k, v.Xto_str());} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
try {Add(k, v.Xto_str());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {// HACK: convert to String b/c tdb does not support byte[]
|
||||
try {Add(k, Val_str_wrap(String_.new_u8(v)));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
try {Add(k, Val_str_wrap(String_.new_u8(v)));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
|
||||
@@ -86,7 +86,7 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
return this;
|
||||
}
|
||||
public Db_stmt Val_rdr_(gplx.ios.Io_stream_rdr v, long rdr_len) {
|
||||
@@ -94,28 +94,28 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
gplx.ios.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add(Key_na, bfr.Xto_str_and_clear());
|
||||
} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
private String Val_str_wrap(String v) {
|
||||
return "'" + String_.Replace(v, "'", "\\'") + "'";
|
||||
}
|
||||
public boolean Exec_insert() {
|
||||
try {boolean rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())) != 0; return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
try {boolean rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())) != 0; return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
}
|
||||
public int Exec_update() {
|
||||
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
}
|
||||
public int Exec_delete() {
|
||||
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
try {int rv = conn.Exec_qry(Db_qry_sql.dml_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
}
|
||||
public DataRdr Exec_select() {
|
||||
try {DataRdr rv = conn.Exec_qry_as_rdr(Db_qry_sql.rdr_(this.Xto_sql())); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
try {DataRdr rv = conn.Exec_qry_as_rdr(Db_qry_sql.rdr_(this.Xto_sql())); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
}
|
||||
public Db_rdr Exec_select__rls_auto() {return Db_rdr_.Empty;}
|
||||
public Db_rdr Exec_select__rls_manual() {return Db_rdr_.Empty;}
|
||||
public Object Exec_select_val() {
|
||||
try {Object rv = Db_qry__select_cmd.Rdr_to_val(this.Exec_select()); return rv;} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
try {Object rv = Db_qry__select_cmd.Rdr_to_val(this.Exec_select()); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql_orig);}
|
||||
}
|
||||
public Db_stmt Clear() {
|
||||
args.Clear();
|
||||
|
||||
@@ -21,8 +21,8 @@ public class Db_obj_ary_crt implements gplx.core.criterias.Criteria {
|
||||
public byte Tid() {return Criteria_.Tid_db_obj_ary;}
|
||||
public Db_fld[] Flds() {return flds;} public Db_obj_ary_crt Flds_(Db_fld[] v) {this.flds = v; return this;} private Db_fld[] flds;
|
||||
public Object[][] Vals() {return vals;} public void Vals_(Object[][] v) {this.vals = v;} private Object[][] vals;
|
||||
public void Val_from_args(Hash_adp args) {throw Exc_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {throw Exc_.new_unimplemented();}
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public boolean Matches(Object obj) {return false;}
|
||||
public String XtoStr() {return "";}
|
||||
public static Db_obj_ary_crt new_(Db_fld... flds) {return new Db_obj_ary_crt().Flds_(flds);}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Db_sqlbldr__sqlite implements Db_sqlbldr {
|
||||
case Db_meta_fld.Tid_str: tmp_bfr.Add_str_a7("varchar(").Add_int_variable(len).Add_byte(Byte_ascii.Paren_end); break;
|
||||
case Db_meta_fld.Tid_text: tmp_bfr.Add_str_a7("text"); break;
|
||||
case Db_meta_fld.Tid_bry: tmp_bfr.Add_str_a7("blob"); break;
|
||||
default: throw Exc_.new_unhandled(tid);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static final Db_sqlbldr__sqlite I = new Db_sqlbldr__sqlite(); Db_sqlbldr__sqlite() {}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
|
||||
case Db_qry_.Tid_select_in_tbl:
|
||||
case Db_qry_.Tid_select: return Bld_qry_select((Db_qry__select_cmd)cmd);
|
||||
case Db_qry_.Tid_sql: return ((Db_qry_sql)cmd).Xto_sql();
|
||||
default: throw Exc_.new_unhandled(cmd.Tid());
|
||||
default: throw Err_.new_unhandled(cmd.Tid());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
|
||||
sb.Add(Bld_qry_select(cmd.Select()));
|
||||
return sb.Xto_str_and_clear();
|
||||
}
|
||||
int arg_count = cmd.Args().Count(); if (arg_count == 0) throw Exc_.new_("Db_qry_insert has no columns", "base_table", cmd.Base_table());
|
||||
int arg_count = cmd.Args().Count(); if (arg_count == 0) throw Err_.new_wo_type("Db_qry_insert has no columns", "base_table", cmd.Base_table());
|
||||
int last = arg_count - 1;
|
||||
sb.Add_many("INSERT INTO ", cmd.Base_table(), " (");
|
||||
for (int i = 0; i < arg_count; i++) {
|
||||
@@ -69,7 +69,7 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
|
||||
return sb.Xto_str_and_clear();
|
||||
}
|
||||
private String Bld_qry_update(Db_qry_update cmd) {
|
||||
int arg_count = cmd.Args().Count(); if (arg_count == 0) throw Exc_.new_("Db_qry_update has no columns", "base_table", cmd.Base_table());
|
||||
int arg_count = cmd.Args().Count(); if (arg_count == 0) throw Err_.new_wo_type("Db_qry_update has no columns", "base_table", cmd.Base_table());
|
||||
sb.Add_many("UPDATE ", cmd.Base_table(), " SET ");
|
||||
for (int i = 0; i < arg_count; i++) {
|
||||
KeyVal pair = cmd.Args().Get_at(i);
|
||||
@@ -140,7 +140,7 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
|
||||
sb.Add(" INDEXED BY ").Add(idx_name);
|
||||
}
|
||||
private void Xto_sql_col(String_bldr sb, Object obj) {
|
||||
if (obj == null) throw Exc_.new_null("ColName");
|
||||
if (obj == null) throw Err_.new_null();
|
||||
sb.Add_obj(obj); // FIXME: options for bracketing; ex: [name]
|
||||
}
|
||||
public void Bld_val(String_bldr sb, Db_arg arg) {
|
||||
@@ -211,7 +211,7 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
|
||||
Append_db_obj_ary(sb, (Db_obj_ary_crt)crt);
|
||||
}
|
||||
else {
|
||||
Criteria_fld leaf = Criteria_fld.as_(crt); if (leaf == null) throw Exc_.new_invalid_op(crt.XtoStr());
|
||||
Criteria_fld leaf = Criteria_fld.as_(crt); if (leaf == null) throw Err_.new_invalid_op(crt.XtoStr());
|
||||
sb.Add(leaf.Key());
|
||||
Bld_where_crt(sb, leaf.Crt());
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public class Sql_qry_wtr_ansi implements Sql_qry_wtr {
|
||||
case Criteria_.Tid_in: Bld_where_in(sb, Criteria_in.as_(crt)); break;
|
||||
case Criteria_.Tid_like: Bld_where_like(sb, Criteria_like.as_(crt)); break;
|
||||
case Criteria_.Tid_iomatch: Bld_where_iomatch(sb, Criteria_ioMatch.as_(crt)); break;
|
||||
default: throw Exc_.new_unhandled(crt);
|
||||
default: throw Err_.new_unhandled(crt);
|
||||
}
|
||||
}
|
||||
private void Bld_where_eq(String_bldr sb, Criteria_eq crt) {
|
||||
|
||||
@@ -31,8 +31,8 @@ public abstract class Sql_select_fld_base {
|
||||
}
|
||||
}
|
||||
class Sql_select_fld_wild extends Sql_select_fld_base {
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {throw Exc_.new_("group by eval not allowed on *");}
|
||||
@Override public void GroupBy_type(GfoFld fld) {throw Exc_.new_("group by type not allowed on *");}
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {throw Err_.new_wo_type("group by eval not allowed on *");}
|
||||
@Override public void GroupBy_type(GfoFld fld) {throw Err_.new_wo_type("group by type not allowed on *");}
|
||||
@Override public String XtoSql() {return "*";}
|
||||
public static final Sql_select_fld_wild _ = new Sql_select_fld_wild(); Sql_select_fld_wild() {this.ctor_(Tbl_null, "*", "*");}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class Sql_select_fld_list {
|
||||
for (int i = 0; i < this.Count(); i++) {
|
||||
Sql_select_fld_base selectFld = this.Get_at(i);
|
||||
GfoFld fld = tbl.Flds().FetchOrNull(selectFld.Fld());
|
||||
if (fld == null) throw Exc_.new_("fld not found in tbl", "fldName", selectFld.Fld(), "tblName", tbl.Name(), "tblFlds", tbl.Flds().XtoStr());
|
||||
if (rv.Has(selectFld.Alias())) throw Exc_.new_("alias is not unique", "fldName", selectFld.Fld(), "flds", rv.XtoStr());
|
||||
if (fld == null) throw Err_.new_wo_type("fld not found in tbl", "fldName", selectFld.Fld(), "tblName", tbl.Name(), "tblFlds", tbl.Flds().XtoStr());
|
||||
if (rv.Has(selectFld.Alias())) throw Err_.new_wo_type("alias is not unique", "fldName", selectFld.Fld(), "flds", rv.XtoStr());
|
||||
selectFld.GroupBy_type(fld);
|
||||
rv.Add(selectFld.Alias(), selectFld.ValType());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class PoolIds {
|
||||
if (rv == 0) {
|
||||
rv = conn.Exec_qry(Db_qry_.insert_(Tbl_Name).Arg_(Fld_id_path, url).Arg_(Fld_id_next_id, val));
|
||||
}
|
||||
if (rv != 1) throw Exc_.new_("failed to update nextId", "url", url, "nextId", val);
|
||||
if (rv != 1) throw Err_.new_wo_type("failed to update nextId", "url", url, "nextId", val);
|
||||
}
|
||||
public static final String Tbl_Name = "pool_ids";
|
||||
@gplx.Internal protected static final String Fld_id_path = "id_path";
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DbMaprItm {
|
||||
DbMaprItm itm = (DbMaprItm)itmObj;
|
||||
if (String_.Eq(find, itm.key)) return itm;
|
||||
}
|
||||
throw Err_arg.notFound_key_("find", find);
|
||||
throw Err_.new_missing_key(find);
|
||||
}
|
||||
public DbMaprArg Flds_get(String key) {return (DbMaprArg)flds.Get_by(key);}
|
||||
SrlObj proto; String key; List_adp subs = List_adp_.new_();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
mgr = (DbMaprMgr)this.EnvVars().Get_by_or_fail(DbMaprWtr.Key_Mgr);
|
||||
DbMaprItm rootMapr = mgr.Root();
|
||||
|
||||
GfoNde tbl = GetTbl(rootMapr, rootCrt); int subsCount = tbl.Subs().Count(); if (subsCount == 0) return null; if (subsCount > 1) throw Exc_.new_("criteria returned > 1 row", "criteria", rootCrt.XtoStr(), "subsCount", subsCount);
|
||||
GfoNde tbl = GetTbl(rootMapr, rootCrt); int subsCount = tbl.Subs().Count(); if (subsCount == 0) return null; if (subsCount > 1) throw Err_.new_wo_type("criteria returned > 1 row", "criteria", rootCrt.XtoStr(), "subsCount", subsCount);
|
||||
SrlObj root = subProto.SrlObj_New(null);
|
||||
mgr.EnvStack_add(rootMapr, root); RowStack_add(tbl, 0);
|
||||
root.SrlObj_Srl(this);
|
||||
@@ -94,22 +94,22 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
return rv;
|
||||
}
|
||||
void RowStack_add(GfoNde tbl, int i) {
|
||||
GfoNdeList ndeList = tbl.Subs(); if (i >= ndeList.Count()) throw Err_arg.outOfBounds_("rowIdx", i, ndeList.Count());
|
||||
GfoNdeList ndeList = tbl.Subs(); if (i >= ndeList.Count()) throw Err_.new_missing_idx(i, ndeList.Count());
|
||||
rowStack.Add(tbl.Subs().FetchAt_asGfoNde(i));
|
||||
}
|
||||
@Override public Object Read(String key) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().Get_at_last();
|
||||
GfoNde row = (GfoNde)rowStack.Get_at_last();
|
||||
DbMaprArg arg = mapr.Flds_get(key);
|
||||
Object dbVal = null; try {dbVal = row.Read(arg.DbFld());} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to read dbVal from row", "key", key, "fld", arg.DbFld());}
|
||||
Object dbVal = null; try {dbVal = row.Read(arg.DbFld());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to read dbVal from row", "key", key, "fld", arg.DbFld());}
|
||||
return dbVal;
|
||||
}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String name) {throw Exc_.new_unimplemented();}
|
||||
@Override public DataRdr Subs() {throw Exc_.new_unimplemented();}
|
||||
@Override public int FieldCount() {throw Exc_.new_unimplemented();}
|
||||
@Override public String KeyAt(int i) {throw Exc_.new_unimplemented();}
|
||||
@Override public Object ReadAt(int i) {throw Exc_.new_unimplemented();}
|
||||
@Override public KeyVal KeyValAt(int i) {throw Exc_.new_unimplemented();}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String name) {throw Err_.new_unimplemented();}
|
||||
@Override public DataRdr Subs() {throw Err_.new_unimplemented();}
|
||||
@Override public int FieldCount() {throw Err_.new_unimplemented();}
|
||||
@Override public String KeyAt(int i) {throw Err_.new_unimplemented();}
|
||||
@Override public Object ReadAt(int i) {throw Err_.new_unimplemented();}
|
||||
@Override public KeyVal KeyValAt(int i) {throw Err_.new_unimplemented();}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new DbMaprRdr();}
|
||||
Hash_adp tables = Hash_adp_.new_();
|
||||
Db_conn conn; Criteria rootCrt;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
}
|
||||
@Override public void WriteData(String name, Object val) {
|
||||
DbMaprItm ownerMapr = (DbMaprItm)mgr.MaprStack().Get_at_last();
|
||||
String fld = ""; try {fld = ownerMapr.Flds_get(name).DbFld();} catch (Exception e) {throw Exc_.new_exc(e, "db", "failed to fetch fld from mapr", "key", name);}
|
||||
String fld = ""; try {fld = ownerMapr.Flds_get(name).DbFld();} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to fetch fld from mapr", "key", name);}
|
||||
WriteDataVal(fld, val);
|
||||
}
|
||||
void WriteDataVal(String fld, Object val) {
|
||||
|
||||
@@ -30,17 +30,17 @@ public class Db_data_rdr extends DataRdr_base implements DataRdr {
|
||||
@Override public String KeyAt(int i) {
|
||||
String rv = null;
|
||||
try {rv = rdr.getMetaData().getColumnLabel(i + List_adp_.Base1);}
|
||||
catch (SQLException e) {throw Exc_.new_exc(e, "db", "get columnName failed", "i", i, "commandText", commandText);}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "get columnName failed", "i", i, "commandText", commandText);}
|
||||
return rv;
|
||||
}
|
||||
@Override public Object ReadAt(int i) {
|
||||
Object rv;
|
||||
try {rv = rdr.getObject(i + List_adp_.Base1);} catch(Exception exc) {throw Exc_.new_("could not read val from dataReader; idx not found or rdr not open", "idx", i, "sql", commandText);}
|
||||
try {rv = rdr.getObject(i + List_adp_.Base1);} catch(Exception exc) {throw Err_.new_wo_type("could not read val from dataReader; idx not found or rdr not open", "idx", i, "sql", commandText);}
|
||||
return rv;
|
||||
}
|
||||
@Override public Object Read(String key) {
|
||||
Object rv;
|
||||
try {rv = rdr.getObject(key);} catch(Exception exc) {throw Exc_.new_("could not read val from dataReader; key not found or rdr may not be open", "key", key, "sql", commandText);}
|
||||
try {rv = rdr.getObject(key);} catch(Exception exc) {throw Err_.new_wo_type("could not read val from dataReader; key not found or rdr may not be open", "key", key, "sql", commandText);}
|
||||
return rv;
|
||||
}
|
||||
@Override public DateAdp ReadDate(String key) {
|
||||
@@ -61,20 +61,20 @@ public class Db_data_rdr extends DataRdr_base implements DataRdr {
|
||||
|
||||
public boolean MoveNextPeer() {
|
||||
try {return rdr.next();}
|
||||
catch (Exception e) {throw Exc_.new_exc(e, "db", "could not move next; check column casting error in SQL", "sql", commandText);}
|
||||
catch (Exception e) {throw Err_.new_exc(e, "db", "could not move next; check column casting error in SQL", "sql", commandText);}
|
||||
}
|
||||
@Override public DataRdr Subs() {throw Exc_.new_unimplemented();}
|
||||
public DataRdr Subs_byName(String fld) {throw Exc_.new_unimplemented();}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String fld) {throw Exc_.new_unimplemented();}
|
||||
@Override public DataRdr Subs() {throw Err_.new_unimplemented();}
|
||||
public DataRdr Subs_byName(String fld) {throw Err_.new_unimplemented();}
|
||||
@Override public DataRdr Subs_byName_moveFirst(String fld) {throw Err_.new_unimplemented();}
|
||||
public void Rls() {
|
||||
try {rdr.close();}
|
||||
catch (SQLException e) {throw Exc_.new_exc(e, "db", "reader dispose failed", "commandText", commandText);}
|
||||
catch (SQLException e) {throw Err_.new_exc(e, "db", "reader dispose failed", "commandText", commandText);}
|
||||
this.EnvVars().Clear();
|
||||
}
|
||||
@gplx.Internal protected Db_data_rdr ctor_db_data_rdr(ResultSet rdr, String commandText) {
|
||||
this.rdr = rdr; this.commandText = commandText; this.Parse_set(false);
|
||||
try {fieldCount = this.rdr.getMetaData().getColumnCount();}
|
||||
catch (SQLException e) {Exc_.new_exc(e, "xo", "get columnCount failed", "commandText", commandText);}
|
||||
catch (SQLException e) {Err_.new_exc(e, "xo", "get columnCount failed", "commandText", commandText);}
|
||||
return this;
|
||||
}
|
||||
@Override public SrlMgr SrlMgr_new(Object o) {return new Db_data_rdr();}
|
||||
|
||||
Reference in New Issue
Block a user