Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Windows Phone 8 SQLite Question

Windows Phone 8 SQLite Question

Scheduled Pinned Locked Moved Mobile
questionsqlite
12 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tony Palumbo
    wrote on last edited by
    #1

    How do I add method for last_insert_rowid I added a record to the table. As soon as it is entered I want to get the rowed that SQLite gave to it. How can I accomplish this?

    P 1 Reply Last reply
    0
    • T Tony Palumbo

      How do I add method for last_insert_rowid I added a record to the table. As soon as it is entered I want to get the rowed that SQLite gave to it. How can I accomplish this?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You should be able to use last_insert_rowid for the last row id that was inserted for that connection. Basically, inside the same connection, issue a separate select command:

      SELECT last_insert_rowid

      I was brought up to respect my elders. I don't respect many people nowadays.
      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      T 1 Reply Last reply
      0
      • P Pete OHanlon

        You should be able to use last_insert_rowid for the last row id that was inserted for that connection. Basically, inside the same connection, issue a separate select command:

        SELECT last_insert_rowid

        I was brought up to respect my elders. I don't respect many people nowadays.
        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        T Offline
        T Offline
        Tony Palumbo
        wrote on last edited by
        #3

        Hi Pete, I tried this and it wont let me compile. I don't know the correct syntax. There is not much out there for WP8 SQLite

        string query = "select last_insert_rowid() as id from myTable";

        using (var db = new SQLite.SQLiteConnection(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "SM.db"), true))
        {

        SQLite.SQLiteCommand cmd = new SQLite.SQLiteCommand(db);
        var result = cmd.ExecuteNonQuery();
        }

        P S 2 Replies Last reply
        0
        • T Tony Palumbo

          Hi Pete, I tried this and it wont let me compile. I don't know the correct syntax. There is not much out there for WP8 SQLite

          string query = "select last_insert_rowid() as id from myTable";

          using (var db = new SQLite.SQLiteConnection(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "SM.db"), true))
          {

          SQLite.SQLiteCommand cmd = new SQLite.SQLiteCommand(db);
          var result = cmd.ExecuteNonQuery();
          }

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          No. Only select last_insert_rowid();. You don't need the rest. There's a reaaon I didn't include it in my answer there.

          I was brought up to respect my elders. I don't respect many people nowadays.
          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          T 2 Replies Last reply
          0
          • P Pete OHanlon

            No. Only select last_insert_rowid();. You don't need the rest. There's a reaaon I didn't include it in my answer there.

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            T Offline
            T Offline
            Tony Palumbo
            wrote on last edited by
            #5

            I tried that and I get this error

            SQLite.SQLiteException: Misuse

            1 Reply Last reply
            0
            • P Pete OHanlon

              No. Only select last_insert_rowid();. You don't need the rest. There's a reaaon I didn't include it in my answer there.

              I was brought up to respect my elders. I don't respect many people nowadays.
              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              T Offline
              T Offline
              Tony Palumbo
              wrote on last edited by
              #6

              I tried this also and the error is "Row" SQLite.SQLiteCommand cmd = new SQLite.SQLiteCommand(db); cmd.CommandText = query.ToString(); var result2 = cmd.ExecuteNonQuery();

              P 1 Reply Last reply
              0
              • T Tony Palumbo

                I tried this also and the error is "Row" SQLite.SQLiteCommand cmd = new SQLite.SQLiteCommand(db); cmd.CommandText = query.ToString(); var result2 = cmd.ExecuteNonQuery();

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                If you're trying to retrieve the record, use ExecuteScalar, not ExecuteNonQuery.

                I was brought up to respect my elders. I don't respect many people nowadays.
                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                T 1 Reply Last reply
                0
                • P Pete OHanlon

                  If you're trying to retrieve the record, use ExecuteScalar, not ExecuteNonQuery.

                  I was brought up to respect my elders. I don't respect many people nowadays.
                  CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                  T Offline
                  T Offline
                  Tony Palumbo
                  wrote on last edited by
                  #8

                  Ok, So what is the syntax for that? cmd.ExecuteScalar< ? >; Sorry, I just don't know SQLite

                  P 1 Reply Last reply
                  0
                  • T Tony Palumbo

                    Ok, So what is the syntax for that? cmd.ExecuteScalar< ? >; Sorry, I just don't know SQLite

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #9

                    It should just be something like:

                    private int GetLastRowId(SQLLite.SQLLiteConnection connection)
                    {
                    SQLLite.SQLLiteCommand cmd = new (connection);
                    cmd.CommandText = "SELECT last_insert_rowid";
                    object rowId = cmd.ExecuteScalar();
                    return Convert.ToInt32(rowId);
                    }

                    I was brought up to respect my elders. I don't respect many people nowadays.
                    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                    T 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      It should just be something like:

                      private int GetLastRowId(SQLLite.SQLLiteConnection connection)
                      {
                      SQLLite.SQLLiteCommand cmd = new (connection);
                      cmd.CommandText = "SELECT last_insert_rowid";
                      object rowId = cmd.ExecuteScalar();
                      return Convert.ToInt32(rowId);
                      }

                      I was brought up to respect my elders. I don't respect many people nowadays.
                      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                      T Offline
                      T Offline
                      Tony Palumbo
                      wrote on last edited by
                      #10

                      Thanks Pete

                      P 1 Reply Last reply
                      0
                      • T Tony Palumbo

                        Thanks Pete

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #11

                        No problem.

                        I was brought up to respect my elders. I don't respect many people nowadays.
                        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                        1 Reply Last reply
                        0
                        • T Tony Palumbo

                          Hi Pete, I tried this and it wont let me compile. I don't know the correct syntax. There is not much out there for WP8 SQLite

                          string query = "select last_insert_rowid() as id from myTable";

                          using (var db = new SQLite.SQLiteConnection(System.IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, "SM.db"), true))
                          {

                          SQLite.SQLiteCommand cmd = new SQLite.SQLiteCommand(db);
                          var result = cmd.ExecuteNonQuery();
                          }

                          S Offline
                          S Offline
                          Sanjay22Tomar
                          wrote on last edited by
                          #12

                          Cursor cursor = getReadableDatabase().
                          rawQuery("select * from todo where _id = ?", new String[] { id });

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups