Porting From SQL to Realm

1,103 views
Skip to first unread message

Syed Ali Naqi

unread,
Jun 16, 2015, 9:48:46 AM6/16/15
to realm...@googlegroups.com
Hi Guys...
I have a SQL Database File Containing About 24 tables and In total above 24 000 Rows.
I Want to Use that data with Realm in my android application. SO Can Anyone Tell Me How I Can use it....

It Will Be A Great Help....

Tim Oliver

unread,
Jun 16, 2015, 3:00:34 PM6/16/15
to realm...@googlegroups.com
Hi there!

Awesome! Thanks a lot for considering switching to Realm!

SQLite and Realm operate in a rather different manner (SQLite being a relational database, and Realm being an object database), so in order to move your data across, you'll need to manually write some bridging code in order to perform that migration. That being said, it shouldn't be a lot. :)

For each of your 24 tables, you'll need to create a 'RealmObject' subclass containing a list of properties that matches each of the columns in that table.
After that, it should simply be a matter of performing a SQLite query on each table to get everything in there, creating a new RealmObject for each row of that table, copying the data for each row to its corresponding object, and then saving that RealmObject to the realm file on disk. 

Given that you've got 24,000 rows of data, you may need to batch the queries from SQLite to ensure you'r not inadvertently loading everything into memory at once.
If you're migrating from SQLite to Realm in an app already publicly released, you'll need to keep this functionality around so it is performed the first time each user updates their app version.

I hope that helped! Feel free to post here if you need any extra clarification.

Have a nice day!

-Tim

Syed Ali Naqi

unread,
Jun 17, 2015, 4:05:58 PM6/17/15
to realm...@googlegroups.com
Hi!
Thanks for Replying!!!
You Said 
I will have to manually write some bridging code in order to perform that migration.
can u tell me what u meant by that. you see the database has 3 Columns and 24000 rows. It is Available in .SQL file and on MySQL Online Server. Now How do I convert it into Realm. Can u please provide some code because I m new to Realm. It will be a great Help...

Tim Oliver

unread,
Jun 17, 2015, 4:15:56 PM6/17/15
to Syed Ali Naqi, realm...@googlegroups.com
Hi there!

Not at all! :)

Oh dear. Sorry! I might have gotten my assumptions wrong. I thought you were referring to a SQLite file.
When you say '.SQL' file, do you mean a text file with exported SQL INSERT queries in it?

-Tim

--
Tim Oliver



On Wed, Jun 17, 2015 at 8:06 PM UTC, Syed Ali Naqi <syedal...@gmail.com> wrote:
Hi!
Thanks for Replying!!!
You Said
*I will have to manually write some bridging code in order to perform that
migration.*

can u tell me what u meant by that. you see the database has 3 Columns and
24000 rows. It is Available in *.SQL* file and on *MySQL Online Server. *Now

How do I convert it into Realm. Can u please provide some code because I m
new to Realm. It will be a great Help...



On Tue, Jun 16, 2015 at 1:48 PM UTC, Syed Ali Naqi <syedal...@gmail.com> wrote:
Hi Guys...
I have a SQL Database File Containing About 24 tables and In total above 24 000 Rows.
I Want to Use that data with Realm in my android application. SO Can Anyone Tell Me How I Can use it....

It Will Be A Great Help....
--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/06a65cad-5aa6-44ee-9f77-4fc95be3af6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



{#HS:98154339-1330#}

Syed Ali Naqi

unread,
Jun 17, 2015, 4:27:07 PM6/17/15
to realm...@googlegroups.com, he...@realm.io
I create a Database in Microsoft Access and i used Bullzip MS Access to MySQL to convert it to .SQL file. Now, at the moment I have the data in the following format:
  1. Excel File (.xls)
  2. Access Database File (.accdb, .mdb)
  3. SQL file (.sql) 

Tim Oliver

unread,
Jun 17, 2015, 4:33:58 PM6/17/15
to Syed Ali Naqi, realm...@googlegroups.com
Oh wow okay. That's definitely not SQLite then!

What does the inside of the .SQL file look like?
Also, just to confirm. Is this data that you're going to bundle with your app? It's not user-generated data?

Thanks a lot!

-Tim

--
Tim Oliver
{#HS:98154339-1330#}

Syed Ali Naqi

unread,
Jun 17, 2015, 4:45:59 PM6/17/15
to realm...@googlegroups.com, he...@realm.io
Hmmm.. Well .SQL File Contains 24 Tables each with 3 columns. And Yes The Data Is Not User Generated. It is going to be bundled with the app...

Tim Oliver

unread,
Jun 17, 2015, 6:35:26 PM6/17/15
to Syed Ali Naqi, realm...@googlegroups.com
Ahhh okay.

If that's the case, then sadly, there's not going to be a really easy way to covert it.

At the moment, I would recommend creating a separate Android project, and then using that project to format your data and save it into a new realm file.

Since you you have the data as an Excel spreadsheet, you should be able to export it as a .CSV file, and then use Java to separate out each column, for each row using simple array splitting.

It's a manual process, but hopefully it won't take too long, and thankfully, you only need to do it once.

I hope that helped. We're always looking at ways to make Realm better, so I've added converting SQL files to realm files as a feature on our task list.

Good luck!

-Tim


--
Tim Oliver
{#HS:98154339-1330#}

Syed Ali Naqi

unread,
Jun 18, 2015, 7:47:33 AM6/18/15
to realm...@googlegroups.com
Well Thanks. I will try that. And again Thanks for Helping me... You are the best.

Tim Oliver

unread,
Jun 18, 2015, 6:47:02 PM6/18/15
to Syed Ali Naqi, realm...@googlegroups.com
Not at all! Sorry I couldn't help further.

Ah, thank you very much! Good luck!

-Tim

--
Tim Oliver



On Thu, Jun 18, 2015 at 11:47 AM UTC, Syed Ali Naqi <syedal...@gmail.com> wrote:
Well Thanks. I will try that. And again Thanks for Helping me... You are
the best.



{#HS:98154339-1330#}
Reply all
Reply to author
Forward
0 new messages