1

I have a unix date in long format

Long tmpLong = (Long) local.getValue();

Here is the value of tmpLong

1485710457166

Now I want to store this variable inside of my SQLite DB, after some research I found out that you cant store Longs in SQLite so I tried this:

Long tmpLong = (Long) local.getValue();
Integer tmpInt = tmpLong.intValue();

But this gives me:

-348227250

In SQLite my datatype is INTEGER

I need help storing this unix number, any help is appreciated

Update 1

If I try store it as a long, so

localDB.add(image_id, unixTimestamp, PATH);

And then in my add method (inside SQLiteHelper class). I print the value for testing :

 public void add(String image_id, Long date, String path) {
    SQLiteDatabase db = this.getWritableDatabase();
    Log.d("SQL", "date " + date);

It prints 1

D/SQL: date 1

1 Answer 1

1

Well, that is what will happen when you truncate a 64 bit Long into a 32 bits integer...

Dont do that but try to store it like it is (as a long) because SQLite ints can handle that values, take a look into the Datatypes In SQLite

enter image description here

Edit:

Your code below:

public void add(String image_id, Long date, String path) {
    SQLiteDatabase db = this.getWritableDatabase();
    Log.d("SQL", "date " + date);
}

if that code is so as it is posted then you are passing as parameter 1 for the date value... the method this.getWritableDatabase(); is not going to modify/change the value of the date parameter...

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

2 Comments

well, before the data is sent to that class I check the unix value and its correct, when it gets to the next class its 1 which i know doesnt make any sense
nevermind I found the problem =, it was not to do with the date

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.