예제 #1
0
        public static XVar getRefinedDateFormat(XVar dateFormat)
        {
            var refinedFormat = "";

            string dateFormatStr = dateFormat.ToLower();

            for (int i = 0; i < dateFormatStr.Length; i++)
            {
                var letter = dateFormatStr[i];
                if ((letter == 'd' || letter == 'm' || letter == 'y') && !refinedFormat.Contains(letter))
                {
                    refinedFormat += letter;
                }
            }

            return(refinedFormat);
        }
예제 #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);
            }
        }