Re: database not accepting data properly

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Shaan Repswal <shaun(dot)reapswaal(at)gmail(dot)com>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: database not accepting data properly
Date: 2016-02-22 15:41:32
Message-ID: 56CB2C2C.1010307@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 02/22/2016 02:03 AM, Shaan Repswal wrote:
Ccing list.
> That was so stupid of me. I am so sorry. When I use a script to query
> the database, the fourth column of my database is of type "interval" I
> store datetime.timedelta() objects in it from Python 3.4 But everytime I
> query it with the attached querying script it always returns
> datetime.timedelta(0) as the values of my sessionduration column.

So to be clear no error is thrown, correct?

You are just not seeing what you expect.

>
> I am storing them there from the testProductivityApp.py script that I
> sent to you in an earlier email. You will need to install GTK 3 for
> Python 3.4 to run that script. So bascally the datetime.timedelta()
> objects are stored, but they are always datetime.timedelta(0,0,0.0) Any
> idea why that could be happening?

First what are the values in that field in the database itself?

Second could it be (datetime.datetime.now() - self.start_time) is
returning the correct result. In other words that now() and
self.start_time are the same. Have you looked at what those values are
as the script runs?

I ask because you have self.start_time created twice in your code:

1) In the __init__ as self.start_time = datetime.datetime

2) In startRecording as self.start_time = datetime.datetime.now()

I am not sure, but I have to believe that is causing at least part of
your issue.

>
> However to troubleshoot the program I wrote another micro script (also
> sent with the last email) called manualaitestdbentry.py which was to
> check if I could store datetime.timedelta() objects in the postgresql
> database, turns out I can store the datetime.timedelta() objects with
> their seconds, days and microseconds attributes intact.
>
> On Sun, Feb 21, 2016 at 9:28 PM, Adrian Klaver
> <adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
>
> On 02/21/2016 02:45 AM, Shaan Repswal wrote:
>
> Hey guys, I hope I used the Mailing List properly. I am trying
> to upload
> a datetime.timedelta object into a column of type interval...
> But when I
> query it says datetime.interval(0)
>
>
> Can you post the actual error message?
>
> What are you querying that gets you datetime.interval[0]?
>
>
>
> here are the lines where the error probably is:-
> print(cur.mogrify("""SELECT %s, %s, %s, %s""",
> (self.start_time.date(),
> self.start_time.time(), datetime.datetime.now() - self.start_time,
> desc_text)))
> cur.execute("""INSERT INTO sessionlogs(sessiondate,
> sessiontime, sessionduration, sessiondesc)
> VALUES(%s, %s, %s, %s);""",
> (self.start_time.date(), self.start_time.time(),
> datetime.datetime.now()
> - self.start_time, desc_text))
>
> although when I wrote another script to enter a specific code,
> it was
> working just fine.
>
> datetime.datetime.now() - self.start_time is the time interval which
> seems to be where the error is.
>
> when I did this :-
> cur.execute("""INSERT INTO sessionlogs(sessiondate, sessiontime,
> sessionduration, sessiondesc)
> VALUES (%s, %s, %s, %s)""",
> (datetime.datetime.now().date(), datetime.datetime.now().time(),
> datetime.timedelta(1, 18268), "This is a manual entry"))
>
> It was working quite fine.
>
> I will attach the two scripts
>
> Sorry for the uber messy code. I hope you can read through my whole
> script as it isn't very big. I am using Gtk 3+ here so be
> warned... :P
>
>
>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2016-02-22 21:58:58 Re: database not accepting data properly
Previous Message Adrian Klaver 2016-02-21 15:58:50 Re: database not accepting data properly