1

I am trying to put objects into the sqlite table. I am using react-native-sqlite for that. When I am storing the object by converting it to string it is storing as [object,object]

    let water_characterstics = {"summer": {"bod": CSbodSummer,"cod": CScodSummer,"tss":CStssSummer,"mcoli":CSmcoliSummer},
                    "winter": {"bod": CSbodWinter,"cod": CScodWinter,"tss":CStssWinter,"mcoli":CSmcoliWinter},
                    "current": {"bod": CSbodCurrent,"cod": CScodCurrent,"tss":CStssCurrent,"mcoli":CSmcoliCurrent}
                    }

let wCC = water_characterstics.toString();

     db.transaction(function(tx) {
                      tx.executeSql(
                        'INSERT INTO stream_liquid_untapped (city_id, drain_name,drain_type,survey_type, drain_status, pollution_reason,status_latitude,status_longitude, treatment_type, stream_flow, meeting_latitude, meeting_longitude, meeting_avatar1_source, meeting_avatar2_source, meeting_avatar1_name, meeting_avatar2_name, characterstic_water, remarks, synced) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
                        [1, drain_name,drain_type_number,1,3,pA,0,0,tapValue,stream_flow,ganga_meet_latitude,ganga_meet_longitude,av1_meeting_source,av2_meeting_source,av1_meeting_name,av2_meeting_name,wCC,rmrks,false],
                        (tx, results) => {  
                          console.log('Results', results.rowsAffected);
                          if (results.rowsAffected > 0) {
                            that.setState({ShowSaveModal:true});
                          } else {
                            Alert.alert(
                              'Failed',
                              [
                                {
                                  text: 'Ok',
                                },
                              ],
                              { cancelable: false }
                            );
                          }
                        }
                      );
                    });

1 Answer 1

2

You did water_characterstics.toString() which always returns [object Object]. Instead, you should do JSON.stringify(water_characterstics).

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Sign up to request clarification or add additional context in comments.

1 Comment

i have some issue with sqlite, i create the insert fetch delete functions and for some reason it doesn't work for me. can you help me please ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.