sqlite

Data not saving SQLite3 python3.4

一个人想着一个人 提交于 2021-02-05 08:10:32
问题 I am currently trying to create a sqlite database of peoples names and ip While my code seems to work when I run it the data doesn't show up when I run SELECT * from ips; in terminal after running SQLite3 ips Below is my code. Both it and the SELECT * from ips; are running in ~/Desktop/SQL import sqlite3 as sql import socket import struct def iptoint(ip): return str(struct.unpack("i",socket.inet_aton(ip))[0]) database = sql.connect("ips") createTable = True if createTable: database.execute(''

Data not saving SQLite3 python3.4

北战南征 提交于 2021-02-05 08:04:59
问题 I am currently trying to create a sqlite database of peoples names and ip While my code seems to work when I run it the data doesn't show up when I run SELECT * from ips; in terminal after running SQLite3 ips Below is my code. Both it and the SELECT * from ips; are running in ~/Desktop/SQL import sqlite3 as sql import socket import struct def iptoint(ip): return str(struct.unpack("i",socket.inet_aton(ip))[0]) database = sql.connect("ips") createTable = True if createTable: database.execute(''

Import CSV into SQLite in Java

那年仲夏 提交于 2021-02-04 19:58:36
问题 I'm starting learning Java and need some help. I need to import CSV file into SQLite database. I have this CSV reader, but i don't know how to copy this data into SQLite database. import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class csv { public static void main(String[] args) { String csvFile = "/home/user/user.csv"; BufferedReader br = null; String line = ""; String cvsSplitBy = ","; try { br = new

Import CSV into SQLite in Java

白昼怎懂夜的黑 提交于 2021-02-04 19:56:30
问题 I'm starting learning Java and need some help. I need to import CSV file into SQLite database. I have this CSV reader, but i don't know how to copy this data into SQLite database. import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class csv { public static void main(String[] args) { String csvFile = "/home/user/user.csv"; BufferedReader br = null; String line = ""; String cvsSplitBy = ","; try { br = new

How do you cleanly pass column names into cursor, Python/SQLite?

允我心安 提交于 2021-02-04 19:14:46
问题 I'm new to cursors and I'm trying to practice by building a dynamic python sql insert statement using a sanitized method for sqlite3: import sqlite3 conn = sqlite3.connect("db.sqlite") cursor = conn.cursor() list = ['column1', 'column2', 'column3', 'value1', 'value2', 'value3'] cursor.execute("""insert into table_name (?,?,?) values (?,?,?)""", list) When I attempt to use this, I get a syntax error "sqlite3.OperationalError: near "?"" on the line with the values. This is despite the fact that

Python - How to print Sqlite table

淺唱寂寞╮ 提交于 2021-02-04 17:38:09
问题 Here I have some simple python code to query a sqlite3 database. import sqlite3 as lite conn = lite.connect('db/posts.db') cur = conn.cursor() def get_posts(): cur.execute("SELECT * FROM Posts") print(cur.fetchall()) get_posts() I have already created the table Posts . When I run this I get no errors, and it just prints out [] . I know that the table Posts isn't empty, I created it in a REPL. Why is this not working? Any help is appreciated! 回答1: Use a context manager, so you don´t have to

Should I call connect() and close() for every Sqlite3 transaction?

泪湿孤枕 提交于 2021-02-04 16:31:20
问题 I want to write a Python module to abstract away database transactions for my application. My question is whether I need to call connect() and close() for every transaction? In code: import sqlite3 # Can I put connect() here? conn = sqlite3.connect('db.py') def insert(args): # Or should I put it here? conn = sqlite3.connect('db.py') # Perform the transaction. c = conn.cursor() c.execute(''' insert args ''') conn.commit() # Do I close the connection here? conn.close() # Or can I close the

Android sqlite getdatabase called recursively

血红的双手。 提交于 2021-02-04 16:10:24
问题 I have got a problem with my database. When the app start it should create the database with the tables if they not exist, but the app chrashes instantly after start. When i close the db after opening logcat tells me that "i want to open an already closed object" and when I do not close the database I have got the error " getReadableDatabase called recursively ". I do not know what I should do. Sometimes it works but when I unistall the app and install them again the errors apear. The error

Android sqlite getdatabase called recursively

梦想与她 提交于 2021-02-04 16:08:55
问题 I have got a problem with my database. When the app start it should create the database with the tables if they not exist, but the app chrashes instantly after start. When i close the db after opening logcat tells me that "i want to open an already closed object" and when I do not close the database I have got the error " getReadableDatabase called recursively ". I do not know what I should do. Sometimes it works but when I unistall the app and install them again the errors apear. The error

Removing the top row of a table in sqlite

核能气质少年 提交于 2021-02-04 08:23:05
问题 I can't figure out how to remove the very top row of a table in SQLite. I have the table populated and I just want to remove off the top of the table to work my way down. Here is what I assume would've worked, but did not. DELETE FROM images WHERE rowid <= 1 DELETE FROM images LIMIT 1 Any help would be greatly appreciated. 回答1: SQLite DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete the selected rows. otherwise, all the