Beispiel #1
0
        public virtual XVar db_getfieldslist(XVar strSQL)
        {
            XVar           res = XVar.Array();
            RunnerDBReader rs  = conn.query(strSQL).getQueryHandle() as RunnerDBReader;

            for (int i = 0; i < rs.FieldCount; i++)
            {
                res[i] = new XVar("fieldname", rs.GetName(i), "type", rs.GetFieldType(i), "not_null", 0);
            }
            rs.Connection.Close();
            return(res);
        }
Beispiel #2
0
        /**
         * An interface stub
         * Fetch a result row as a numeric array
         * @param Mixed qHanle		The query handle
         * @return Array
         */
        public XVar fetch_numarray(dynamic qHanle)
        {
            //db_fetch_numarray
            if (qHanle != null)
            {
                RunnerDBReader reader = (RunnerDBReader)qHanle;
                if (reader.Read())
                {
                    XVar result = new XVar();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        result.SetArrayItem(i, reader[i]);
                    }
                    return(result);
                }
            }

            return(XVar.Array());
        }
Beispiel #3
0
 virtual protected void CalculateLastInsertedId(string qstring, DbCommand cmd)
 {
     if (qstring.ToLower().IndexOf("insert").Equals(0))
     {
         lastInsertedID = "";
         try
         {
             cmd.CommandText = GetLastInsertedIdSql();
             cmd.Prepare();
             RunnerDBReader rdr = cmd.ExecuteReader();
             rdr.Connection = cmd.Connection;
             if (rdr.Read())
             {
                 lastInsertedID = new XVar(rdr[0]);
             }
         }
         catch (Exception e) { }
     }
 }
Beispiel #4
0
        /**
         * An interface stub
         * @param Mixed qHandle
         * @param Number pageSize
         * @param Number page
         */
        public XVar seekPage(XVar qHandle, XVar pageSize, XVar page)
        {
            //db_pageseek
            if (page == 1)
            {
                return(null);
            }

            if (qHandle != null)
            {
                RunnerDBReader reader = qHandle as RunnerDBReader;
                for (int i = 0; i < pageSize * (page - 1); i++)
                {
                    if (!reader.Read())
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }
        public static dynamic Query(dynamic strSQL)
        {
            Oracle.ManagedDataAccess.Client.OracleConnection connection = new Oracle.ManagedDataAccess.Client.OracleConnection();
            connection.ConnectionString = DB.connectionString;
            connection.Open();

            Oracle.ManagedDataAccess.Client.OracleCommand dbCommand = new Oracle.ManagedDataAccess.Client.OracleCommand(strSQL, connection);
            dbCommand.CommandType = System.Data.CommandType.Text;
            try {
                dbCommand.Prepare();
                string   commandStr      = strSQL.ToLower().Substring(0, 6);
                string[] stopCommandList = { "insert", "update", "delete", "create", "drop", "rename", "alter" };
                if (stopCommandList.Any(x => commandStr.Substring(0, x.Length) == x))
                {
                    dbCommand.ExecuteNonQuery();
                    dbCommand.Connection.Close();
                    return(null);
                }
                else
                {
                    RunnerDBReader rdr = dbCommand.ExecuteReader();
                    rdr.Connection = dbCommand.Connection;

                    return(new QueryResult(dbCommand.Connection, rdr));
                }
            }  catch (Exception e) {
                if (dbCommand != null)
                {
                    dbCommand.Connection.Close();
                }
                throw e;

                return(null);
            }

            dbCommand.Dispose();
            dbCommand = null;
            connection.Close();
        }
Beispiel #6
0
        /**
         * An interface stub
         * Send an SQL query
         * @param String sql
         * @return QueryResult
         */
        public QueryResult query(XVar sql)
        {
            //db_query
            //return new QueryResult( this, qHandle );

            if (GlobalVars.dDebug)
            {
                MVCFunctions.EchoToOutput(sql.ToString() + "<br />");
            }

            GlobalVars.strLastSQL = sql;
            DbCommand cmd     = null;
            DbCommand initCmd = null;

            try {
                DbConnection connection = connectionsPool.FreeConnection;
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                    if (initializingSQL != null)
                    {
                        initCmd             = GetCommand();
                        initCmd.Connection  = connection;
                        initCmd.CommandText = initializingSQL;
                        initCmd.Prepare();
                        initCmd.ExecuteNonQuery();
                    }
                }
                cmd             = GetCommand();
                cmd.Connection  = connection;
                cmd.CommandText = sql;
                cmd.Prepare();

                string    commandStr      = sql.ToLower().Substring(0, 6);
                string [] stopCommandList = { "insert", "update", "delete", "create", "drop", "rename", "alter" };
                if (stopCommandList.Any(x => commandStr.Substring(0, x.Length) == x))
                {
                    cmd.ExecuteNonQuery();
                    CalculateLastInsertedId(commandStr, cmd);
                    cmd.Connection.Close();
                    return(null);
                }
                else
                {
                    RunnerDBReader rdr = cmd.ExecuteReader();
                    rdr.Connection = cmd.Connection;
                    return(new QueryResult(this, rdr));
                }
            }
            catch (Exception e)
            {
                GlobalVars.LastDBError = e.Message;
                if (cmd != null)
                {
                    cmd.Connection.Close();
                }

                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
                return(null);
            }
        }
Beispiel #7
0
        public override void db_multipleInsertQuery(XVar qstringArray, XVar table = null, XVar isIdentityOffNeeded = null)
        {
            try
            {
                DbConnection connection = connectionsPool.FreeConnection;
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                }

                DbCommand cmd = GetCommand();
                cmd.Connection = connection;

                if (isIdentityOffNeeded)
                {
                    cmd.CommandText = "SET IDENTITY_INSERT " + table.ToString() + " ON";
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                foreach (var qstring in qstringArray.GetEnumerator())
                {
                    if (GlobalVars.dDebug)
                    {
                        MVCFunctions.EchoToOutput(qstring.Value.ToString() + "<br />");
                    }

                    GlobalVars.strLastSQL = qstring.Value;

                    cmd.CommandText = qstring.Value.ToString();

                    cmd.ExecuteNonQuery();
                }
                if (isIdentityOffNeeded)
                {
                    cmd.CommandText = "SET IDENTITY_INSERT " + table.ToString() + " OFF";
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    cmd.CommandText = "select @@IDENTITY as indent";
                    cmd.Prepare();
                    RunnerDBReader rdr = cmd.ExecuteReader();
                    rdr.Connection = cmd.Connection;
                    if (rdr.Read())
                    {
                        lastInsertedID = new XVar(rdr["indent"]);
                    }
                }
                connection.Close();
            }
            catch (Exception e)
            {
                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
            }
        }