Exemplo n.º 1
0
        /// <summary>
        /// Gets a contents of a specified cell from a specified query result resource.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="row">Row index.</param>
        /// <param name="field">Column (field) integer index or string name.</param>
        /// <returns>The value of the cell or a <B>null</B> reference (<B>false</B> in PHP) on failure (invalid resource or row/field index/name).</returns>
        /// <remarks>
        /// Result is affected by run-time quoting.
        /// </remarks>
        public static PhpValue mysql_result(PhpResource resultHandle, int row, PhpValue field)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(PhpValue.False);
            }

            string field_name;
            object field_value;

            if (field.IsEmpty)
            {
                field_value = result.GetFieldValue(row, result.CurrentFieldIndex);
            }
            else if ((field_name = PhpVariable.AsString(field)) != null)
            {
                field_value = result.GetFieldValue(row, field_name);
            }
            else
            {
                field_value = result.GetFieldValue(row, (int)field.ToLong());
            }

            return(PhpValue.FromClr(field_value)); // TODO: Core.Convert.Quote(field_value, context);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a contents of a specified cell from a specified query result resource.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="row">Row index.</param>
        /// <param name="field">Column (field) integer index or string name.</param>
        /// <returns>The value of the cell or a <B>null</B> reference (<B>false</B> in PHP) on failure (invalid resource or row/field index/name).</returns>
        /// <remarks>
        /// Result is affected by run-time quoting.
        /// </remarks>
        public static PhpValue mysql_result(PhpResource resultHandle, int row, PhpValue field = default)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

            if (result == null)
            {
                return(PhpValue.False);
            }

            object field_value;

            if (!Operators.IsSet(field))
            {
                field_value = result.GetFieldValue(row, result.CurrentFieldIndex);
            }
            else if (field.IsString(out var field_name))
            {
                field_value = result.GetFieldValue(row, field_name);
            }
            else
            {
                field_value = result.GetFieldValue(row, (int)field);
            }

            return(PhpValue.FromClr(field_value)); // TODO: Core.Convert.Quote(field_value, context);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets flags of a specified field.
        /// </summary>
        /// <param name="resultHandle">Query result resource.</param>
        /// <param name="fieldIndex">Field index.</param>
        /// <returns>Flags of the field.</returns>
        public static string mysql_field_flags(PhpResource resultHandle, int fieldIndex)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

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

            throw new NotImplementedException();

            //ColumnFlags flags = result.GetFieldFlags(fieldIndex);
            //string type_name = result.GetPhpFieldType(fieldIndex);

            //StringBuilder str_fields = new StringBuilder();

            //if ((flags & ColumnFlags.NOT_NULL) != 0)
            //    str_fields.Append("not_null ");

            //if ((flags & ColumnFlags.PRIMARY_KEY) != 0)
            //    str_fields.Append("primary_key ");

            //if ((flags & ColumnFlags.UNIQUE_KEY) != 0)
            //    str_fields.Append("unique_key ");

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

            //if ((flags & ColumnFlags.BLOB) != 0)
            //    str_fields.Append("blob ");

            //if ((flags & ColumnFlags.UNSIGNED) != 0)
            //    str_fields.Append("unsigned ");

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

            //if ((flags & ColumnFlags.BINARY) != 0)
            //    str_fields.Append("binary ");

            //if ((flags & ColumnFlags.ENUM) != 0)
            //    str_fields.Append("enum ");

            //if ((flags & ColumnFlags.SET) != 0)
            //    str_fields.Append("set ");

            //if ((flags & ColumnFlags.AUTO_INCREMENT) != 0)
            //    str_fields.Append("auto_increment ");

            //if ((flags & ColumnFlags.TIMESTAMP) != 0)
            //    str_fields.Append("timestamp ");

            //if (str_fields.Length > 0)
            //    str_fields.Length = str_fields.Length - 1;

            //return str_fields.ToString();
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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()));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public static object mysql_fetch_object(PhpResource resultHandle)
        {
            var result = MySqlResultResource.ValidResult(resultHandle);

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

            return(result.FetchStdClass());
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 16
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));
        }
Exemplo n.º 17
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));
        }