Exemple #1
0
        public static void Init(EcmaScript energy)
        {
            EcmaHeadObject obj = new EcmaHeadObject();

            obj.Class = "MysqlConnector";
            obj.Put("connect", EcmaValue.Object(new NativeFunctionInstance(4, energy.State, (EcmaHeadObject o, EcmaValue[] arg) =>
            {
                MySqlConnection connection = new MySqlConnection("SERVER=" + arg[0].ToString(energy.State) + ";UID=" + arg[1].ToString(energy.State) + ";PASSWORD="******";DATABASE=" + arg[3].ToString(energy.State) + ";");
                try
                {
                    connection.Open();
                    return(EcmaValue.Object(new MysqlValue(energy.State, connection)));
                }
                catch (MySqlException)
                {
                    return(EcmaValue.Null());
                }
            })));
            energy.CreateVariable("MysqlConnector", EcmaValue.Object(obj));

            obj       = new EcmaHeadObject();
            obj.Class = "Mysql";
            obj.Put("escape", EcmaValue.Object(new NativeFunctionInstance(1, energy.State, (EcmaHeadObject o, EcmaValue[] arg) =>
            {
                return(EcmaValue.String(MySqlHelper.EscapeString(arg[0].ToString(energy.State))));
            })));
        }
Exemple #2
0
 public DefaultScript(EcmaScript e)
 {
     state = e.State;
     e.CreateVariable("include", EcmaValue.Object(new NativeFunctionInstance(1, state, Include)));
 }