locked
bulk run sql query from file in sqlite async in winrt c#

    Question

  • i want to run bulk create and insert sql query from a file in sqlite, i am created a file like this:

    byte[] data = Convert.FromBase64String(Base64Text);
    StorageFile ZipFile = await Windows.Storage.KnownFolders.DocumentsLibrary.CreateFileAsync("GloWin.zip");
    await FileIO.WriteBytesAsync(ZipFile, data);

    with reference of: "http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a543a425-2b4a-4ff4-a173-bb7c97c7c33d/create-file-from-encoded-base64-string-winrt-windows8?forum=winappswithcsharp"

    Now i got a file which contains thousands line of sql query, i want to execute all the query from file in my sqlite(async) DB.

    I tried something like:

    public static async Task<string> ReadZFile()
            {
                StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    
                try
                {
                    StorageFile sampleFile = await storageFolder.GetFileAsync("Global.dmp");
                    IRandomAccessStream readStream = await sampleFile.OpenAsync(FileAccessMode.Read);
                    IInputStream inputStream = readStream.GetInputStreamAt(0);
                    DataReader dataReader = new DataReader(inputStream);
                    uint numBytesLoaded = await dataReader.LoadAsync((uint)readStream.Size);
                    return getMessage1 = dataReader.ReadString(numBytesLoaded);
                }
    
                catch (FileNotFoundException ex)
                {
                    return getMessage = ex.Message.ToString();
                    throw;
                }
            }

    but i don't know exactly what to do for this, please guide me.



    • Edited by nkd108 Tuesday, March 25, 2014 12:57 PM
    Tuesday, March 25, 2014 7:44 AM

Answers

  • i can run query multiple query one by one by passing query to this function
    public static string getQXn(string Squery)
            {
                var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NMFS.db3");
                using (var db = new SQLite.SQLiteConnection(dbpath))
                {
                    db.Execute(Squery);
                    return "sucess";
                }
            }
    thanks
    • Marked as answer by nkd108 Friday, March 28, 2014 8:08 AM
    Friday, March 28, 2014 8:08 AM

All replies

  • Not knowing SQLite, I expect that you just extract the commands from the file and run them one by one. Use fileIO class to get the information from the file:
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileio.aspx

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, March 25, 2014 7:05 PM
    Moderator
  • through this i can read file but how can i execute sql statements(multiple sql query one by one) in async mode. i followed this to create my project : http://blog.thomaslebrun.net/2012/10/windows-8-using-sqlite-in-your-windows-store-application/#.UvHUrLTPXt0.


    • Edited by nkd108 Tuesday, March 25, 2014 7:19 PM
    Tuesday, March 25, 2014 7:18 PM
  • You should ask on a SQLite alias.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, March 26, 2014 2:17 AM
    Moderator
  • can you tell me is there any Sqlite forum available in msdn? because i couldn't found in list
    Wednesday, March 26, 2014 12:50 PM
  • i can run query multiple query one by one by passing query to this function
    public static string getQXn(string Squery)
            {
                var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NMFS.db3");
                using (var db = new SQLite.SQLiteConnection(dbpath))
                {
                    db.Execute(Squery);
                    return "sucess";
                }
            }
    thanks
    • Marked as answer by nkd108 Friday, March 28, 2014 8:08 AM
    Friday, March 28, 2014 8:08 AM