Python Forum
How to append a tuple full of records to a dbf file in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to append a tuple full of records to a dbf file in Python?
#1
I'm trying to append a tuple full of records into a dbf file that I received from a sql statement but it only produce one record in my tuple. This is my code:


try:            
            DbConnect = '***'
            myDbConn = pymssql.connect("*********","********", "*************",DbConnect)
            cursor = myDbConn.cursor()
            cursor.execute("""select * from payrolldata where busdate>= %s and busdate<=%s ;""",(dteStartDate,m0weekend))
            rows = cursor.fetchall() or []

            for row in rows:
                myTup = tuple(row)



                Dbf = dbf.Table( 'microsdata.DBF', 'id N(7,0); StoNo C(4);BusDate C(20);Position C(20);Ssn C(11); R_HRS N(10,4); Ot_Hrs N(10,4); OthOt_Hrs N(10,4); Oth_Hrs N(10,4); Tips_Pd N(10,4); Tips_Chg N(10,4); Tips_Ind N(10,4); Tips_Dec N(10,4); FirstName C(20); LastName C(20); PayrollId C(10); PayRate N(10,4); RegPay N(10,4)') 
                Dbf.open(mode=dbf.READ_WRITE)
                records = Dbf.append(myTup)
Reply
#2
Could it be that you only receive the last record?
It seems to me that you are creating the same table in a loop over and over again.

Paul
Reply
#3
I put it in that loop because I thought it would loop all my records. When its outside my for loop it shows no records in my dbf file.
Reply
#4
I'm trying to append tuple into my dbf file as records but it only gets the last line of my tuple.

 table = dbf.Table( 'empInfo.DBF', 'SSN C(11); STOREID C(4);Payrollid C(10); EmpId C(10); Fname C(20); Lname C(20)') 
 table.open(mode=dbf.READ_WRITE)
 rec = tuple(rows)
 print(rec)
Reply
#5
I'm trying to append a tuple for multiple records but I only get the last record of my tuple.
table = dbf.Table( 'empInfo.DBF', 'SSN C(11); STOREID C(4);Payrollid C(10); EmpId C(10); Fname C(20); Lname C(20)') 
table.open(mode=dbf.READ_WRITE)

rec = tuple(rows)

table.append(rec)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Building a DoublyLinkedList in Python - - append method Drone4four 2 371 Jan-08-2024, 01:27 PM
Last Post: Drone4four
Question How to append integers from file to list? Milan 8 1,358 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  validate large json file with millions of records in batches herobpv 3 1,221 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Create multiple/single csv file for each sql records mg24 6 1,323 Sep-29-2022, 08:06 AM
Last Post: buran
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,694 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  read a text file, find all integers, append to list oldtrafford 12 3,368 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,175 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  My python code is running very slow on millions of records shantanu97 7 2,510 Dec-28-2021, 11:02 AM
Last Post: Larz60+
  How to make a test data file for the full length of definition? MDRI 6 3,481 Apr-16-2021, 01:47 AM
Last Post: MDRI
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,726 Nov-04-2020, 11:26 AM
Last Post: Aggam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020