How to use FTS in SQLite with Monotouch for iOS - sqlite

I'm looking to build an iOS app using Monotouch that has a rather large sqlite db full of text. I need to provide fast searching over this text.
My best solution right now is the FTS module (preferably version 4). I have read that the default instance of sqlite on iOS does not support FTS. If this is true what is the recommended way to build a custom instance of sqlite with Monotouch? Or can this be done at all?
I found this site describing how to accomplish this with xcode, but it is not clear how I would accomplish with Monotouch.
http://longweekendmobile.com/2010/06/16/sqlite-full-text-search-for-iphone-ipadyour-own-sqlite-for-iphone-and-ipad/
Any help is much appreciated!

As I mentioned in my comment above I got this working and since Stack Overflow has really helped me out I wanted to contribute a little to give back to the community.
Disclaimer
This is coming from a .NET developer who is a N00B when it comes to iOS/MacOS/XCode/Monotouch.
Although I tested this out on the iPad simulator I have yet to test it out on an actual device.
End disclaimer
This is a quick how-to compile your own version of SQLite and include it in your Monotouch project with the goal of supporting Full text search.
Step 1:
Download the SQLite amalgamation file.
This includes all of SQLite in one file.
http://www.sqlite.org/download.html
Step 2: Compile the SQLite source in Xcode for iOS.
There is a good walkthrough on how to do this here:
http://pp.hillrippers.ch/blog/2009/08/08/Static+SQLite+Library+with+Unicode+Support+for+the+iPhone/
I followed steps 1-5, skipped #6 since we're not adding additional headers.
Instead of using the compile flags used in the walk through I used:
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_FTS4
There may be others you want to add as well.
These compile flags are added in XCode, to the "Build" tab of the project under "Preprocessor Macros".
Once you've compiled this you should have "mylibrary.a".
Step 3: Include this file in your MonoDevelop project
Add mylibrary.a into MonoDevelop as any other file, right click it and make sure the build action is 'Nothing'.
In your project options select "iPhone Build". You need to add additional mtouch arguments. Add the following
-gcc_flags "-L${ProjectDir} -lmylibrary -force_load ${ProjectDir}/mylibrary.a"
Step 4: Build a c# wrapper
You could probably find a good wrapper to include at this point but I just quickly rolled my own.
For a good tutorial on writing an SQLite wrapper in C# check this page out:
http://www.switchonthecode.com/tutorials/csharp-tutorial-writing-a-dotnet-wrapper-for-sqlite
Because your library is a part of the project you don't need to reference the library by name but instead use the "__Internal" keyword. *NOTE THERE ARE TWO UNDERSCORES IN "__INTERNAL" * (Don't ask me how much time I wasted before I realized that)
Here's a sample of one of mine
[DllImport ("__Internal", EntryPoint="sqlite3_open")]
static extern int sqlite3_open_v2(string filename, out IntPtr db);
There's obviously a lot more to putting together a wrapper, but there's lots of info out there on how to do that. One gotcha is to properly marshal the strings you get returned from SQLite. (see http://blog.gebhardtcomputing.com/2007/11/marshal-utf8-strings-in-net.html for more info on Marshaling)
This was intended to be a quick walkthrough on getting a native library compiled in into MonoDevelop/monotouch, and I hope it helps someone.

You would have to do the same thing, build your own libsqlite3.a, and mangle all the public exports so it doesn't conflict with the libsqlite loaded by the system, and then you would need to modify whatever library you want to bind to sqlite to [DllImport ("__Internal")] instead of libsqlite.

Related

I want to generate boiler plate code in my repository pattern project

As title suggests, I am creating open source project that is in .net core 2.0. here is the architecture of it.
Now, it's working fine with everything including code first, seeders, swagger UI, TDD etc.
But there are many places where I have to add/modify classes when I want to add new Table in Database (see SimpleCRUD.Model > Entities)
So, I think I can reduce that boilerplate code, but I am not sure what is best way to do it.
What I did so far?
I tried to create a windows app, which will check and generate code for new added entity.
What I am trying to achieve?
Is there anyway I can add some kind of code in my current project and that will check after each build? is it feasible? any other suggestion to make it working perfectly?
Reference
I have checked this working in few other frameworks like serenity, asp.net boilerplate etc.
T4 temples can help cut down the boiler plate...
https://dotnetthoughts.net/generate-your-database-entities-using-t4-templates/
You've asked for my help here
I agree with other posters that you might want to look into T4. It sounds like you also want to create an MSBuild task.
I outlined the steps to do this for a different question in post here
You can find my code generators under this folder, CodeGen.SessionProxies
The t4 example can be found here: AppSessionPartials.tt
The MSBuild task can be found here: GenerateSessionProxies.cs
I had it generating a nuget file through the CodeGen.SessionProxies.nuspec. You won't find it on nuget.com; I had a local nuget repository. It would be helpful to you to look at the corresponding install.ps1 to understand how to set the generator up as a msbuild task.
Disclaimer: All of the GitHub links are subject to break if I ever decide to clean up that repo.
Cheers

Prevent Atom Editor from auto creating files

at the moment I try to experiment a little bit with Atom for writing an API documentation with RAML. Everything works fine but one damn thing:
Everytime I type some file paths (e.g. !include schemas/file.schema Atom auto creates the file when I'm not quick enough with typing. So, in some cases I have a hole bunch of file-zombies in my schema folder. That's kind of annoying.
My setup is standard Atom on MacBook, with api-workbench plugin, which includes linter as well. I already had a look at all those settings concerning auto completion - nothing found there. Also, Google doesn't show any hints. Any Tips?
Best regards,
Chris
It looks like this is a defect in the api-workbench package:
Api workbench creates new schemas, while i type their paths. For example below, i can see two-three files created while i type full name:
E.g:
schemas:
- myschema: !include schemas/myschema.json
Will create following files:
schemas/my
schemas/mysche
schemas/myschema
schemas/myschemas.json - this file is existing, i've created it before. all other files are redudant and i have to delete them.
Bug is not reproduced with examples, which i can also include in my document. Having issues while edition RAML 0.8 files.
If you want to help the package maintainers fix the defect, can I suggest you put together a minimal but complete example that reproduces the issue, this will make it easier for them to identify and resolve the issue.

Avalonedit Show syntax error

when I develop a custom language IDE using avalonedit, I encountered a problem. I use regex to check the syntax, and it works as designed. However, I want to show the syntax error with wave text mark. I did search at google, yet the solution is either outdated or not feasible. Any ideas? Thanks ahead.
AvalonEdit does not have this functionality built-in. However it provides all the infrastructure needed to implement it yourself. In the SharpDevelop IDE we have an implementation that should suit your needs.
You'll need some of the code from the SharpDevelop repository (https://github.com/icsharpcode/SharpDevelop/):
TextMarkerService, TextMarker
and its related interfaces and enums.
To make it easier for you, I have created a small sample application:
https://github.com/siegfriedpammer/AvalonEditSamples/tree/master/TextMarkerSample
It uses the AvalonEdit 5 nuget package and contains the classes mentioned above, plus a WPF Window to test it.

Flex application versioning

I'm not referring to CVS or SVN! The thing I would like to do is:
I want to have a version number of the application ex. 0.0.120
I want to see this version number only in the About box or similar
This version number should change everityme I hit debug or release. ex. my version was 0.0.120, after I hit debug in the FlexBuilder, the versionNumber should change to 0.0.121, but If I press Release Build, then the version should change to 0.1.0
The first number changes only when I manually change it
Don't know how is this possible but if you have a tip, let me know. Thanks!
Have a look at this article http://www.igorcosta.org/?p=220. I use this method to keep tract of compilation date of my swfs.
Credits goes to Paul Sivtsov.
I think Flex Builder doesn't have this out of the box, but you can build ant script for that and build your application with it:
http://blog.nirav.name/2008/02/how-to-auto-increament-version-build-id.html
This is typically something you support with frameworks such as maven.
There is actually a maven plugin for flex here
mico's trick is nice though

SQLite with MFC

I want to use SQLite within my MFC application.
for that, i'll create an object whose job is to interact directly with the DB(SQLite) to insulate the rest of the app from the DB code.
can anyone point me to a good tutorial ?
i'll need operations such as (create,delete,insert,update,createdb,dropdb and so on...)
Thanks.
There's a page in the SQLite site that lists many available wrappers - here. The C++ wrapper Daniel mentions in his answer is probably the most common one, though it does not support Unicode and the SQLite dll that comes with it is quite dated. There's a Unicode version of that wrapper here, but it's a bit buggy and requires some more work. It could, however, save you the trouble of writing the whole thing from scratch.
Have a look at this. This was really easy to port to MFC classes, but it will get you started.
http://www.codeproject.com/KB/database/CppSQLite.aspx
Or you can just do #include "sqlite3.h", add sqlite3.lib to your linker and use sqlite3.dll directly with the C api. That's what I did in my MFC app.
And you can even statically link sqlite3 into your app. Download the amalgamation and include it! It adds about 400 k.
Please define your problem more clearly.
sqlite can be coding with c, and you can read the sample in their site.

Resources