Right now I’m using Microsoft SQL Community to start a database, but for some reason I can’t command the server to do something that I want, is there any to use the library sqlite3 or pyodc to print a value that I want on the console?
PYTHON:
JavaScript
x
10
10
1
connection = sqlite3.connect("REPLICATED_STORAGE.db")
2
cursor = connection.cursor()
3
4
sql_file = open("Template.sql")
5
sql_as_string = sql_file.read()
6
cursor.executescript(sql_as_string)
7
8
for row in cursor.execute("SELECT * FROM FRUITS"):
9
print(row)
10
SQL:
JavaScript
1
18
18
1
USE [REPLICATED_STORAGE]
2
GO
3
4
SET ANSI_NULLS ON
5
GO
6
7
SET QUOTED_IDENTIFIER ON
8
GO
9
10
CREATE TABLE [dbo].[FRUITS](
11
[COLOR] [nchar](10) NOT NULL,
12
[TYPE] [nchar](10) NULL,
13
[NAME] [nchar](10) NULL,
14
[WEIGHT] [nchar](10) NULL
15
) ON [PRIMARY]
16
GO
17
18
Advertisement
Answer
sqlite3
talks to SQLite databases.
If you want to talk to a Microsoft SQL Server, Microsoft recommends using pyodbc
. Follow the instructions to connect and run queries and the pyodbc documentation. To execute queries from a file, read the contents of the file and run it like any other query.
Note that executescript
is specific to sqlite3. Use execute
.