public string ClearTable(string back_name, int table_num) { string sql = "select table_name from information_schema.tables where table_schema='" + back_name + "'"; KingbaseESCommand cmd = new KingbaseESCommand(sql, conn); KingbaseESDataReader dr = null; dr = cmd.ExecuteReader(); var tables = new List <string>(); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { tables.Add((string)dr.GetValue(i)); } } dr.Close(); back_name = '"' + back_name + '"'; string table_name = $"{back_name}.{tables[table_num]}"; sql = $"delete from {table_name}"; string except = ""; try{ cmd.ExecuteNonQuery(); } catch (System.Exception e) { except = e.Message; } return(except); }
public List <string> GetSchemaInfo(string back_name) { string sql = "select table_name from information_schema.tables where table_schema='" + back_name + "'"; KingbaseESCommand cmd = new KingbaseESCommand(sql, conn); KingbaseESDataReader dr = null; dr = cmd.ExecuteReader(); var tables = new List <string>(); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { tables.Add((string)dr.GetValue(i)); } } dr.Close(); return(tables); }
//public void TestDQL(question ques, string ans); public Tuple <string, object> InsertData(string path, char deli, string back_name, int table_num, string filename) { string sql = "select table_name from information_schema.tables where table_schema='" + back_name + "'"; KingbaseESCommand cmd = new KingbaseESCommand(sql, conn); KingbaseESDataReader dr = null; dr = cmd.ExecuteReader(); var tables = new List <string>(); while (dr.Read()) { for (int i = 0; i < dr.FieldCount; i++) { tables.Add((string)dr.GetValue(i)); } } dr.Close(); string table_name = $"{back_name}.{tables[table_num]}"; path = $"'{path.Replace(@"\","/")}'"; string[] lines = { $"DELIMITER='{deli}'", "TYPE=csv", $"DATAFILE={path}", $"TABLE={table_name}", "ROLLBACK=True" }; var fname = filename.Split('.')[0]; var ctrl_path = HttpContext.Current.Server.MapPath($"/KingbaseCtrl/{fname + ".ctrl"}"); System.IO.File.WriteAllLines(ctrl_path, lines); sql = $"select bulkload('{ctrl_path}')"; cmd.CommandText = sql; string except = ""; object result = new object(); try { result = cmd.ExecuteScalar(); } catch (System.Exception e) { except = e.Message; } return(new Tuple <string, object>(except, result)); }