save received sample to sqlite database

3 posts / 0 new
Last post
Offline
Last seen: 7 years 6 months ago
Joined: 04/20/2017
Posts: 1
save received sample to sqlite database

I try to save received sample to sqlite database.

Please refer below Csharp code:

public void createDB()
{
    SQLiteConnection.CreateFile("sqlite.dat");
    SQLiteConnection dbConnection = new SQLiteConnection("Data Source=sqlite.dat;Version=3;");
    dbConnection.Open();

    string sql = "create table Data (data BLOB)";
    SQLiteCommand command = new SQLiteCommand(sql, dbConnection);
    command.ExecuteNonQuery();

    dbConnection.Close();
}

public void insertData(byte[] data)
{
    SQLiteConnection dbConnection = new SQLiteConnection("Data Source=sqlite.dat;Version=3;");
    dbConnection.Open();

    string sql = "insert into Data (data) values (@data)";
    SQLiteCommand command = new SQLiteCommand(sql, dbConnection);
    command.Parameters.Add("@data", DbType.Binary, data.Length).Value = data;
    command.ExecuteNonQuery();

    dbConnection.Close();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

public override void on_data_available(DDS.DataReader reader)
{
    reader.take(_dataSeq, ... );
    processData(_dataSeq.get_at(i));
}


private void processData(Foo instance)
{
    byte[] data = null;
    uint length = 0;

    FooTypeSupport.serialize_data_to_cdr_buffer(data, ref length, instance);

    insertData(data);
}

I tried this, but error occurred.

The serialize_data_to_cdr_buffer() does not copy instance to data.

So data still null.

 

Then I tried this:

private byte[] serializeData(Foo instance)
{
    BinaryFormatter bf = new BinaryFormatter();

    using (MemoryStream ms = new MemoryStream())
    {
        bf.Serialize(ms, instance);
        return ms.ToArray();
    }
}

Naturally a SerializationException error occurred.

 

Please Help!

 

Organization:
Offline
Last seen: 11 months 1 week ago
Joined: 02/11/2016
Posts: 144

Hey,

Have you tried passing a Byte[] instead of a byte[]?

 

 

gianpiero's picture
Offline
Last seen: 11 months 1 week ago
Joined: 06/02/2010
Posts: 177

Hello,

I am not sure what are you trying to do, so maybe what I am about to say doesn't apply, but: did you try recording service: https://community.rti.com/static/documentation/connext-dds/5.2.3/doc/manuals/recording_service/RTI_Recording_Service_GettingStarted.pdf

Best,
  Gianpiero