BLOB data type

JanKijonkaJanKijonka Jan KijonkaCZMember

How to correctly create BLOB data type for use with a database ? I have created it as:

byte[] blob= { 0,1, 2, 3, 4, 5 };

but it's not working with database.

Posts

  • TG01TG01 Tom Galdos USMember

    That looks like a byte array named "blob", and not a real BLOB (Binary Large Object). Might be helpful if you tell us what you're trying to store and what kind of database you're storing it in.

  • JanKijonkaJanKijonka Jan Kijonka CZMember

    I want to use the android database sqlite library:
    using Android.Database.Sqlite;

    Create table like that:

        sqldb_query = "CREATE TABLE IF NOT EXISTS Info (_id INTEGER PRIMARY KEY AUTOINCREMENT, Place BLOB);";
        sqldb.ExecSQL(sqldb_query);
    

    Store some data into the database table:

        byte[] blob= { 0,1, 2, 3, 4, 5 };
        sqldb_query = "INSERT INTO Info (Place) VALUES (" + blob + ");";
        sqldb.ExecSQL(sqldb_query);
    

    And read data like that:

    void GetCursorView(int iId)
    {
            Android.Database.ICursor sqldb_cursor = sqldb.GetRecordCursorInfo(iId);
                if (sqldb_cursor != null) 
                    {
                            sqldb_cursor.MoveToFirst ();
                                    Id   = sqldb_cursor.GetInt (sqldb_cursor.GetColumnIndex ("_id")),
                                    Place = sqldb_cursor.GetBlob (sqldb_cursor.GetColumnIndex ("Place")),
                    } 
                    else 
                    {
                    shMsg.Text = sqldb.Message;
                    }
    }
    

    By the function:

                                    public Android.Database.ICursor GetRecordCursorInfo(int iId)
                                    {
                                        Android.Database.ICursor sqldb_cursor = null;
                                        try
                                        {
                                            sqldb_query = "SELECT*FROM Info WHERE _id ='" + iId + "';";
                                            sqldb_cursor = sqldb.RawQuery(sqldb_query, null);
                                            if(!(sqldb_cursor != null))
                                            {
                                                sqldb_message = "Record not found";
                                            }
                                        }
                                        catch(SQLiteException ex) 
                                        {
                                            sqldb_message = ex.Message;
                                        }
                                        return sqldb_cursor;
                                    }
    

    Other datatypes (VARCHAR and Int ) are red correctly. But I need to store the data stream only.

Sign In or Register to comment.