Esempio n. 1
0
        /**
         * An interface stub.
         * Open a connection to db
         */
        public XVar connect()
        {
            // db_connect
            try
            {
                connectionsPool = GetConnectionsPool(GlobalVars.ConnectionStrings[connId]);
                XVar connect = new XVar(connectionsPool.FreeConnection);
            }
            catch (Exception e)
            {
                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
                return(null);
            }

            return(new XVar(connectionsPool.FreeConnection));
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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;
                    }
                }
            }
        }