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. Database & SysAdmin
  3. Database
  4. Counting records in a dBase III file

Counting records in a dBase III file

Scheduled Pinned Locked Moved Database
questioncssdatabasedebuggingjson
6 Posts 3 Posters 0 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.
  • D Offline
    D Offline
    David Crow
    wrote on last edited by
    #1

    I'm interacting with a dBase III file using Microsoft's ODBC dBase driver. I can create a CRecordset object and iterate through the table just fine (populating controls on a dialog and such). When I went to count the rows/records in the table using SELECT COUNT(*) FROM ACTY, the code kept throwing exceptions. Based on the error messages in the debug window, I suspected column 1 (type Date) was at fault. I managed to insert another column into the table of type Text (Numeric type also works). The COUNTing code now works fine. My question is, why? I could iterate the table just fine when the first column was a Date, but not count the rows. Is there a rule that states what types can be in the first column and what types cannot when counting? As there are hundreds of these database files in use, injecting a "dummy" column into them just for the sake of counting is not a solution. [edit] I was able to create a dBase 5 table and it exhibited the same behavior. When I added the extra column, however, no exceptions and counting worked fine. [/edit] [edit2] I was able to successfully count records in the table using the ODBC API (e.g., SQLDriverConnect(), SQLExecDirect(), SQLGetData()) rather than CDatabase and CRecordset. [/edit2]

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

    L F 3 Replies Last reply
    0
    • D David Crow

      I'm interacting with a dBase III file using Microsoft's ODBC dBase driver. I can create a CRecordset object and iterate through the table just fine (populating controls on a dialog and such). When I went to count the rows/records in the table using SELECT COUNT(*) FROM ACTY, the code kept throwing exceptions. Based on the error messages in the debug window, I suspected column 1 (type Date) was at fault. I managed to insert another column into the table of type Text (Numeric type also works). The COUNTing code now works fine. My question is, why? I could iterate the table just fine when the first column was a Date, but not count the rows. Is there a rule that states what types can be in the first column and what types cannot when counting? As there are hundreds of these database files in use, injecting a "dummy" column into them just for the sake of counting is not a solution. [edit] I was able to create a dBase 5 table and it exhibited the same behavior. When I added the extra column, however, no exceptions and counting worked fine. [/edit] [edit2] I was able to successfully count records in the table using the ODBC API (e.g., SQLDriverConnect(), SQLExecDirect(), SQLGetData()) rather than CDatabase and CRecordset. [/edit2]

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm surprised at your findings. The COUNT function shouldn't care what columns are on the table or what datatype they're made of. May be a bug with the driver? If I were you, I would suspected that USER was a keyword and would have tried to rename the table and see if it worked instead of adding a new column.

      D 1 Reply Last reply
      0
      • D David Crow

        I'm interacting with a dBase III file using Microsoft's ODBC dBase driver. I can create a CRecordset object and iterate through the table just fine (populating controls on a dialog and such). When I went to count the rows/records in the table using SELECT COUNT(*) FROM ACTY, the code kept throwing exceptions. Based on the error messages in the debug window, I suspected column 1 (type Date) was at fault. I managed to insert another column into the table of type Text (Numeric type also works). The COUNTing code now works fine. My question is, why? I could iterate the table just fine when the first column was a Date, but not count the rows. Is there a rule that states what types can be in the first column and what types cannot when counting? As there are hundreds of these database files in use, injecting a "dummy" column into them just for the sake of counting is not a solution. [edit] I was able to create a dBase 5 table and it exhibited the same behavior. When I added the extra column, however, no exceptions and counting worked fine. [/edit] [edit2] I was able to successfully count records in the table using the ODBC API (e.g., SQLDriverConnect(), SQLExecDirect(), SQLGetData()) rather than CDatabase and CRecordset. [/edit2]

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        DavidCrow wrote:

        dBase III

        :wtf: I do hope that you have a copy of that database is a more recent format?

        Bastard Programmer from Hell :suss:

        D 1 Reply Last reply
        0
        • L Lost User

          DavidCrow wrote:

          dBase III

          :wtf: I do hope that you have a copy of that database is a more recent format?

          Bastard Programmer from Hell :suss:

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          If I can't operate on it directly, I will consider converting it. Given the constraints on the client side, that would be a last resort.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          1 Reply Last reply
          0
          • L Lost User

            I'm surprised at your findings. The COUNT function shouldn't care what columns are on the table or what datatype they're made of. May be a bug with the driver? If I were you, I would suspected that USER was a keyword and would have tried to rename the table and see if it worked instead of adding a new column.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Shameel wrote:

            I'm surprised at your findings. The COUNT function shouldn't care what columns are on the table or what datatype they're made of. May be a bug with the driver?

            I'm not familar enough with it one way or the other. If you step through the code, however, the columns are definitely being bound (in the set's DoFieldExchange() method).

            Shameel wrote:

            If I were you, I would suspected that USER was a keyword and would have tried to rename the table and see if it worked instead of adding a new column.

            There are actually two tables: ACTY and USER. The USER table works fine with no changes, both iterating and counting.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            1 Reply Last reply
            0
            • D David Crow

              I'm interacting with a dBase III file using Microsoft's ODBC dBase driver. I can create a CRecordset object and iterate through the table just fine (populating controls on a dialog and such). When I went to count the rows/records in the table using SELECT COUNT(*) FROM ACTY, the code kept throwing exceptions. Based on the error messages in the debug window, I suspected column 1 (type Date) was at fault. I managed to insert another column into the table of type Text (Numeric type also works). The COUNTing code now works fine. My question is, why? I could iterate the table just fine when the first column was a Date, but not count the rows. Is there a rule that states what types can be in the first column and what types cannot when counting? As there are hundreds of these database files in use, injecting a "dummy" column into them just for the sake of counting is not a solution. [edit] I was able to create a dBase 5 table and it exhibited the same behavior. When I added the extra column, however, no exceptions and counting worked fine. [/edit] [edit2] I was able to successfully count records in the table using the ODBC API (e.g., SQLDriverConnect(), SQLExecDirect(), SQLGetData()) rather than CDatabase and CRecordset. [/edit2]

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              F Offline
              F Offline
              foxyland
              wrote on last edited by
              #6

              I suggest you use Microsoft Visual Foxpro ODBC Driver[^]. It has full compatility with other xBase product (including dBase III+), it is newer, and it has much better handling with SQL queries. hth, foxyland

              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