Ejemplo n.º 1
0
        /// <summary>
        /// Gets a PHP object whose properties describes the last fetched field.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <returns>The PHP object.</returns>
        public static object mysql_fetch_field(PhpResource resultHandle)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            return(FetchFieldInternal(result, result.FetchNextField()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a type of a specified column (field) in a result.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="fieldIndex">Column index.</param>
        /// <returns>MySQL type translated to PHP terminology.</returns>
        /// <remarks>
        /// Possible values are: "string", "int", "real", "year", "date", "timestamp", "datetime", "time",
        /// "set", "enum", "blob", "bit" (Phalanger specific), "NULL", and "unknown".
        /// </remarks>
        public static string mysql_field_type(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            return(result.GetPhpFieldType(fieldIndex));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a length of a specified column (field) in a result.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="fieldIndex">Column index.</param>
        /// <returns>Length of the column or a -1 on failure (invalid resource or column index).</returns>
        public static int mysql_field_len(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(-1);
            }

            return(result.GetFieldLength(fieldIndex));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get number of rows in a specified result.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <returns>Number of rows in the specified result or 0 if the result resource is invalid.</returns>
        public static int mysql_num_rows(PhpResource resultHandle)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(0);
            }

            return(result.RowCount);
        }
Ejemplo n.º 5
0
        public static object mysql_fetch_object(PhpResource resultHandle)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            return(result.FetchStdClass());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets a PHP object whose properties describes a specified field.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="fieldIndex">Field index.</param>
        /// <returns>The PHP object.</returns>
        public static stdClass mysql_fetch_field(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            return(FetchFieldInternal(result, fieldIndex));
        }
Ejemplo n.º 7
0
        public static string mysql_field_table(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null || !result.CheckFieldIndex(fieldIndex))
            {
                return(null);
            }

            return(result.GetColumnSchema(fieldIndex).BaseTableName);
        }
Ejemplo n.º 8
0
        static stdClass FetchFieldInternal(MySqlResultResource /*!*/ result, int fieldIndex)
        {
            if (!result.CheckFieldIndex(fieldIndex))
            {
                return(null);
            }

            //DataRow info = result.GetSchemaRowInfo(fieldIndex);
            //if (info == null) return null;

            var col      = result.GetColumnSchema(fieldIndex);
            var php_type = result.GetPhpFieldType(fieldIndex);

            //PhpMyDbResult.FieldCustomData data = ((PhpMyDbResult.FieldCustomData[])result.GetRowCustomData())[fieldIndex];
            //ColumnFlags flags = data.Flags;//result.GetFieldFlags(fieldIndex);

            //name - column name
            //table - name of the table the column belongs to, which is the alias name if one is defined
            //max_length - maximum length of the column
            //not_null - 1 if the column cannot be NULL
            //primary_key - 1 if the column is a primary key
            //unique_key - 1 if the column is a unique key
            //multiple_key - 1 if the column is a non - unique key
            //numeric - 1 if the column is numeric
            //blob - 1 if the column is a BLOB
            //type - the type of the column
            //unsigned - 1 if the column is unsigned
            //zerofill - 1 if the column is zero - filled

            // create an array of runtime fields with specified capacity:
            var objFields = new PhpArray(16)
            {
                { "name", col.ColumnName },
                //{ "orgname", col.BaseColumnName },
                { "table", col.BaseTableName ?? string.Empty },
                //{ "def", "" }, // undocumented
                //{ "db", col.BaseSchemaName },
                //{ "catalog", col.BaseCatalogName },
                //{ "max_length", /*result.GetFieldLength(fieldIndex)*/data.ColumnSize },
                //{ "length", col.ColumnSize.GetValueOrDefault() },
                { "not_null", col.AllowDBNull.GetValueOrDefault() == false },
                { "primary_key", col.IsKey.GetValueOrDefault() ? 1 : 0 },
                //{ "multiple_key", ((flags & ColumnFlags.MULTIPLE_KEY) != 0) /*((bool)info["IsMultipleKey"])*/ ? 1 : 0 },
                { "unique_key", col.IsUnique.GetValueOrDefault() ? 1 : 0 },
                { "numeric", col.IsNumeric() ? 1 : 0 },
                { "blob", col.IsBlob() ? 1 : 0 },
                { "type", php_type },
                { "unsigned", col.IsUnsigned() ? 1 : 0 }, // ((flags & ColumnFlags.UNSIGNED) != 0) /*((bool)info["IsUnsigned"])*/ ? 1 : 0 },
                //{ "zerofill", ((flags & ColumnFlags.ZERO_FILL) != 0) /*((bool)info["ZeroFill"])*/ ? 1 : 0 },
            };

            // create new stdClass with runtime fields initialized above:
            return(objFields.AsStdClass());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Releases a resource represening a query result.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <returns><B>true</B> on success, <B>false</B> on failure (invalid resource).</returns>
        public static bool mysql_free_result(PhpResource resultHandle)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result != null)
            {
                result.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets a base table of a specified field.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="fieldIndex">Field index.</param>
        /// <returns>Name of the base table of the field.</returns>
        public static string mysql_field_table(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            //var info = result.GetSchemaRowInfo(fieldIndex);
            //if (info == null) return null;

            //return (string)info["BaseTableName"];
            throw new NotImplementedException();
        }
Ejemplo n.º 11
0
        public static PhpArray mysql_fetch_array(PhpResource resultHandle, QueryResultKeys resultType = QueryResultKeys.Both)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            switch (resultType)
            {
            case QueryResultKeys.ColumnNames: return(result.FetchArray(false, true));

            case QueryResultKeys.Numbers: return(result.FetchArray(true, false));

            case QueryResultKeys.Both: return(result.FetchArray(true, true));
            }

            return(null);
        }
