コード例 #1
0
        private static PhpArray Fetch_Assoc(PDODriver driver, IDataReader dr, bool withNum)
        {
            if (dr.Read())
            {
                int      fieldCount = dr.FieldCount;
                PhpArray arr        = new PhpArray(fieldCount * (withNum ? 2 : 1));

                for (int i = 0; i < fieldCount; i++)
                {
                    string fName = dr.GetName(i);
                    object value = driver.ConvertDbValue(dr.GetValue(i), dr.GetDataTypeName(i));

                    arr.Add(fName, value);
                    if (withNum)
                    {
                        arr.Add(i, value);
                    }
                }
                return(arr);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public static void RegisterProvider(PDODriver driver)
        {
            if (driver == null)
                throw new ArgumentNullException();

            string scheme = driver.Scheme;
            if (!m_providers.ContainsKey(scheme))
            {
                m_providers.Add(scheme, driver);
            }
        }
コード例 #3
0
ファイル: PDO.cs プロジェクト: ikvm/Phalanger
        public virtual object __construct(ScriptContext context, object argdsn, [Optional] object argusername, [Optional] object argpassword, [Optional] object argdriver_options)
        {
            string dsn            = PHP.Core.Convert.ObjectToString(argdsn);
            string username       = (argusername == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argusername);
            string password       = (argpassword == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argpassword);
            object driver_options = (argdriver_options == Arg.Default) ? null : argdriver_options;

            if (string.IsNullOrEmpty(dsn))
            {
                throw new ArgumentNullException();
            }

            const string uri = "uri:";

            if (dsn.StartsWith(uri))
            {
                Uri url = new Uri(dsn.Substring(uri.Length));
                throw new NotImplementedException("PDO uri handling");
            }
            string[] items = dsn.Split(new char[] { ':' }, 2);
            if (items.Length == 1)
            {
                //TODO : try to search for aliasing
                throw new NotImplementedException("PDO DSN aliasing");
            }
            if (items.Length == 2)
            {
                string drvName = items[0];
                this.m_driver = PDOLibraryDescriptor.GetProvider(drvName);
                if (this.m_driver == null)
                {
                    PDOException.Throw(context, "Driver not found", null, null, null);
                    return(null);
                }
                this.m_con = this.m_driver.OpenConnection(context, items[1], username, password, driver_options);
            }

            if (this.m_driver == null || this.m_con == null)
            {
                PDOException.Throw(context, "Invalid DSN", null, null, null);
                return(null);
            }

            //Defaults
            this.SetAttributeValueNoCheck(ATTR_AUTOCOMMIT, true);
            this.SetAttributeValueNoCheck(ATTR_DEFAULT_FETCH_MODE, FETCH_BOTH);
            this.SetAttributeValueNoCheck(ATTR_DRIVER_NAME, this.m_driver.Scheme);
            this.SetAttributeValueNoCheck(ATTR_ORACLE_NULLS, NULL_NATURAL);
            this.SetAttributeValueNoCheck(ATTR_STRINGIFY_FETCHES, false);
            this.SetAttributeValueNoCheck(ATTR_TIMEOUT, 30000);

            return(null);
        }
コード例 #4
0
        public static void RegisterProvider(PDODriver driver)
        {
            if (driver == null)
            {
                throw new ArgumentNullException();
            }

            string scheme = driver.Scheme;

            if (!m_providers.ContainsKey(scheme))
            {
                m_providers.Add(scheme, driver);
            }
        }
コード例 #5
0
        private static PhpArray Fetch_Num(PDODriver driver, IDataReader dr)
        {
            if (dr.Read())
            {
                object[] values = new object[dr.FieldCount];
                dr.GetValues(values);

                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = driver.ConvertDbValue(values[i], dr.GetDataTypeName(i));
                }

                return(new PhpArray(values));
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: PDO.cs プロジェクト: hansdude/Phalanger
        public object __construct(ScriptContext context, object argdsn, [Optional] object argusername, [Optional] object argpassword, [Optional] object argdriver_options)
        {
            string dsn = PHP.Core.Convert.ObjectToString(argdsn);
            string username = (argusername == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argusername);
            string password = (argpassword == Arg.Default) ? null : PHP.Core.Convert.ObjectToString(argpassword);
            object driver_options = (argdriver_options == Arg.Default) ? null : argdriver_options;

            if (string.IsNullOrEmpty(dsn))
                throw new ArgumentNullException();
            
            const string uri = "uri:";
            if (dsn.StartsWith(uri))
            {
                Uri url = new Uri(dsn.Substring(uri.Length));
                throw new NotImplementedException("PDO uri handling");
            }
            string[] items = dsn.Split(new char[] { ':' }, 2);
            if (items.Length == 1)
            {
                //TODO : try to search for aliasing
                throw new NotImplementedException("PDO DSN aliasing");
            }
            if (items.Length == 2)
            {
                string drvName = items[0];
                this.m_driver = PDOLibraryDescriptor.GetProvider(drvName);
                if (this.m_driver == null)
                {
                    PDOException.Throw(context, "Driver not found", null, null, null);
                    return null;
                }
                this.m_con = this.m_driver.OpenConnection(context, items[1], username, password, driver_options);
            }

            if (this.m_driver == null || this.m_con == null)
            {
                PDOException.Throw(context, "Invalid DSN", null, null, null);
                return null;
            }

            //Defaults
            this.SetAttributeValueNoCheck(ATTR_AUTOCOMMIT, true);
            this.SetAttributeValueNoCheck(ATTR_DEFAULT_FETCH_MODE, FETCH_BOTH);
            this.SetAttributeValueNoCheck(ATTR_DRIVER_NAME, this.m_driver.Scheme);
            this.SetAttributeValueNoCheck(ATTR_ORACLE_NULLS, NULL_NATURAL);
            this.SetAttributeValueNoCheck(ATTR_STRINGIFY_FETCHES, false);
            this.SetAttributeValueNoCheck(ATTR_TIMEOUT, 30000);

            return null;
        }
コード例 #7
0
ファイル: PDOStatement.cs プロジェクト: hansdude/Phalanger
        private static PhpArray Fetch_Assoc(PDODriver driver, IDataReader dr, bool withNum)
        {
            if (dr.Read())
            {
                int fieldCount = dr.FieldCount;
                PhpArray arr = new PhpArray(fieldCount * (withNum ? 2 : 1));

                for (int i = 0; i < fieldCount; i++)
                {
                    string fName = dr.GetName(i);
                    object value = driver.ConvertDbValue(dr.GetValue(i), dr.GetDataTypeName(i));

                    arr.Add(fName, value);
                    if (withNum)
                        arr.Add(i, value);
                }
                return arr;
            }
            else
            {
                return null;
            }
        }
コード例 #8
0
ファイル: PDOStatement.cs プロジェクト: hansdude/Phalanger
        private static PhpArray Fetch_Num(PDODriver driver, IDataReader dr)
        {
            if (dr.Read())
            {
                object[] values = new object[dr.FieldCount];
                dr.GetValues(values);

                for (int i = 0; i < values.Length; i++)
                    values[i] = driver.ConvertDbValue(values[i], dr.GetDataTypeName(i));
                
                return new PhpArray(values);
            }
            else
            {
                return null;
            }
        }