Esempio n. 1
0
        internal object GetScalar(string sqlQuery, CSParameterCollection parameters)
        {
            long logId = Log(sqlQuery, parameters);

            try
            {
                using (ICSDbCommand dbCommand = CreateCommandInternal(sqlQuery, parameters))
                {
                    using (ICSDbReader reader = dbCommand.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            object r = reader[0];

                            return((r is DBNull) ? null : r);
                        }
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw new CSSQLException("GetScalar exception", ex, sqlQuery, parameters);
            }
            finally
            {
                LogEnd(logId);

                CSNameGenerator.Reset();
            }
        }
Esempio n. 2
0
        protected internal int ExecuteNonQuery(string sqlQuery, CSParameterCollection parameters)
        {
            long logId = Log(sqlQuery, parameters);


            try
            {
                using (ICSDbCommand dbCommand = CreateCommandInternal(sqlQuery, parameters))
                    dbCommand.ExecuteNonQuery();

                return(1);
            }
            catch (InvalidOperationException)
            {
                return(-1);
            }
            catch (Exception ex)
            {
                throw new CSSQLException("ExecuteNonQuery exception", ex, sqlQuery, parameters);
            }
            finally
            {
                LogEnd(logId);

                CSNameGenerator.Reset();
            }
        }
Esempio n. 3
0
        protected internal ICSDbCommand CreateCommandInternal(string sqlQuery, CSParameterCollection parameters)
        {
            ICSDbCommand command = CreateCommand(sqlQuery, parameters);

            if (CSConfig.CommandTimeout.HasValue)
            {
                command.CommandTimeout = CSConfig.CommandTimeout.Value;
            }

            return(command);
        }
        protected internal override CSSchemaColumn[] GetSchemaColumns(string tableName)
        {
            using (ICSDbConnection newConn = CreateConnection())
            {
                ICSDbCommand dbCommand = newConn.CreateCommand();

                dbCommand.CommandText = "select * from " + QuoteTable(tableName);

                using (var dataReader = (CSSqlReader)dbCommand.ExecuteReader(CSCommandBehavior.SchemaOnly | CSCommandBehavior.KeyInfo))
                {
                    var schemaColumns = new List <CSSchemaColumn>();

                    DataTable schemaTable = dataReader.Reader.GetSchemaTable();

                    bool hasHidden        = schemaTable.Columns.Contains("IsHidden");
                    bool hasIdentity      = schemaTable.Columns.Contains("IsIdentity");
                    bool hasAutoincrement = schemaTable.Columns.Contains("IsAutoIncrement");

                    foreach (DataRow schemaRow in schemaTable.Rows)
                    {
                        var schemaColumn = new CSSchemaColumn();

                        if (hasHidden && !schemaRow.IsNull("IsHidden") && (bool)schemaRow["IsHidden"])
                        {
                            schemaColumn.Hidden = true;
                        }

                        if (hasIdentity && !schemaRow.IsNull("IsIdentity") && (bool)schemaRow["IsIdentity"])
                        {
                            schemaColumn.Identity = true;
                        }

                        schemaColumn.IsKey     = (bool)schemaRow["IsKey"];
                        schemaColumn.AllowNull = (bool)schemaRow["AllowDBNull"];
                        schemaColumn.Name      = (string)schemaRow["ColumnName"];
                        schemaColumn.ReadOnly  = (bool)schemaRow["IsReadOnly"];
                        schemaColumn.DataType  = (Type)schemaRow["DataType"];
                        schemaColumn.Size      = (int)schemaRow["ColumnSize"];

                        if (hasAutoincrement && !schemaRow.IsNull("IsAutoIncrement") && (bool)schemaRow["IsAutoIncrement"])
                        {
                            schemaColumn.Identity = true;
                        }


                        schemaColumns.Add(schemaColumn);
                    }

                    return(schemaColumns.ToArray());
                }
            }
        }
Esempio n. 5
0
        protected internal ICSDbReader CreateReader(string sqlQuery, CSParameterCollection parameters)
        {
            long logId = Log(sqlQuery, parameters);

            try
            {
                using (ICSDbCommand dbCommand = CreateCommandInternal(sqlQuery, parameters))
                    return(dbCommand.ExecuteReader());
            }
            catch (Exception ex)
            {
                throw new CSSQLException("Error executing query. Possible syntax error", ex, sqlQuery, parameters);
            }
            finally
            {
                LogEnd(logId);

                CSNameGenerator.Reset();
            }
        }
		public override void DeriveParameters (ICSDbCommand dbCommand)
		{
			SqlCommandBuilder.DeriveParameters ((dbCommand as CSSqlCommand).Command);
		}
		public override void DeriveParameters (ICSDbCommand dbCommand)
		{
			//throw new NotImplementedException ();
			OleDbCommandBuilder.DeriveParameters ((dbCommand as CSAccessCommand).Command);
		}