Python Forum
pymysql: insert query throws error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymysql: insert query throws error
#4
hi,

thanks for answering. you are right, this needs more explaination.

First, i use python-sudoers for parsing sudoers files.
So this is part of the procedure of parsing various aspects of a sudoers file into python structures.

for key in sudo_obj.host_aliases:
        host_alias_list = []
        host_alias_list.append((key, list(sudo_obj.host_aliases[key])))
        results['hostalias'].append(host_alias_list)
this ist the output from the parsing library and represents a complete sudoers files. i added items= tablenames for clarification.

[['aixacodbt']] = sudohost 
[[['root']]] = users
[[['ALL']]] = hosts
[[(['root'], ['ALL'], [{'run_as': ['ALL'], 'tags': None, 'command': 'ALL'}])]] = commands
the next part prints out a complete insert statement...

qmarks = ",".join('?' * len(results))
        qry = "INSERT INTO rules (%s) VALUES (%s)" % (qmarks, qmarks)
        qvals = *results.keys(), *results.values()
        qvals_stringed = ','.join(map(str, qvals))
        print(type(qvals_stringed))
        print(qry, qvals_stringed)
<class 'str'>
INSERT INTO rules (?,?,?,?) VALUES (?,?,?,?) sudohost,users,hosts,commands,[['aixacodbt']],[[['root']]],[[['ALL']]],[[(['root'], ['ALL'], [{'run_as': ['ALL'], 'tags': None, 'command': 'ALL'}])]]
updated original post with slightly modified script and outputs from a more simple sudoers file.

wbr chris
Reply


Messages In This Thread
pymysql: insert query throws error - by wardancer84 - Jan-21-2022, 12:54 PM
RE: pymysql: insert query throws error - by wardancer84 - Jan-24-2022, 11:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sqlite3 Conn Insert Value Error TylerDunbar 3 805 Sep-04-2023, 06:32 PM
Last Post: deanhystad
  pymysql; insert on duplicate key update fails wardancer84 4 2,105 Jun-28-2022, 08:14 PM
Last Post: Larz60+
  Mysql Syntax error in pymysql ilknurg 4 2,446 May-18-2022, 06:50 AM
Last Post: ibreeden
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,408 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Query Syntax Error hammer 2 1,662 Jan-03-2022, 02:30 PM
Last Post: hammer
  pymysql can't do SELECT * Pedroski55 3 3,044 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,215 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error using mariadb select query with form in python? shams 2 2,062 Jul-29-2021, 12:30 PM
Last Post: shams
  pyarrow throws oserror winerror 193 1 is not a valid win32 application aupres 2 3,853 Oct-21-2020, 01:04 AM
Last Post: aupres
  Function throws error but then works? Milfredo 10 3,909 Sep-12-2020, 05:16 AM
Last Post: Milfredo

Forum Jump:

User Panel Messages

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