Python Zeit/Datum Probleme

  • Hallo Leute ich will das in meiner Datenbank tabelle die Normale Zeit und Datum angezeigt wird.

    Das ist der ORGINAL CODE der Funktioniert aber Datum/Zeit in UNIX Datum in die Datenbank schreibt.



    Das ist der VERSUCHS Code mit dem ich die UNIX Datum time tamp in der Datenbank ändern wollte in Normal PC Datum/Zeit z.b. "2014-10-12 21:20:30"


    Stimmt das so ?

    Hat jemand eine Idee wie man es noch machen könnte

    Einmal editiert, zuletzt von B0sSK4ra (26. Februar 2014 um 21:40)

    • Offizieller Beitrag

    Außerdem ist Python empfindlich was Leerzeichen und Tabulatoren angeht!
    Wie schon per PN besprochen....

    1. benutzte doch bitte die [code] Klammern!
    2. Lade mal deinen Ausgangsquellcode hoch mit dem es funktioniert hat.

    Dann kann ich dir sicherlich helfen.

    Well in my humble opinion, of course without offending anyone who thinks differently from my point of view, but also by looking into this matter in a different way and without fighting and by trying to make it clear and by considering each and every one's opinion, I honestly believe that I completely forgot what I was going to say.

    • Offizieller Beitrag

    Er möchte anstatt dem Unix timestamp einen String ( 27.02.2013 13:33) in die Tabelle schreiben. Keine große Sache.

    Wie schon gesagt. Du musst in der Tabelle das Feld von integer auf Text setzten.
    Danach kannst du mit Python weitermachen. Leider ist dein Code immer noch falsch eingerückt. So wird der niemals korrekt ausgeführt. ;)

    Wirf mal einen Blick auf das erste Current_State in der while Schleife.

    Well in my humble opinion, of course without offending anyone who thinks differently from my point of view, but also by looking into this matter in a different way and without fighting and by trying to make it clear and by considering each and every one's opinion, I honestly believe that I completely forgot what I was going to say.

  • Das kommt danach raus


    Code
    PIR Module Test (CTRL-C to exit)
    Alarmanlage PIR Sensoren ; SCHARF ;
      Ready;Bereit 'NO ALARM'
      ALARM ; !!! MOTION DETECTED !!! UNERLAUBTE AUTHORISIERUNG
    Traceback (most recent call last):
      File "infrarotorgi.py", line 61, in <module>
        cur.execute("INSERT INTO tbl_log values(null , %s, 'PIR 1','ALARM')" % (ts) )
    sqlite3.OperationalError: near "11": syntax error
    • Offizieller Beitrag

    Ich hab mir angewöhnt SQL Abfragen nur noch in Documentation Strings zu schreiben

    Code
    cur.execute("""INSERT INTO tbl_log values(NULL , "%s", "PIR 1","ALARM")""" % (ts) )

    Eigentlich mag ich diese Schreibweise sogar noch lieber

    Code
    cur.execute("""INSERT INTO tbl_log values("spalte1,Spalte2, Spalte3,spalte4) VALUES (NULL , "%s", "PIR 1","ALARM")""" % (ts) )

    Ob NULL jetzt auch in "" geschrieben werden muss, bin ich mir grad nicht sicher

  • eigentlich sollte man sowieso immer Platzhalter nehmen:

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!