public JSResults Select(string queryString) { JSResults result = new JSResults(); MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(queryString, conn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { JSResult item = new JSResult(); Console.WriteLine(reader.VisibleFieldCount); for (int i = 0; i < reader.FieldCount; i++) { try { if (item.ContainsKey(reader.GetName(i))) { continue; } switch (reader.GetValue(i).ToString()) { case "System.Byte[]": byte[] data = (byte[])reader[reader.GetName(i)]; item.Add(reader.GetName(i), data); break; default: item.Add(reader.GetName(i), reader.GetString(i)); break; } } catch (System.Data.SqlTypes.SqlNullValueException ex) { item.Add(reader.GetName(i), null); } } result.Add(item); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } return(result); }
/// <summary> /// - 쿼리 입력 시에 마지막에 limit를 자동으로 입력해줌. /// - 쿼리 마지막에 ';' 입력 금지 /// </summary> /// <param name="queryString"></param> /// <param name="limit"></param> /// <param name="page"></param> /// <returns></returns> public JSResults Select_Paging(string queryString, int limit, int page) { JSResults result = new JSResults(); MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(queryString + " LIMIT " + (limit * (page - 1)) + ", " + limit + ";", conn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { JSResult item = new JSResult(); for (int i = 0; i < reader.FieldCount; i++) { try { switch (reader.GetValue(i).ToString()) { case "System.Byte[]": byte[] data = (byte[])reader[reader.GetName(i)]; item.Add(reader.GetName(i), data); break; default: item.Add(reader.GetName(i), reader.GetString(i)); break; } } catch (System.Data.SqlTypes.SqlNullValueException ex) { item.Add(reader.GetName(i), null); } } result.Add(item); } } catch (Exception ex) { } finally { conn.Close(); } return(result); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/json"; CustomerData customerObject = new CustomerData(); JSResult.ProcessRequest(context, () => { string position = this.GetPosition(); customerObject.CustomerDepartment = this.ConvertDepartmentNameToID(this.CheckDepartment(position)); customerObject.CustomerResponsibilityZone = this.CheckResponsibilityZone(position); string json = DataSerializer.SerializeJSON(customerObject); Result = null; return(customerObject); }); }
public JSResults Select(string query) { if (true == ConnectToOracle()) { JSResults result = new JSResults(); Dictionary <int, byte[]> images = new Dictionary <int, byte[]>(); OracleCommand oracle_cmd = new OracleCommand(query, connToORACLE); OracleDataReader oracle_reader = oracle_cmd.ExecuteReader(); try { while (oracle_reader.Read()) { JSResult item = new JSResult(); for (int i = 0; i < oracle_reader.FieldCount; i++) { string s = oracle_reader.GetName(i); item.Add(oracle_reader.GetName(i), (string)oracle_reader.GetValue(i).ToString()); //오라클 바이트처리 해야됨...... } result.Add(item); } } finally { UnconnectToOracle(); } if (result.Count != 0) { return(result); } else { return(null); } } return(null); }
public JSResults Select(string queryString) { JSResults result = new JSResults(); try { conn.Open(); using (var command = new NpgsqlCommand()) { command.Connection = conn; command.CommandText = queryString; using (var reader = command.ExecuteReader()) { while (reader.Read()) { JSResult item = new JSResult(); for (int i = 0; i < reader.FieldCount; i++) { if (reader.IsDBNull(i) == false) { Console.WriteLine(reader.GetName(i) + " : " + reader.GetPostgresType(i).ToString()); switch (reader.GetPostgresType(i).ToString()) { //case : // byte[] data = (byte[])reader[reader.GetName(i)]; // item.Add(reader.GetName(i), data); // break; case "integer": item.Add(reader.GetName(i), reader.GetInt32(i)); break; case "date": item.Add(reader.GetName(i), reader.GetDate(i)); break; case "timestamp without time zone": item.Add(reader.GetName(i), reader.GetTimeStamp(i)); break; case "jsonb": case "character": case "character varying": item.Add(reader.GetName(i), reader.GetString(i)); break; default: Console.WriteLine("===================" + reader.GetName(i) + " : " + reader.GetPostgresType(i).ToString()); break; } } else { item.Add(reader.GetName(i), null); } } result.Add(item); } reader.Close(); } } } catch (Npgsql.PostgresException ex) { return(result); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } return(result); }