数据为什么没有添加到单元格?

huangapple go评论121阅读模式
英文:

Why is data is not added to the cell?

问题

我可以告诉你为什么数据没有添加到指定的单元格吗?
我正在尝试收集列表中的所有数字并将它们放入一个单元格中。脚本执行成功,清空了一个单元格,但单元格中的数据没有出现。
需要将列表放入一个单元格中,因为这就是freebx的工作原理。

#/usr/bin/python3

import mysql.connector

try:
    connection = mysql.connector.connect(host='localhost',
                                         database='asterisk',
                                         user='freepbxuser',
                                         password='',
                                         autocommit=True)
    sql_select_Query = "SELECT CONCAT(cell) FROM userman_users"
    cursor = connection.cursor()
    cursor.execute(sql_select_Query)
    dirty_text = [i[0] for i in cursor.fetchall()]
    for item in dirty_text.copy():
        if item is None:
            dirty_text.remove(item)
    SYMBOLS = '{}()[].,:;+-*/&|<>=~'
    clear_text = []
    for element in dirty_text:
        temp = ""
        for ch in element:
            if ch not in SYMBOLS:
                temp += ch
        clear_text.append(temp)
    values = [list([item]) for item in clear_text]
    cursor.executemany ("""
    UPDATE pinsets
    SET passwords=%s
    WHERE pinsets_id=1
    """, (values))
except mysql.connector.Error as e:
    print("Error", e)
finally:
    if connection.is_connected():
        connection.close()
        cursor.close()

请注意,此脚本将从数据库中检索的数据更新到名为pinsets的表中的passwords列中,其中pinsets_id为1。确保数据库连接配置正确并且您有适当的权限来执行这些操作。如果仍然有问题,您可能需要检查数据库中的表结构和数据类型是否正确匹配。

英文:

Can you tell me why the data is not being added to the specified cell?
I'm trying to collect all the numbers in a list and put them in a cell. The script fulfills, clears a cell, but the data in a cell does not appear.
It is necessary to put the list in exactly one cell, because this is how freebx works

数据为什么没有添加到单元格?

#/usr/bin/python3

import mysql.connector

try:
    connection = mysql.connector.connect(host=&#39;localhost&#39;,
                                     database=&#39;asterisk&#39;,
                                     user=&#39;freepbxuser&#39;,
                                     password=&#39;&#39;,
                                     autocommit=True)
    sql_select_Query = &quot;SELECT CONCAT(cell) FROM userman_users&quot;
    cursor = connection.cursor()
    cursor.execute(sql_select_Query)
    dirty_text = [i[0] for i in cursor.fetchall()]
    for item in dirty_text.copy():
        if item is None:
           dirty_text.remove(item)
    SYMBOLS = &#39;{}()[].,:;+-*/&amp;|&lt;&gt;=~&#39;
    clear_text = []
    for element in dirty_text:
        temp = &quot;&quot;
        for ch in element:
            if ch not in SYMBOLS:
                temp += ch
        clear_text.append(temp)
    values = [list([item]) for item in clear_text]
    cursor.executemany (&quot;&quot;&quot;
    UPDATE pinsets
    SET passwords=%s
    WHERE pinsets_id=1
    &quot;&quot;&quot;, (values))
except mysql.connector.Error as e:
    print(&quot;Error&quot;, e)
finally:
    if connection.is_connected():
        connection.close()
        cursor.close()

答案1

得分: 1

这段代码实现了我认为你想要的功能。它从"userman_users"表的"cell"列中提取所有非NULL值,去除其中的特殊字符,然后将它们存储为以逗号分隔的列表,存储在"pinsets"表的一行中:

connection = mysql.connector.connect(host='localhost',
                                     database='asterisk',
                                     user='freepbxuser',
                                     password='',
                                     autocommit=True)
sql_select_Query = "SELECT cell FROM userman_users;"
cursor = connection.cursor()
cursor.execute(sql_select_Query)
dirty_text = [i[0] for i in cursor.fetchall() if i[0]]

SYMBOLS = '{}()[].,:;+-*/&|<>=~'
clear_text = []
for element in dirty_text:
    clear_text.append(''.join(ch for ch in element if ch not in SYMBOLS))

cursor.execute ("""
    UPDATE pinsets
    SET passwords=%s
    WHERE pinsets_id=1;
""", (','.join(clear_text),)
)

请注意,这段代码是用Python编写的,用于从数据库中提取数据并进行处理。

英文:

This does what I THINK you were trying to do. This fetches all of the non-NULL values from the "cell" column from "userman_users", removes any special characters from them, and stores them as a comma-separated list in the one row in "pinsets":

connection = mysql.connector.connect(host=&#39;localhost&#39;,
                                 database=&#39;asterisk&#39;,
                                 user=&#39;freepbxuser&#39;,
                                 password=&#39;&#39;,
                                 autocommit=True)
sql_select_Query = &quot;SELECT cell FROM userman_users;&quot;
cursor = connection.cursor()
cursor.execute(sql_select_Query)
dirty_text = [i[0] for i in cursor.fetchall() if i[0]]

SYMBOLS = &#39;{}()[].,:;+-*/&amp;|&lt;&gt;=~&#39;
clear_text = []
for element in dirty_text:
    clear_text.append( &#39;&#39;.join(ch for ch in element if ch not in SYMBOLS) )

cursor.execute (&quot;&quot;&quot;
    UPDATE pinsets
    SET passwords=%s
    WHERE pinsets_id=1;
&quot;&quot;&quot;, (&#39;,&#39;.join(clear_text),)
)

huangapple
  • 本文由 发表于 2023年8月5日 02:09:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定