private string SanitizeString(DbTypes dbType, string s) { if (String.IsNullOrEmpty(s)) { return(String.Empty); } string ret = ""; switch (dbType) { case DbTypes.MsSql: ret = MssqlHelper.SanitizeString(s); break; case DbTypes.MySql: ret = MysqlHelper.SanitizeString(s); break; case DbTypes.PgSql: ret = PgsqlHelper.SanitizeString(s); break; } return(ret); }
private string PreparedStringValue(string s) { switch (_DbType) { case DbTypes.MsSql: return("'" + MssqlHelper.SanitizeString(s) + "'"); case DbTypes.MySql: return("'" + MysqlHelper.SanitizeString(s) + "'"); case DbTypes.PgSql: // uses $xx$ escaping return(PgsqlHelper.SanitizeString(s)); } return(null); }
private void PopulaConnectionString() { ConnectionString = ""; switch (_DbType) { case DbTypes.MsSql: ConnectionString = MssqlHelper.ConnectionString(_ServerIp, _ServerPort, _Username, _Password, _Instance, _DatabaseName); break; case DbTypes.MySql: ConnectionString = MysqlHelper.ConnectionString(_ServerIp, _ServerPort, _Username, _Password, _DatabaseName); break; case DbTypes.PgSql: ConnectionString = PgsqlHelper.ConnectionString(_ServerIp, _ServerPort, _Username, _Password, _DatabaseName); break; } return; }
/// <summary> /// Sanitize an input string. /// </summary> /// <param name="val">The value to sanitize.</param> /// <returns>A sanitized string.</returns> public string SanitizeString(string val) { if (String.IsNullOrEmpty(val)) { return(val); } switch (_DbType) { case DbTypes.MsSql: return(MssqlHelper.SanitizeString(val)); case DbTypes.MySql: return(MysqlHelper.SanitizeString(val)); case DbTypes.PgSql: return(PgsqlHelper.SanitizeString(val)); } throw new Exception("Unknown database type"); }
private void CarregaDetalhesTabela() { lock (_LoadingTablesLock) { string query = ""; DataTable result = new DataTable(); Dictionary <string, List <Coluna> > tableDetails = new Dictionary <string, List <Coluna> >(); foreach (string currTable in _TableNames) { #region Gather-Schema List <Coluna> columns = new List <Coluna>(); List <Constraint> mReferrencias = new List <Constraint>(); switch (_DbType) { case DbTypes.MsSql: query = MssqlHelper.LoadTableColumnsQuery(_DatabaseName, currTable); break; case DbTypes.MySql: query = MysqlHelper.LoadTableColumnsQuery(_DatabaseName, currTable); break; case DbTypes.PgSql: query = PgsqlHelper.LoadTableColumnsQuery(_DatabaseName, currTable); break; } #endregion #region Process-Schema result = Query(query); if (result != null && result.Rows.Count > 0) { foreach (DataRow currColumn in result.Rows) { #region Process-Each-Column /* * public bool IsPrimaryKey; * public string Name; * public string DataType; * public int? MaxLength; * public bool Nullable; */ Coluna tempColumn = new Coluna(); int maxLength = 0; switch (_DbType) { case DbTypes.MsSql: #region Mssql tempColumn.Name = currColumn["COLUMN_NAME"].ToString(); if (currColumn["CONSTRAINT_NAME"].ToString().StartsWith("PK_")) { tempColumn.IsPrimaryKey = true; } else { tempColumn.IsPrimaryKey = false; } tempColumn.DataType = currColumn["DATA_TYPE"].ToString(); if (!Int32.TryParse(currColumn["CHARACTER_MAXIMUM_LENGTH"].ToString(), out maxLength)) { tempColumn.MaxLength = null; } else { tempColumn.MaxLength = maxLength; } if (String.Compare(currColumn["IS_NULLABLE"].ToString(), "YES") == 0) { tempColumn.Nullable = true; } else { tempColumn.Nullable = false; } break; #endregion case DbTypes.MySql: #region Mysql tempColumn.Name = currColumn["COLUMN_NAME"].ToString(); if (String.Compare(currColumn["COLUMN_KEY"].ToString(), "PRI") == 0) { tempColumn.IsPrimaryKey = true; } else { tempColumn.IsPrimaryKey = false; } tempColumn.DataType = currColumn["DATA_TYPE"].ToString(); if (!Int32.TryParse(currColumn["CHARACTER_MAXIMUM_LENGTH"].ToString(), out maxLength)) { tempColumn.MaxLength = null; } else { tempColumn.MaxLength = maxLength; } if (String.Compare(currColumn["IS_NULLABLE"].ToString(), "YES") == 0) { tempColumn.Nullable = true; } else { tempColumn.Nullable = false; } break; #endregion case DbTypes.PgSql: #region Pgsql tempColumn.Name = "\"" + currColumn["column_name"].ToString() + "\""; if (String.Compare(currColumn["is_primary_key"].ToString(), "YES") == 0) { tempColumn.IsPrimaryKey = true; } else { tempColumn.IsPrimaryKey = false; } tempColumn.DataType = currColumn["DATA_TYPE"].ToString(); if (!Int32.TryParse(currColumn["max_len"].ToString(), out maxLength)) { tempColumn.MaxLength = null; } else { tempColumn.MaxLength = maxLength; } if (String.Compare(currColumn["IS_NULLABLE"].ToString(), "YES") == 0) { tempColumn.Nullable = true; } else { tempColumn.Nullable = false; } if (string.IsNullOrEmpty(currColumn["column_default"].ToString())) { tempColumn.Default = ""; } else { tempColumn.Default = currColumn["column_default"].ToString(); } break; #endregion } columns.Add(tempColumn); #endregion } tableDetails.Add(currTable, columns); switch (_DbType) { case DbTypes.MsSql: query = ""; break; case DbTypes.MySql: query = ""; break; case DbTypes.PgSql: query = PgsqlHelper.LoadConstraintQuery(_DatabaseName, currTable); break; } if (!string.IsNullOrEmpty(query)) { result = Query(query); if (result != null && result.Rows.Count > 0) { foreach (DataRow currColumn in result.Rows) { #region Process-Each-Column Constraint tempConstraint = new Constraint(); switch (_DbType) { case DbTypes.MsSql: #region Mssql break; #endregion case DbTypes.MySql: #region Mysql break; #endregion case DbTypes.PgSql: #region Pgsql tempConstraint.Name = "\"" + currColumn["constraint_name"].ToString() + "\""; tempConstraint.ForeignTable = "\"" + currColumn["foreign_table_name"].ToString() + "\""; tempConstraint.ForeignColumns = "\"" + currColumn["foreign_column_name"].ToString() + "\""; tempConstraint.LocalColumns = "\"" + currColumn["column_name"].ToString() + "\""; tempConstraint.Type = currColumn["constraint_type"].ToString(); break; #endregion } mReferrencias.Add(tempConstraint); #endregion } } } } mTabelas.Add(new Tabela("\"" + currTable + "\"", columns, mReferrencias)); #endregion } #region Replace-Table-Details _TableDetails = new ConcurrentDictionary <string, List <Coluna> >(); foreach (KeyValuePair <string, List <Coluna> > curr in tableDetails) { _TableDetails.TryAdd(curr.Key, curr.Value); } #endregion return; } }
private void CarregaTabelas() { lock (_LoadingTablesLock) { string query = ""; DataTable result = new DataTable(); #region Build-Query switch (_DbType) { case DbTypes.MsSql: query = MssqlHelper.LoadTableNamesQuery(_DatabaseName); break; case DbTypes.MySql: query = MysqlHelper.LoadTableNamesQuery(); break; case DbTypes.PgSql: query = PgsqlHelper.LoadTableNamesQuery(); break; } #endregion #region Process-Results result = Query(query); List <string> tableNames = new List <string>(); if (result != null && result.Rows.Count > 0) { switch (_DbType) { case DbTypes.MsSql: foreach (DataRow curr in result.Rows) { tableNames.Add(curr["TABLE_NAME"].ToString()); } break; case DbTypes.MySql: foreach (DataRow curr in result.Rows) { tableNames.Add(curr["Tables_in_" + _DatabaseName].ToString()); } break; case DbTypes.PgSql: foreach (DataRow curr in result.Rows) { tableNames.Add(curr["tablename"].ToString()); } break; } } if (tableNames != null && tableNames.Count > 0) { _TableNames = new ListaConcorrente <string>(); foreach (string curr in tableNames) { _TableNames.Add(curr); } } #endregion return; } }