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

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

Why is data is not added to the cell?

问题

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

  1. #/usr/bin/python3
  2. import mysql.connector
  3. try:
  4. connection = mysql.connector.connect(host='localhost',
  5. database='asterisk',
  6. user='freepbxuser',
  7. password='',
  8. autocommit=True)
  9. sql_select_Query = "SELECT CONCAT(cell) FROM userman_users"
  10. cursor = connection.cursor()
  11. cursor.execute(sql_select_Query)
  12. dirty_text = [i[0] for i in cursor.fetchall()]
  13. for item in dirty_text.copy():
  14. if item is None:
  15. dirty_text.remove(item)
  16. SYMBOLS = '{}()[].,:;+-*/&|<>=~'
  17. clear_text = []
  18. for element in dirty_text:
  19. temp = ""
  20. for ch in element:
  21. if ch not in SYMBOLS:
  22. temp += ch
  23. clear_text.append(temp)
  24. values = [list([item]) for item in clear_text]
  25. cursor.executemany ("""
  26. UPDATE pinsets
  27. SET passwords=%s
  28. WHERE pinsets_id=1
  29. """, (values))
  30. except mysql.connector.Error as e:
  31. print("Error", e)
  32. finally:
  33. if connection.is_connected():
  34. connection.close()
  35. 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

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

  1. #/usr/bin/python3
  2. import mysql.connector
  3. try:
  4. connection = mysql.connector.connect(host=&#39;localhost&#39;,
  5. database=&#39;asterisk&#39;,
  6. user=&#39;freepbxuser&#39;,
  7. password=&#39;&#39;,
  8. autocommit=True)
  9. sql_select_Query = &quot;SELECT CONCAT(cell) FROM userman_users&quot;
  10. cursor = connection.cursor()
  11. cursor.execute(sql_select_Query)
  12. dirty_text = [i[0] for i in cursor.fetchall()]
  13. for item in dirty_text.copy():
  14. if item is None:
  15. dirty_text.remove(item)
  16. SYMBOLS = &#39;{}()[].,:;+-*/&amp;|&lt;&gt;=~&#39;
  17. clear_text = []
  18. for element in dirty_text:
  19. temp = &quot;&quot;
  20. for ch in element:
  21. if ch not in SYMBOLS:
  22. temp += ch
  23. clear_text.append(temp)
  24. values = [list([item]) for item in clear_text]
  25. cursor.executemany (&quot;&quot;&quot;
  26. UPDATE pinsets
  27. SET passwords=%s
  28. WHERE pinsets_id=1
  29. &quot;&quot;&quot;, (values))
  30. except mysql.connector.Error as e:
  31. print(&quot;Error&quot;, e)
  32. finally:
  33. if connection.is_connected():
  34. connection.close()
  35. cursor.close()

答案1

得分: 1

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

  1. connection = mysql.connector.connect(host='localhost',
  2. database='asterisk',
  3. user='freepbxuser',
  4. password='',
  5. autocommit=True)
  6. sql_select_Query = "SELECT cell FROM userman_users;"
  7. cursor = connection.cursor()
  8. cursor.execute(sql_select_Query)
  9. dirty_text = [i[0] for i in cursor.fetchall() if i[0]]
  10. SYMBOLS = '{}()[].,:;+-*/&|<>=~'
  11. clear_text = []
  12. for element in dirty_text:
  13. clear_text.append(''.join(ch for ch in element if ch not in SYMBOLS))
  14. cursor.execute ("""
  15. UPDATE pinsets
  16. SET passwords=%s
  17. WHERE pinsets_id=1;
  18. """, (','.join(clear_text),)
  19. )

请注意,这段代码是用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":

  1. connection = mysql.connector.connect(host=&#39;localhost&#39;,
  2. database=&#39;asterisk&#39;,
  3. user=&#39;freepbxuser&#39;,
  4. password=&#39;&#39;,
  5. autocommit=True)
  6. sql_select_Query = &quot;SELECT cell FROM userman_users;&quot;
  7. cursor = connection.cursor()
  8. cursor.execute(sql_select_Query)
  9. dirty_text = [i[0] for i in cursor.fetchall() if i[0]]
  10. SYMBOLS = &#39;{}()[].,:;+-*/&amp;|&lt;&gt;=~&#39;
  11. clear_text = []
  12. for element in dirty_text:
  13. clear_text.append( &#39;&#39;.join(ch for ch in element if ch not in SYMBOLS) )
  14. cursor.execute (&quot;&quot;&quot;
  15. UPDATE pinsets
  16. SET passwords=%s
  17. WHERE pinsets_id=1;
  18. &quot;&quot;&quot;, (&#39;,&#39;.join(clear_text),)
  19. )

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:

确定