martinrybak / SQLClient

Native Microsoft SQL Server client for iOS
http://objcsharp.wordpress.com/2013/10/15/an-open-source-sql-server-library-for-ios/
MIT License
124 stars 51 forks source link

crash at connection #8

Closed sunarc123 closed 7 years ago

sunarc123 commented 10 years ago

Hello Martin,

After a long time I am getting again crashes due to sql library in my app. Please check below screen shot for details. screen shot 2014-02-25 at 12 22 28

martinrybak commented 10 years ago

Does this happen every time or just sometimes? Can you include me more of the stack trace? Thanks.

ramsince88 commented 10 years ago

This happens every time.

martinrybak commented 10 years ago

Please tell me if anything changed since the last time you said everything was working fine. Also please attach the full stack trace.

ramsince88 commented 10 years ago

I have not made any change just deploy code on another machine.

ramsince88 commented 10 years ago

Did you get any solution????

ramsince88 commented 10 years ago

Hii Sorry for inconvenience.

{

//Execute query on worker queue

[self.workerQueue addOperationWithBlock:^{

//Prepare SQL statement

dbcmd(connection, [sql UTF8String]);

//Execute SQL statement

if (dbsqlexec(connection) == FAIL)

return [self executionFailure:completion];

//Create array to contain the tables

NSMutableArray* output = [[NSMutableArray alloc] init];

struct COL* columns;

struct COL* pcol;

int erc;

//Loop through each table

while ((erc = dbresults(connection)) != NO_MORE_RESULTS)

{

int ncols;

int row_code;

//Create array to contain the rows for this table

NSMutableArray* table = [[NSMutableArray alloc] init];

//Get number of columns

ncols = dbnumcols(connection);

//Allocate C-style array of COL structs

if ((columns = calloc(ncols, sizeof(struct COL))) == NULL)

return [self executionFailure:completion];

//Bind the column info

for (pcol = columns; pcol - columns < ncols; pcol++)

{

//Get column number

int c = pcol - columns + 1;

//Get column metadata

pcol->name = dbcolname(connection, c);

pcol->type = dbcoltype(connection, c);

pcol->size = dbcollen(connection, c);

//If the column is [VAR]CHAR, we want the column's defined size, otherwise we want

//its maximum size when represented as a string, which FreeTDS's dbwillconvert()

//returns (for fixed-length datatypes).

if (pcol->type != SYBCHAR)

pcol->size = dbwillconvert(pcol->type, SYBCHAR);

//Allocate memory in the current pcol struct for a buffer

if ((pcol->buffer = calloc(1, pcol->size + 1)) == NULL)

return [self executionFailure:completion];

//Bind column name

erc = dbbind(connection, c, NTBSTRINGBIND, pcol->size + 1, (BYTE*)pcol->buffer);

if (erc == FAIL)

return [self executionFailure:completion];

//Bind column status

erc = dbnullbind(connection, c, &pcol->status);

if (erc == FAIL)

return [self executionFailure:completion];

//printf("%s is type %d with value %s\n", pcol->name, pcol->type, pcol->buffer);

}

//printf("\n");

//Loop through each row

while ((row_code = dbnextrow(connection)) != NO_MORE_ROWS)

{

//Check row type

switch (row_code)

{

//Regular row

case REG_ROW:

{

//Create a new dictionary to contain the column names and vaues

NSMutableDictionary* row = [[NSMutableDictionary alloc] initWithCapacity:ncols];

//Loop through each column and create an entry where dictionary[columnName] = columnValue

for (pcol = columns; pcol - columns < ncols; pcol++)

{

NSString* column = [NSString stringWithUTF8String:pcol->name];

id value = [NSString stringWithUTF8String:pcol->buffer] ?: [NSNull null];

row[column] = value;

                        //printf("%@=%@\n", column, value);

}

                    //Add an immutable copy to the table

[table addObject:[row copy]];

//printf("\n");

break;

}

//Buffer full

case BUF_FULL:

return [self executionFailure:completion];

//Error

case FAIL:

return [self executionFailure:completion];

default:

[self message:SQLClientRowIgnoreMessage];

}

}

//Clean up

for (pcol = columns; pcol - columns < ncols; pcol++)

free(pcol->buffer);

free(columns);

//Add immutable copy of table to output

[output addObject:[table copy]];

}

    //Success! Send an immutable copy of the results array

[self executionSuccess:completion results:[output copy]];

}];

}

this code where crashing exist. and screen shot of stack is below screen shot 2014-03-06 at 12 58 36

ramsince88 commented 10 years ago

Martin please reply. My whole app depend on your code.

martinrybak commented 10 years ago

You said your code works on one machine and not the other? Can you tell me what is different between them?

ramsince88 commented 10 years ago

No difference. That time I was working at dubai and now in india. And now testing on simulator and that time testing on device. Thats all.

martinrybak commented 10 years ago

So it works on the device but not in the simulator?

ramsince88 commented 10 years ago

YES . But once let me confirm again.

ramsince88 commented 10 years ago

Yes. This happened only in simulator.