public void CreateActionPhpScript(string objectName, string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            if (string.CompareOrdinal(methodName, "StartWithParameterValues") == 0)
            {
                if (!phpSupported())
                {
                    return;
                }
                if (DataDestination != null && DataDestination.DatabaseDestination != null && DataDestination.DatabaseDestination.Fields.Count > 0)
                {
                    if (this.PhpTimeoutInMinutes > 0)
                    {
                        addCode(code, "if($this->{0}->PhpTimeoutInMinutes>0) ini_set('max_execution_time', $this->{0}->PhpTimeoutInMinutes * 60);\r\n", this.Site.Name);
                    }
                    string tblVar = string.Format(CultureInfo.InvariantCulture, "tbl{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    if (DataSource.SourceType == EnumDataSource.Database)
                    {
                        EasyQuery qry = DataSource.DatabaseSource.QueryDef;
                        if (qry != null)
                        {
                            //===fetch data==================================================================
                            string mySql = string.Format(CultureInfo.InvariantCulture, "mysql{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                            addCode(code, "\t${0} = new JsonSourceMySql();\r\n", mySql);
                            //
                            addCode(code, "\t${0}->SetCredential($this->{1}->sourceCredential);\r\n", mySql, this.Site.Name);
                            addCode(code, "\t${0}->SetDebug($this->DEBUG);\r\n", mySql);
                            string sql = qry.SqlQuery;
                            //sqlParams contains parameter names orderred by the appearance in sql, may duplicate
                            string[] sqlParams = EasyQuery.GetParameterNames(sql, qry.NameDelimiterBegin, qry.NameDelimiterEnd);
                            if (this.Parameters != null)
                            {
                                for (int i = 0; i < this.Parameters.Count; i++)
                                {
                                    sql = sql.Replace(this.Parameters[i].Name, "?");
                                }
                            }
                            string sqlVar = string.Format(CultureInfo.InvariantCulture, "sql{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                            addCode(code, "\t${0} = \"{1} \";\r\n", sqlVar, sql);
                            addCode(code, "\t${0} = new JsonDataTable();\r\n", tblVar);
                            addCode(code, "\t${0}->TableName = '{1}';\r\n", tblVar, qry.TableName);
                            string psVar = string.Format(CultureInfo.InvariantCulture, "ps{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                            addCode(code, "\t${0} = array();\r\n", psVar);
                            if (qry.Parameters != null)
                            {
                                DbParameterList dbps = new DbParameterList(qry.Parameters);
                                for (int i = 0; i < sqlParams.Length; i++)
                                {
                                    int k = dbps.GetIndex(sqlParams[i]);
                                    if (k < 0)
                                    {
                                        throw new ExceptionLimnorDatabase("Query Parameter [{0}] not found", sqlParams[i]);
                                    }
                                    DbCommandParam dp   = dbps[k];
                                    string         pVar = string.Format(CultureInfo.InvariantCulture, "p{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                                    addCode(code, "\t${0} = new SqlClientParameter();\r\n", pVar);
                                    addCode(code, "\t${0}->name = '{1}';\r\n", pVar, dp.Name);
                                    addCode(code, "\t${0}->type = '{1}';\r\n", pVar, ValueConvertor.OleDbTypeToPhpMySqlType(dp.Type));
                                    addCode(code, "\t${0}->value = {1};\r\n", pVar, parameters[k]);
                                    addCode(code, "\t${0}[] = ${1};\r\n//\r\n", psVar, pVar);
                                }
                            }
                            addCode(code, "\t${0}->GetData(${1},${2},${3});\r\n", mySql, tblVar, sqlVar, psVar);
                            addCode(code, "\t$this->{0}->ErrorMessage = ${1}->errorMessage;\r\n", this.Site.Name, mySql);
                            //===data fetched on tblVar=============================================================
                        }
                    }
                    else if (DataSource.SourceType == EnumDataSource.TextFile)
                    {
                        string tblName    = string.Format(CultureInfo.InvariantCulture, "srcTbl{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                        string txtFileVar = string.Format(CultureInfo.InvariantCulture, "txtFile{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                        addCode(code, "${0} = new DataSourceTextFile();\r\n", txtFileVar);
                        addCode(code, "\t${0} = new JsonDataTable();\r\n", tblVar);
                        addCode(code, "\t${0}->TableName = '{1}';\r\n", tblVar, tblName);
                        //
                        if (this.DataSource.TextSource.Delimiter == enumSourceTextDelimiter.Comma)
                        {
                            addCode(code, "\t${0}->delimiter=',';\r\n", txtFileVar);
                        }
                        else if (this.DataSource.TextSource.Delimiter == enumSourceTextDelimiter.TAB)
                        {
                            addCode(code, "\t${0}->delimiter='\\t';\r\n", txtFileVar);
                        }
                        if (this.DataSource.TextSource.HasHeader)
                        {
                            addCode(code, "\t${0}->hasHeader=true;\r\n", txtFileVar);
                        }
                        else
                        {
                            addCode(code, "\t${0}->hasHeader=false;\r\n", txtFileVar);
                        }
                        IPropertyValueLink fnl = this.DataSource.TextSource.GetPropertyLink("Filename");
                        if (fnl != null && fnl.IsValueLinkSet())
                        {
                            addCode(code, "\t${0}->filepath={1};\r\n", txtFileVar, fnl.GetPhpScriptReferenceCode(code));
                        }
                        else
                        {
                            addCode(code, "\t${0}->filepath='{1}';\r\n", txtFileVar, this.DataSource.TextSource.Filename);
                        }
                        //
                        addCode(code, "\t${0}->GetData(${1});\r\n", txtFileVar, tblVar);
                        addCode(code, "\t$this->{0}->ErrorMessage = ${1}->errorMessage;\r\n", this.Site.Name, txtFileVar);
                        addCode(code, "\tif(strlen(${0}->errorMessage) > 0)\r\n", txtFileVar);
                        code.Add("\t{\r\n");
                        code.Add("\t\tif($this->DEBUG)\r\n\t\t{\r\n");
                        addCode(code, "\t\t\techo 'Error reading text file: '.${0}->filepath.' Error message:'.${0}->errorMessage;\r\n", txtFileVar);
                        code.Add("\t\t\treturn;\r\n");
                        code.Add("\t\t}\r\n");
                        code.Add("\t}\r\n");
                    }
                    //
                    string mySqlTVar = string.Format(CultureInfo.InvariantCulture, "mySqlT{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\t${0} = new JsonSourceMySql();\r\n", mySqlTVar);
                    addCode(code, "\t${0}->SetCredential($this->{1}->destinationCredential);\r\n", mySqlTVar, this.Site.Name);
                    addCode(code, "\t${0}->SetDebug($this->DEBUG);\r\n", mySqlTVar);
                    //
                    StringBuilder sbSql       = new StringBuilder();
                    StringBuilder sbSqlValues = new StringBuilder();
                    sbSql.Append("Insert into ");
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterBegin);
                    sbSql.Append(DataDestination.DatabaseDestination.TableName);
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterEnd);
                    sbSql.Append(" (");
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterBegin);
                    sbSql.Append(DataDestination.DatabaseDestination.Fields[0].Name);
                    sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterEnd);
                    sbSqlValues.Append("?");
                    for (int i = 1; i < DataDestination.DatabaseDestination.Fields.Count; i++)
                    {
                        sbSql.Append(",");
                        sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterBegin);
                        sbSql.Append(DataDestination.DatabaseDestination.Fields[i].Name);
                        sbSql.Append(DataDestination.DatabaseDestination.DatabaseConnection.NameDelimiterEnd);
                        sbSqlValues.Append(",?");
                    }
                    sbSql.Append(") values (");
                    sbSql.Append(sbSqlValues.ToString());
                    sbSql.Append(")");
                    //
                    string myIVar = string.Format(CultureInfo.InvariantCulture, "mySqlI{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\t${0} = ${1}->GetMySqli();\r\n", myIVar, mySqlTVar);
                    string statementVar = string.Format(CultureInfo.InvariantCulture, "state{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\t${0}=${1}->prepareStatement(${2},\"{3}\");\r\n", statementVar, mySqlTVar, myIVar, sbSql.ToString());
                    //
                    string paramsVar = string.Format(CultureInfo.InvariantCulture, "params{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    //
                    code.Add("\t//loop through rows of $tbl\r\n");
                    string idxVar = string.Format(CultureInfo.InvariantCulture, "idx{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    string rowVar = string.Format(CultureInfo.InvariantCulture, "row{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    addCode(code, "\tforeach (${0}->Rows as ${1} => ${2})\r\n", tblVar, idxVar, rowVar);
                    code.Add("\t{\r\n");
                    addCode(code, "\t\t${0}=array();\r\n", paramsVar);
                    string paramVar = string.Format(CultureInfo.InvariantCulture, "param{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                    for (int i = 0; i < DataDestination.DatabaseDestination.Fields.Count; i++)
                    {
                        addCode(code, "\t\t${0}=new SqlClientParameter();\r\n", paramVar);

                        addCode(code, "\t\t${0}->name = '{1}';\r\n", paramVar, DataDestination.DatabaseDestination.Fields[i].Name);
                        addCode(code, "\t\t${0}->type = '{1}';\r\n", paramVar, ValueConvertor.OleDbTypeToPhpMySqlType(DataDestination.DatabaseDestination.Fields[i].OleDbType));
                        addCode(code, "\t\t${0}->value = ${1}->ItemArray[{2}];\r\n", paramVar, rowVar, i);
                        addCode(code, "\t\t${0}[] = ${1};\r\n//\r\n", paramsVar, paramVar);
                    }
                    addCode(code, "\t\t${0}->executeStatement(${1},${2}, ${3});\r\n", mySqlTVar, myIVar, statementVar, paramsVar);
                    //
                    code.Add("\t}\r\n");
                    //
                    addCode(code, "\t${0}->free_result();\r\n", statementVar);
                    addCode(code, "\t${0}->close();\r\n", statementVar);
                    addCode(code, "\t${0}->close();\r\n", myIVar);
                }
                //
                code.Add(string.Format(CultureInfo.InvariantCulture, "\t$this->SetServerComponentName('{0}');\r\n", this.Site.Name));
            }
        }
        public void CreateActionPhpScript(string objectName, string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            string connName = GetConnectionCodeName();

            if (string.CompareOrdinal(methodName, "ExecuteWithParameterValues") == 0)
            {
                if (_sql != null && connect != null)
                {
                    code.Add("$GLOBALS[\"debugError\"] = '';\r\n");
                    code.Add("$msql = new JsonSourceMySql();\r\n");
                    code.Add(string.Format(CultureInfo.InvariantCulture, "$msql->SetCredential($this->{0});\r\n", connName));
                    code.Add("$msql->SetDebug($this->DEBUG);\r\n");
                    //
                    string        sql;
                    string[]      sqlParams;
                    List <string> inputParams  = new List <string>();
                    List <string> outputParams = new List <string>();
                    if (this.IsStoredProc)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("call ");
                        sb.Append(_sql.SQL);
                        sb.Append("(");
                        DatabaseExecuter de = this as DatabaseExecuter;
                        DbParameterList  ps = de.Parameters;
                        if (ps != null && ps.Count > 0)
                        {
                            ParameterDirection[] pds = de.Param_Directions;
                            for (int i = 0; i < ps.Count; i++)
                            {
                                if (i > 0)
                                {
                                    sb.Append(",");
                                }
                                ParameterDirection pd = ParameterDirection.Input;
                                if (pds != null && pds.Length > i)
                                {
                                    pd = pds[i];
                                }
                                switch (pd)
                                {
                                case ParameterDirection.Input:
                                    inputParams.Add(ps[i].Name);
                                    sb.Append(" ? ");
                                    break;

                                case ParameterDirection.InputOutput:
                                    outputParams.Add(ps[i].Name);
                                    sb.Append(string.Format(CultureInfo.InvariantCulture, " @{0} ", ps[i].Name));
                                    break;

                                case ParameterDirection.Output:
                                    outputParams.Add(ps[i].Name);
                                    sb.Append(string.Format(CultureInfo.InvariantCulture, " @{0} ", ps[i].Name));
                                    break;
                                }
                            }
                            sqlParams = inputParams.ToArray();
                        }
                        else
                        {
                            sqlParams = new string[] { };
                        }
                        sb.Append(")");
                        sql = sb.ToString();
                    }
                    else
                    {
                        sql       = _sql.SQL;
                        sqlParams = EasyQuery.GetParameterNames(sql, connect.NameDelimiterBegin, connect.NameDelimiterEnd);
                        if (sqlParams != null)
                        {
                            for (int i = 0; i < sqlParams.Length; i++)
                            {
                                sql = sql.Replace(sqlParams[i], "?");
                            }
                        }
                    }
                    code.Add(string.Format(CultureInfo.InvariantCulture, "$sql = \"{0} \";\r\n", sql));
                    code.Add("$ps = array();\r\n");
                    if (this.Parameters != null)
                    {
                        for (int i = 0; i < sqlParams.Length; i++)
                        {
                            int k = this.Parameters.GetIndex(sqlParams[i]);
                            if (k < 0)
                            {
                                throw new ExceptionLimnorDatabase("Query Parameter [{0}] not found", sqlParams[i]);
                            }
                            DbCommandParam dp = this.Parameters[k];
                            code.Add("$p = new SqlClientParameter();\r\n");
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$p->name = '{0}';\r\n", dp.Name));
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$p->type = '{0}';\r\n", ValueConvertor.OleDbTypeToPhpMySqlType(dp.Type)));
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$p->value = {0};\r\n", parameters[k]));
                            code.Add("$ps[] = $p;\r\n//\r\n");
                        }
                    }
                    if (outputParams.Count > 0)
                    {
                        StringBuilder sb2 = new StringBuilder();
                        sb2.Append("SELECT ");
                        for (int i = 0; i < outputParams.Count; i++)
                        {
                            if (i > 0)
                            {
                                sb2.Append(",");
                            }
                            sb2.Append(string.Format(CultureInfo.InvariantCulture, "@{0} AS {0} ", outputParams[i]));
                        }
                        string s2 = string.Format(CultureInfo.InvariantCulture, "$qry{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                        code.Add(string.Format(CultureInfo.InvariantCulture, "{0} = \"{1}\";\r\n", s2, sb2.ToString()));
                        code.Add(string.Format(CultureInfo.InvariantCulture, "$this->{0}->ExecuteWithOutputs($sql,{1},$ps,$msql);\r\n", this.Site.Name, s2));
                        for (int i = 0; i < outputParams.Count; i++)
                        {
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$this->{0}->{1}=$this->{0}->outputValues['{1}'];\r\n", this.Site.Name, outputParams[i]));
                        }
                    }
                    else
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture, "$this->{0}->ExecuteNonQuery($sql,$ps,$msql);\r\n", this.Site.Name));
                    }
                    if (!string.IsNullOrEmpty(returnReceiver))
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture,
                                               "{0}=$this->{1}->errorMessage;\r\n", returnReceiver, this.Site.Name));
                    }
                    code.Add(string.Format(CultureInfo.InvariantCulture, "$this->SetServerComponentName('{0}');\r\n", this.Site.Name));
                }
            }
        }