/// <summary> /// Returns wheter given table exists on this database. /// </summary> /// <param name="table"></param> /// <returns></returns> public bool tableExists(string table) { var q = new Query.Count("INFORMATION_SCHEMA.TABLES"); q.where (new Where.Equals("TABLE_NAME", table)); return(count(q) > 0); }
/// <summary> /// Executes the provided count query and returns the (single) count result by reading the COUNT result. /// </summary> /// <param name="query"></param> /// <returns></returns> public int count(Query.Count query) { int count = 0; using (var sql = connect()) { using (var cmd = new SqlCommand(useDatabase(query.build()), sql)) { foreach (var a in query.arguments) { if (a.Value != null) { cmd.Parameters.AddWithValue(a.Key, a.Value); } } sql.Open(); using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { count = dr.GetInt32(dr.GetOrdinal("count")); } } } } return(count); }