I think I found your problem.


Change

self.con.commit

To

self.con.commit()



In your Fupdate function



sqlite> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE abc800_111_1111_FIRST
                                            (pink varchar,
                                            green varchar,
                                            rec_Rowname varchar,
                                            row_1 varchar,
                                            ent_1 varchar,
                                            notes varchar,
                                            rowcount
                                            );
INSERT INTO "abc800_111_1111_FIRST" VALUES('abc','800 111 1111','FIRST','1)    
Add New Name','','','1');



Michael D. Black

Senior Scientist

Advanced Analytics Directorate

Advanced GEOINT Solutions Operating Unit

Northrop Grumman Information Systems

________________________________
From: [email protected] [[email protected]] on 
behalf of inq1ltd [[email protected]]
Sent: Friday, February 03, 2012 4:32 PM
To: [email protected]
Subject: EXT :[sqlite] Re; update problem

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3


This email copy may be easier to work with rather than the previous one.

 If someone has the time I would appreciate it if you
 could run this module.

 Everything works except the class Kupdate.
 For some reason I don't get any complaints from
 python or sqlite but when selecting from the table I
 cannot retrieve the last update on line 113,  (  '1)
    Add New Name' ). any suggestions would be
 helpful.

jd


class KmkSql:


    def __init__(self) :

        self.sqldb = 'ZZSQL_TEST.sql'
        KmkSql.sqldb = self.sqldb

        self.tablename = tablename = 'abc800_111_1111_FIRST'
        print tablename,  '## tablename sql_test 24 \n'

        self.vRecordKey = ['abc', '800 111 1111', 'FIRST' ]

        self.FmkSql_01()



    def FmkSql_01(self) :

        print   '## locate sql_test 34\n'
        self.con = sqlite3.connect(self.sqldb)
        self.cursor = self.con.cursor()


        self.cursor.execute ("""CREATE TABLE IF NOT EXISTS """ +
self.tablename + """
                                            (pink varchar,
                                            green varchar,
                                            rec_Rowname varchar,
                                            row_1 varchar,
                                            ent_1 varchar,
                                            notes varchar,
                                            rowcount
                                            )"""
                                            );

        self.con.commit()

        self.FaddDefault()


    def FaddDefault(self) :

        vrowcount = 'rowcount'
        vpink = str(self.vRecordKey[0] )
        vgreen = str(self.vRecordKey[1] )
        rec_Rowname = str(self.vRecordKey[2] )

        self.cursor.execute("""SELECT """ + vrowcount + """ FROM """ +
self.tablename + """ WHERE pink = (?) AND green = (?) AND rec_Rowname = (?)
""", [self.vRecordKey[0], self.vRecordKey[1], self.vRecordKey[2] ]);
        self.con.commit()

        Rcount = self.cursor.fetchall()  ## unicode
        self.con.commit()

        print Rcount, '## Rcount sql_test 69  \n'

        if Rcount == [] :

            Kinsert( self.sqldb, self.tablename, self.vRecordKey )

            Kupdate (self.sqldb, self.tablename, self.vRecordKey)

        else :
            self.con.close()
            Kupdate(self.sqldb, self.tablename, self.vRecordKey )


class Kinsert:

    def __init__(self, sqldb, tablename, vRecordKey ) :

        self.tablename = tablename

        self.vRecordKey = vRecordKey
        print vRecordKey,  '## vRecordKey sql_test 97 \n'

        self.sqldb = sqldb

        self.Finsert()


    def Finsert(self) :

        vpink = str(self.vRecordKey[0] )
        vgreen = str(self.vRecordKey[1] )
        rec_Rowname = str(self.vRecordKey[2] )

        norow =  '1)    No Row Name'

        self.con = sqlite3.connect(self.sqldb) # open DB
        self.cursor = self.con.cursor()

        self.cursor.execute ("""INSERT INTO """ + self.tablename + """ VALUES
(?,?,?,?,?,?,?)  """ , [ vpink, vgreen, rec_Rowname,  norow, '', '', '1'  ]  )
;

        self.con.commit()
        self.con.close()




class Kupdate :

    def __init__(self, sqldb, tablename, vRecordKey ) :

        self.tablename = tablename

        self.colname = 'row_1'
        self.divAddName = '1)    Add New Name'

        self.sqldb = sqldb

        self.vRecordKey = vRecordKey

        self.Fupdate()


    def Fupdate(self) :

        vpink = str(self.vRecordKey[0] )
        vgreen = str(self.vRecordKey[1] )
        rec_Rowname = str(self.vRecordKey[2] )

        self.con = sqlite3.connect(self.sqldb) # open DB
        self.cursor = self.con.cursor()

        self.cursor.execute (""" UPDATE """ + self.tablename + """ SET """ +
self.colname +  """ = (?) WHERE pink = (?) AND green = (?) AND rec_Rowname =
(?) """, [ self.divAddName, vpink, vgreen,  rec_Rowname ]  );
        self.con.commit
        self.con.close()

        Kselect( self.sqldb, self.tablename, self.vRecordKey, self.colname)

class Kselect:

    def __init__(self, sqldb, tablename, vRecordKey, colname ) :

        self.vRecordKey = vRecordKey

        self.Fselect(sqldb, tablename, vRecordKey, colname)

    def Fselect(self, sqldb, tablename, vRecordKey, colname) :


        vpink = str(self.vRecordKey[0] )
        vgreen = str(self.vRecordKey[1] )
        rec_Rowname = str(self.vRecordKey[2] )

        con = sqlite3.connect(sqldb) # open DB
        cursor = con.cursor()

        cursor.execute("""SELECT """ + colname + """  FROM """ + tablename +
""" WHERE pink = (?) AND green = (?) AND rec_Rowname = (?) """, [vpink,
vgreen, rec_Rowname ] );
        con.commit()

        divcolinfo = cursor.fetchall()  ## unicode
        con.commit()
        con.close()

        print divcolinfo, '## divcolinfo sql_test 170  \n'



if __name__ == "__main__" :
    KmkSql()


_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to