SQLite Forum

sqlite3_exec: the 3rd argument
Login
>Are you attempting to "hang onto a pointer" after your callback returns? 

No.

My SQL is:

>select * from employees; //chinook.db; table **employees** has 15 columns and 8 rows

My callback function gets the data correctly <i>to start with, as follows (showing first row below)</i> 

|**names**                 |**values**                            |
|{string[15]}          |{string[15]}                      |
|    [0]: "EmployeeId" |    [0]: "1"                      |
|    [1]: "LastName"   |    [1]: "Adams"                  |
|    [2]: "FirstName"  |    [2]: "Andrew"                 |
|    [3]: "Title"      |    [3]: "General Manager"        |
|    [4]: "ReportsTo"  |    [4]: null                     |
|    [5]: "BirthDate"  |    [5]: "1962-02-18 00:00:00"    |
|    [6]: "HireDate"   |    [6]: "2002-08-14 00:00:00"    |
|    [7]: "Address"    |    [7]: "11120 Jasper Ave NW"    |
|    [8]: "City"       |    [8]: "Edmonton"               |
|    [9]: "State"      |    [9]: "AB"                     |
|    [10]: "Country"   |    [10]: "Canada"                |
|    [11]: "PostalCode"|    [11]: "T5K 2N1"               |
|    [12]: "Phone"     |    [12]: "+1 (780) 428-9482"     |
|    [13]: "Fax"       |    [13]: "+1 (780) 428-3457"     |
|    [14]: "Email"     |    [14]: "andrew@chinookcorp.com"|

I've got the 15 column names and values, including the <i>null</i> value  for <i>ReportsTo</i>. The values are literals, <i>as you've pointed out.</i>

My callback function writes the data it receives to a file, <i> its content as follows:</i>

```
1-0:EmployeeId=1
1-1:LastName=Adams
1-2:FirstName=Andrew
1-3:Title=General Manager
1-4:ReportsTo=
1-5:BirthDate=1962-02-18 00:00:00
1-6:HireDate=2002-08-14 00:00:00
1-7:Address=11120 Jasper Ave NW
1-8:City=Edmonton
1-9:State=AB
1-10:Country=Canada
1-11:PostalCode=T5K 2N1
1-12:Phone=+1 (780) 428-9482
1-13:Fax=+1 (780) 428-3457
1-14:Email=andrew@chinookcorp.com
2-0:EmployeeId=2
2-1:LastName=Edwards
2-2:FirstName=Nancy
2-3:Title=Sales Manager
2-4:ReportsTo=1
2-5:BirthDate=1958-12-08 00:00:00
2-6:HireDate=2002-05-01 00:00:00
2-7:Address=825 8 Ave SW
2-8:City=Calgary
2-9:State=AB
2-10:Country=Canada
2-11:PostalCode=T2P 2T3
2-12:Phone=+1 (403) 262-3443
2-13:Fax=+1 (403) 262-3322
2-14:Email=nancy@chinookcorp.com
3-0:EmployeeId=3
3-1:LastName=Peacock
3-2:FirstName=Jane
3-3:Title=Sales Support Agent
3-4:ReportsTo=2
3-5:BirthDate=1973-08-29 00:00:00
3-6:HireDate=2002-04-01 00:00:00
3-7:Address=1111 6 Ave SW
3-8:City=Calgary
3-9:State=AB
3-10:Country=Canada
3-11:PostalCode=T2P 5M5
3-12:Phone=+1 (403) 262-3443
3-13:Fax=+1 (403) 262-6712
3-14:Email=jane@chinookcorp.com
```

The first number is the record number (index 1), the second number is the column number (index 0) , followed by the column name and column value.

<b> Only 3 of 8 rows come to the callback function</b>. Then I hit this error:

>Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=<Cannot evaluate the exception source>

1.I've tried with other tables with fewer and more columns and records (in case it was a buffer issue) and meet the same fatal error.

2.I've also experimented with adding delays (in case there was a timing issue) in the callback function but it makes no difference.

3.I am using the pre-compiled 32-bit 3.34 version. I tried with 3.26 - makes no difference.

Since my code works for 3 records, it is probably 'correct'. 

<i>I've run out of options for debugging the reason for the error I am getting after 3 rows.</i> Hopefully, someone can share their insight so I can solve this problem.

When I call sqlite3_exec from my code, on which line in sqlite3.c does it land?