Ejemplo n.º 12
0
        static stdClass FetchFieldInternal(MySqlResultResource /*!*/ result, int fieldIndex)
        {
            if (!result.CheckFieldIndex(fieldIndex))
            {
                return(null);
            }

            //DataRow info = result.GetSchemaRowInfo(fieldIndex);
            //if (info == null) return null;

            Debug.Assert(result.GetRowCustomData() != null);

            string php_type = result.GetPhpFieldType(fieldIndex);
            //PhpMyDbResult.FieldCustomData data = ((PhpMyDbResult.FieldCustomData[])result.GetRowCustomData())[fieldIndex];
            //ColumnFlags flags = data.Flags;//result.GetFieldFlags(fieldIndex);

            // create an array of runtime fields with specified capacity:
            var objFields = new PhpArray(13);

            // add fields into the hastable directly:
            // no duplicity check, since array is already valid
            objFields.Add("name", result.GetFieldName(fieldIndex));
            //objFields.Add("table", (/*info["BaseTableName"] as string*/data.RealTableName) ?? string.Empty);
            //objFields.Add("def", ""); // TODO
            //objFields.Add("max_length", /*result.GetFieldLength(fieldIndex)*/data.ColumnSize);

            //objFields.Add("not_null", ((flags & ColumnFlags.NOT_NULL) != 0) /*(!(bool)info["AllowDBNull"])*/ ? 1 : 0);
            //objFields.Add("primary_key", ((flags & ColumnFlags.PRIMARY_KEY) != 0) /*((bool)info["IsKey"])*/ ? 1 : 0);
            //objFields.Add("multiple_key", ((flags & ColumnFlags.MULTIPLE_KEY) != 0) /*((bool)info["IsMultipleKey"])*/ ? 1 : 0);
            //objFields.Add("unique_key", ((flags & ColumnFlags.UNIQUE_KEY) != 0) /*((bool)info["IsUnique"])*/ ? 1 : 0);
            //objFields.Add("numeric", result.IsNumericType(php_type) ? 1 : 0);
            //objFields.Add("blob", ((flags & ColumnFlags.BLOB) != 0) /*((bool)info["IsBlob"])*/ ? 1 : 0);

            //objFields.Add("type", php_type);
            //objFields.Add("unsigned", ((flags & ColumnFlags.UNSIGNED) != 0) /*((bool)info["IsUnsigned"])*/ ? 1 : 0);
            //objFields.Add("zerofill", ((flags & ColumnFlags.ZERO_FILL) != 0) /*((bool)info["ZeroFill"])*/ ? 1 : 0);

            // create new stdClass with runtime fields initialized above:
            return((stdClass)objFields.ToClass());
        }
Ejemplo n.º 13
0
        public static PhpArray mysql_fetch_lengths(PhpResource resultHandle)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(null);
            }

            int row_index = result.CurrentRowIndex;

            if (row_index < 0)
            {
                return(null);
            }

            var array = new PhpArray(result.FieldCount);

            for (int i = 0; i < result.FieldCount; i++)
            {
                object value = result.GetFieldValue(row_index, i);

                if (value is PhpString phpstr)
                {
                    array.Add(phpstr.Length);
                }
                else if (value != null)
                {
                    array.Add(value.ToString().Length);
                }
                else
                {
                    array.Add(0);
                }
            }

            return(array);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets the result resource's current row index.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="rowIndex">New row index.</param>
        /// <returns><B>true</B> on success, <B>false</B> on failure (invalid resource or row index).</returns>
        public static bool mysql_data_seek(PhpResource resultHandle, int rowIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            return(result != null && result.SeekRow(rowIndex));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets the result resource's current column (field) offset.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="fieldOffset">New column offset.</param>
        /// <returns><B>true</B> on success, <B>false</B> on failure (invalid resource or column offset).</returns>
        public static bool mysql_field_seek(PhpResource resultHandle, int fieldOffset)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            return(result != null && result.SeekField(fieldOffset));
        }
Ejemplo n.º 16
0
        public static string mysql_field_flags(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null || !result.CheckFieldIndex(fieldIndex))
            {
                return(null);
            }

            var col = result.GetColumnSchema(fieldIndex);
            //ColumnFlags flags = result.GetFieldFlags(fieldIndex);

            var flags = new List <string>(16);

            if (col.AllowDBNull.GetValueOrDefault() == false)
            {
                flags.Add("not_null");
            }

            if (col.IsKey.GetValueOrDefault())
            {
                flags.Add("primary_key");
            }

            if (col.IsUnique.GetValueOrDefault())
            {
                flags.Add("unique_key");
            }

            //if ((flags & ColumnFlags.MULTIPLE_KEY) != 0)
            //    flags.Add("multiple_key");

            if (col.IsBlob())
            {
                flags.Add("blob");
            }

            if (col.IsUnsigned())
            {
                flags.Add("unsigned");
            }

            //if ((flags & ColumnFlags.ZERO_FILL) != 0)
            //    flags.Add("zerofill");

            if (col.ProviderType == MySqlDbType.Binary || col.ProviderType == MySqlDbType.VarBinary)
            {
                flags.Add("binary");
            }

            if (col.ProviderType == MySqlDbType.Enum)
            {
                flags.Add("enum");
            }

            if (col.ProviderType == MySqlDbType.Set)
            {
                flags.Add("set");
            }

            if (col.IsAutoIncrement.GetValueOrDefault())
            {
                flags.Add("auto_increment");
            }

            if (col.ProviderType == MySqlDbType.Timestamp)
            {
                flags.Add("timestamp");
            }

            //
            return(string.Join(" ", flags));
        }