Code Monkey home page Code Monkey logo

Comments (7)

ccgus avatar ccgus commented on June 27, 2024

Sorry, but I can't even being to help you out on this, since there are so many things that could be going wrong.

I would suggest you add a bunch of logging to your classes, and make sure every input that you're giving to the various methods is exactly as you expect it to be. Either that, or break the problem down into the simplest possible example, and if there's a bug in that- we can start there.

from fmdb.

 avatar commented on June 27, 2024

Hi, thanks for your patience. This is the insert statement I am using:

    [fmdb beginTransaction];
    [fmdb executeUpdate:@"INSERT INTO T_ANSWER (PATIENT_VISIT_ID, QUESTION_ID) VALUES (?, ?)",     [_patientVisit patientVisitId], [_question questionId]];
    [fmdb commit];
    if ([fmdb hadError]) {
        [fmdb close];
        NSLog(@"db error");
        return FALSE;
    }  

and then, to check, I execute a count(*) select, and it returns that 0 records are in the table!?

no errors returned executeUpdate returns true, and rc in the inner method is 0.. i don't know what is it.. i open the connection multiple times before the insert, but i close it everytime.. that's the only sketchy thing i have in the app right now..

but my other concern is it does not "insert" into the db location I have it writes to this one:

i open the database like this:
fmdb = [FMDatabase databaseWithPath: [[NSBundle mainBundle] pathForResource:@"database" ofType:@"db"]];

any thoughts? this is the first time i use inserts in the application using fmdb, been always manually inserting data while developing..

again, thank you VERY much for your support!

Isaac

from fmdb.

 avatar commented on June 27, 2024

forget about "but my other concern is it does not "insert" into the db location I have it writes to this one:" because it actually inserts in the right database.. i just check that.

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

Sorry, I'm not sure what to tell you. Unless you can provide for me a stripped down reproducible sample, there isn't anything I can do.

from fmdb.

 avatar commented on June 27, 2024

FMDatabase * fmdb = [FMDatabase databaseWithPath: [[NSBundle mainBundle] pathForResource:@"ortho" ofType:@"db"]];
[fmdb setLogsErrors: TRUE];
[fmdb setTraceExecution: TRUE];
[fmdb open];
[fmdb beginTransaction];
[fmdb executeUpdate:@"INSERT INTO T_ANSWER (PATIENT_VISIT_ID, QUESTION_ID) VALUES (?, ?)", [NSNumber numberWithInt: 99], [NSNumber numberWithInt: 99]];
[fmdb commit];
if ([fmdb hadError]) {
[fmdb close];
NSLog(@"db error");
return;
}

FMResultSet * rs = [fmdb executeQuery:@"select count(*) from T_ANSWER where PATIENT_VISIT_ID = 99"];
if ([fmdb hadError]) {
    NSLog(@"cannot execute clean_start check query");
    return;
}
NSLog(@"count inserted = %d", [rs intForColumnIndex: 1]);
[fmdb close];

2012-01-04 22:29:53.867 Tests[4099:207] SessionCommandProcessorGHTestCase/testSimpleInsert
2012-01-04 22:29:58.983 Tests[4099:207] Re-running: SessionCommandProcessorGHTestCase/testSimpleInsert <GHTest: 0x4c25590>
2012-01-04 22:29:58.985 Tests[4099:207] <FMDatabase: 0x4c2f190> executeUpdate: BEGIN EXCLUSIVE TRANSACTION;
2012-01-04 22:29:58.986 Tests[4099:207] <FMDatabase: 0x4c2f190> executeUpdate: INSERT INTO T_ANSWER (PATIENT_VISIT_ID, QUESTION_ID) VALUES (?, ?)
2012-01-04 22:29:58.988 Tests[4099:207] obj: 99
2012-01-04 22:29:58.988 Tests[4099:207] obj: 99
2012-01-04 22:29:58.989 Tests[4099:207] <FMDatabase: 0x4c2f190> executeUpdate: COMMIT TRANSACTION;
2012-01-04 22:29:58.992 Tests[4099:207] <FMDatabase: 0x4c2f190> executeQuery: select count(*) from T_ANSWER where PATIENT_VISIT_ID = 99
2012-01-04 22:29:58.993 Tests[4099:207] count inserted = 0
2012-01-04 22:29:58.996 Tests[4099:207] SessionCommandProcessorGHTestCase/testSimpleInsert ✔ 0.01s

table:
CREATE TABLE T_ANSWER (
ANSWER_ID INTEGER PRIMARY KEY ASC AUTOINCREMENT,
PATIENT_VISIT_ID INTEGER NOT NULL,
QUESTION_ID INTEGER NOT NULL UNIQUE,
EFF_TS INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
EXP_TS INTEGER
)

weird!?

from fmdb.

ccgus avatar ccgus commented on June 27, 2024

Works ok for me (using this JSTalk script):

var dbPath = "/tmp/jstalk.sqlite";

var db = [JSTDatabase databaseWithPath:dbPath];
if (![db open]) {
print("Could not open database");
}

[db executeUpdate:"""CREATE TABLE T_ANSWER (
ANSWER_ID INTEGER PRIMARY KEY ASC AUTOINCREMENT,
PATIENT_VISIT_ID INTEGER NOT NULL,
QUESTION_ID INTEGER NOT NULL UNIQUE,
EFF_TS INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
EXP_TS INTEGER
)"""];

[db executeUpdate:"INSERT INTO T_ANSWER (PATIENT_VISIT_ID, QUESTION_ID) VALUES (?, ?)", [NSNumber numberWithInt:99], [NSNumber numberWithInt:99]];

var rs = [db executeQuery:"select * from T_ANSWER"];

while ([rs next]) {
print([rs resultDict]);
}

var rs = [db executeQuery:"select count(*) from T_ANSWER where PATIENT_VISIT_ID = 99"];

while ([rs next]) {
print("b: " + [rs stringForColumnIndex:0]);
}


{
"answer_id" = 1;
"eff_ts" = "2012-01-05 17:50:58";
"exp_ts" = "";
"patient_visit_id" = 99;
"question_id" = 99;
}
b: 1

from fmdb.

 avatar commented on June 27, 2024

Thank you! I'll do my homework!

from fmdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.