Sql error or missing database incomplete input

I have loaded a custom function TESTFUNC and used db.exec() to execute a SQL query using it. I have an exception on this line, which is basically the only line I have using the API after loading th...

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Comments

@baptistapedro

I have loaded a custom function TESTFUNC and used db.exec() to execute a SQL query using it.
I have an exception on this line, which is basically the only line I have using the API after loading the func.

index.js:9
db.exec(«SELECT TESTFUNC(‘CREATE TABLE foo(bar TEXT)'»);

incomplete input
SqliteError: incomplete input
    at /home/nasa/sql1te/compiledshit/myapp/routes/index.js:9:8
    at Layer.handle [as handle_request] (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/layer.js:95:5)
    at /home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:335:12)
    at next (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:174:3)
    at router (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:47:12)

@baptistapedro

What’s the right syntax to execute any SQL query? Is it db.exec?

@JoshuaWise

Yeah that’s the right syntax. I don’t know why you’re getting an incomplete input error, but even if you somehow avoided that error, you’d get an error saying This database connection is busy executing a query, unless TESTFUNC executes the SQL on a different database connection.

@baptistapedro

Why would I receive that other error?
TESTFUNC is basically a eval() function?
Is my error related to quotes syntax or something?
I can perfectly execute it on sqlite3 shell.

@JoshuaWise

@baptistapedro

through load_extension too, like you have to load a shared lib.

@baptistapedro

.loadExtension on your api that’s what Im using to load TESTFUNC

@JoshuaWise

Ahhh I see. My guess is that there’s some assumption that the extension is making, which better-sqlite3 doesn’t abide by. But without knowing the extension, it’s impossible to debug.

@baptistapedro

Is that a feature you implemented yourself to verify the extension? If so, there’s a quick way to disallow that feature so that we can see if that’s the problem?

@JoshuaWise

There’s no special logic behind db.loadExtension(). It’s a minimalistic wrapper that simply executes the underling sqlite3 C API.

@baptistapedro

This is my TESTFUNC — https://dpaste.org/uBt8
It doesn’t do anything too fancy. You can even create an extension yourself to do whatever and you might go through the same error.
I believe the quotes on the query are breaking the SQL somehow?

@baptistapedro

Please try load an extension yourself. Im not sure if I need to register the function as said in custom function api?
That’s all that I have:

const Database = require('better-sqlite3');
const db = new Database('foobar.db', {verbose: console.log});
db.loadExtension('./myfunc3');
db.exec("SELECT TESTFUNC('CREATE TABLE foo(bar TEXT)'");

I do not know what that error Incomplete input is about.

@baptistapedro

I honestly think is an issue with the double quotes» » and then the inner ‘
Any other way I can format this?

@wizzard0

um, to me, that query simply misses closing «)» parentneses

@JoshuaWise

doh! I can’t believe I didn’t see that. @wizzard0 is right.

Содержание

  1. Sql logic error incomplete input
  2. Вопрос
  3. SqliteException: SQLite Error 1: ‘incomplete input’.
  4. Все ответы
  5. I am getting (sqlite3.OperationalError: incomplete input) error in Python
  6. Answer by Braylee Hughes
  7. Answer by Giovanna Howard
  8. Answer by Cash Stevenson
  9. Answer by Ethan Wilkinson
  10. Answer by Zachary Vazquez
  11. ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input #38066
  12. Comments
  13. Steps to reproduce
  14. Expected behavior
  15. Actual behavior
  16. System configuration
  17. ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input #38066
  18. Comments
  19. Steps to reproduce
  20. Expected behavior
  21. Actual behavior
  22. System configuration

Sql logic error incomplete input

Вопрос

SqliteException: SQLite Error 1: ‘incomplete input’.

This error on the phrase

using (SqliteDataReader dr = com.ExecuteReader())

Now this exact code worked on another MVC view page and i’m clueless. Im new so I do not know what else information to give you.

Im using mac OS

Все ответы

Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
—————————-
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Although you might get lucky here, this forum is for Microsoft SQL Server Express Edition. SqlLite is an entirely different product.

Источник

I am getting (sqlite3.OperationalError: incomplete input) error in Python

Answer by Braylee Hughes

This is the error I am getting:, Electrical reason for the minimum altitude (-50 feet) in the computer specs? ,Asking for help, clarification, or responding to other answers.,Traceback (most recent call last): File «/Users/My Documents/Independent Learning/BBA Coding Related Work/Creating a Database with SQLite3 for Python/MarketCo1.py», line 89, in »’); sqlite3.OperationalError: incomplete input

You are missing a closing brace, as mentioned by glibdud in the comments:

Answer by Giovanna Howard

What’s the right syntax to execute any SQL query? Is it db.exec?,I have loaded a custom function TESTFUNC and used db.exec() to execute a SQL query using it. I have an exception on this line, which is basically the only line I have using the API after loading the func.,@baptistapedro I was under the assumption that TESTFUNC was a custom function. How can you execute a custom function from the sqlite3 shell?,Please try load an extension yourself. Im not sure if I need to register the function as said in custom function api? That’s all that I have:

Answer by Cash Stevenson

These are the two lines where the error is shown I did read an answer here on stackoverflow but the error wasnt rectified., Save my name, email, and website in this browser for the next time I comment.,Your email address will not be published. Required fields are marked *

Answer by Ethan Wilkinson

Answer by Zachary Vazquez

What is it that I am getting wrong? The following is the code:,I am fairly new to python and am writing a code to read imagery and insert them into an SQLite database but I get the following error ,First, the name index is reserved by SQLite ( SQLite: create Index ). ,Connect and share knowledge within a single location that is structured and easy to search.

It’s not %s in your SQL prepared statements, it’s ? .

Источник

ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input #38066

Hi everyone,
I did setup a fresh rails project (—api)
Rails 5.2.4

wrote some routes,
wrote some assert_routing tests,
everything was fine.

generated a model «releases»
all tests immediately did fail with:
ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input: INSERT INTO «releases»

The culprit was fixtures/releases.yml
When I removed that file, that error messages vanished.

I’d like to suggest to improve the error messages of running «rails test»
to make it more easy to diagnose the root causes of the problems.

My error message must have come from deep down of the sqlite adapter as an exception.
But it was triggered from some rails code working with fixtures.

I’d suggest to catch exceptions and wrap them,
so to annotate where they where invoked from.

the breaking fixture was:
one: <>
two: <>

I never needed fixtures, yet.
I don’t even know what they are good for, yet.

So why was that code generated in the first place?
to only break my workflow and all my tests?

Again, that bad thing for me was the error message:
ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input

I’m sure we can improve on that.
Let’s make it a test case first,
so that we can reliabably trigger that error message again.

I have to go on,
my workaround was to delete the fixtures/ file

Steps to reproduce

generate a fresh rails project
cz
generate a model
(obviously some of my intermediate steps which I can not yet reproduce made this fails)
x

Expected behavior

Actual behavior

System configuration

Rails version:

Ruby version:

The text was updated successfully, but these errors were encountered:

Источник

ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input #38066

Hi everyone,
I did setup a fresh rails project (—api)
Rails 5.2.4

wrote some routes,
wrote some assert_routing tests,
everything was fine.

generated a model «releases»
all tests immediately did fail with:
ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input: INSERT INTO «releases»

The culprit was fixtures/releases.yml
When I removed that file, that error messages vanished.

I’d like to suggest to improve the error messages of running «rails test»
to make it more easy to diagnose the root causes of the problems.

My error message must have come from deep down of the sqlite adapter as an exception.
But it was triggered from some rails code working with fixtures.

I’d suggest to catch exceptions and wrap them,
so to annotate where they where invoked from.

the breaking fixture was:
one: <>
two: <>

I never needed fixtures, yet.
I don’t even know what they are good for, yet.

So why was that code generated in the first place?
to only break my workflow and all my tests?

Again, that bad thing for me was the error message:
ActiveRecord::StatementInvalid: SQLite3::SQLException: incomplete input

I’m sure we can improve on that.
Let’s make it a test case first,
so that we can reliabably trigger that error message again.

I have to go on,
my workaround was to delete the fixtures/ file

Steps to reproduce

generate a fresh rails project
cz
generate a model
(obviously some of my intermediate steps which I can not yet reproduce made this fails)
x

Expected behavior

Actual behavior

System configuration

Rails version:

Ruby version:

The text was updated successfully, but these errors were encountered:

Источник

Sql logic error incomplete input

Вопрос

SqliteException: SQLite Error 1: ‘incomplete input’.

This error on the phrase

using (SqliteDataReader dr = com.ExecuteReader())

Now this exact code worked on another MVC view page and i’m clueless. Im new so I do not know what else information to give you.

Im using mac OS

Все ответы

Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
—————————-
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Although you might get lucky here, this forum is for Microsoft SQL Server Express Edition. SqlLite is an entirely different product.

Источник

SQLite error: incomplete input #333

Comments

baptistapedro commented Dec 19, 2019

I have loaded a custom function TESTFUNC and used db.exec() to execute a SQL query using it.
I have an exception on this line, which is basically the only line I have using the API after loading the func.

index.js:9
db.exec(«SELECT TESTFUNC(‘CREATE TABLE foo(bar TEXT)’»);

The text was updated successfully, but these errors were encountered:

baptistapedro commented Dec 19, 2019

What’s the right syntax to execute any SQL query? Is it db.exec?

JoshuaWise commented Dec 19, 2019

Yeah that’s the right syntax. I don’t know why you’re getting an incomplete input error, but even if you somehow avoided that error, you’d get an error saying This database connection is busy executing a query , unless TESTFUNC executes the SQL on a different database connection.

baptistapedro commented Dec 19, 2019

Why would I receive that other error?
TESTFUNC is basically a eval() function?
Is my error related to quotes syntax or something?
I can perfectly execute it on sqlite3 shell.

JoshuaWise commented Dec 19, 2019

@baptistapedro I was under the assumption that TESTFUNC was a custom function. How can you execute a custom function from the sqlite3 shell?

baptistapedro commented Dec 19, 2019

through load_extension too, like you have to load a shared lib.

baptistapedro commented Dec 19, 2019

.loadExtension on your api that’s what Im using to load TESTFUNC

JoshuaWise commented Dec 19, 2019

Ahhh I see. My guess is that there’s some assumption that the extension is making, which better-sqlite3 doesn’t abide by. But without knowing the extension, it’s impossible to debug.

baptistapedro commented Dec 19, 2019

Is that a feature you implemented yourself to verify the extension? If so, there’s a quick way to disallow that feature so that we can see if that’s the problem?

JoshuaWise commented Dec 19, 2019

There’s no special logic behind db.loadExtension() . It’s a minimalistic wrapper that simply executes the underling sqlite3 C API.

baptistapedro commented Dec 19, 2019

This is my TESTFUNC — https://dpaste.org/uBt8
It doesn’t do anything too fancy. You can even create an extension yourself to do whatever and you might go through the same error.
I believe the quotes on the query are breaking the SQL somehow?

baptistapedro commented Dec 19, 2019

Please try load an extension yourself. Im not sure if I need to register the function as said in custom function api?
That’s all that I have:

I do not know what that error Incomplete input is about.

baptistapedro commented Dec 19, 2019

I honestly think is an issue with the double quotes» » and then the inner ‘
Any other way I can format this?

wizzard0 commented Jan 7, 2020

um, to me, that query simply misses closing «)» parentneses

JoshuaWise commented Jan 7, 2020

doh! I can’t believe I didn’t see that. @wizzard0 is right.

Footer

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

I am getting (sqlite3.OperationalError: incomplete input) error in Python

Answer by Braylee Hughes

This is the error I am getting:, Electrical reason for the minimum altitude (-50 feet) in the computer specs? ,Asking for help, clarification, or responding to other answers.,Traceback (most recent call last): File «/Users/My Documents/Independent Learning/BBA Coding Related Work/Creating a Database with SQLite3 for Python/MarketCo1.py», line 89, in »’); sqlite3.OperationalError: incomplete input

You are missing a closing brace, as mentioned by glibdud in the comments:

Answer by Giovanna Howard

What’s the right syntax to execute any SQL query? Is it db.exec?,I have loaded a custom function TESTFUNC and used db.exec() to execute a SQL query using it. I have an exception on this line, which is basically the only line I have using the API after loading the func.,@baptistapedro I was under the assumption that TESTFUNC was a custom function. How can you execute a custom function from the sqlite3 shell?,Please try load an extension yourself. Im not sure if I need to register the function as said in custom function api? That’s all that I have:

Answer by Cash Stevenson

These are the two lines where the error is shown I did read an answer here on stackoverflow but the error wasnt rectified., Save my name, email, and website in this browser for the next time I comment.,Your email address will not be published. Required fields are marked *

Answer by Ethan Wilkinson

Answer by Zachary Vazquez

What is it that I am getting wrong? The following is the code:,I am fairly new to python and am writing a code to read imagery and insert them into an SQLite database but I get the following error ,First, the name index is reserved by SQLite ( SQLite: create Index ). ,Connect and share knowledge within a single location that is structured and easy to search.

It’s not %s in your SQL prepared statements, it’s ? .

Источник

[Solved] sqlite3.OperationalError: incomplete input on my code

Stephen Martinez

Guest

Stephen Martinez Asks: sqlite3.OperationalError: incomplete input on my code
Can someone help me understand what’s incomplete about my code, no matter what I try I keep getting the sqlite3.OperationalError: incomplete input. My code is

The line that sublime is referring to is the one I’ve drawn an arrow to, if anyone could help that would be great!

Unreplied Threads

NLP vs Keyword-Search. which one is the best?

  • Lakshitha Samod
  • 27 minutes ago
  • Computer Science
  • Replies: 0

Lakshitha Samod Asks: NLP vs Keyword-Search. which one is the best?
I have constructed a natural language processing (NLP) model with the aim of identifying technology keywords within text. The model is trained on a large dataset that contains over 400,000 phrases and has been annotated with approximately 1000 technology keywords, of which only the keywords that I provided in the dataset, can be identified. The annotations within the training dataset include specific locations of technology keywords in the phrases, like for example in the below example, the technology keyword «php» is located at positions 0-3 and 43-46.

An alternative very simple approach that I considered is to manually search for the technology keywords within the text, by using a set of predefined keywords and checking the text in a loop. However, I am wondering of which approach would be more efficient and effective. Given the large dataset and a vast number of keywords, I wonder which of these two methods would yield the best results and would be more appropriate.

Encoder-Decoder performance time

  • Sabrina
  • 27 minutes ago
  • Computer Science
  • Replies: 0

Sabrina Asks: Encoder-Decoder performance time
I have two encoder-decoder models.

When I check the performance of the models I get approximately the same performance time (First model

42 sec, Second model

40 sec). I train my model on GPU and check performance on CPU. I test it only on one large image where the size is 12348×12348. I was expecting the larger model that has more parameters to train (second model) to give me longer run time. Anyone can help me to understand why it is not the case here? Am I doing something wrong?

[Solved] How GEE align pixels and projection when reduce resolution?

  • hydro9
  • 27 minutes ago
  • Geography
  • Replies: 0

424, larger than the theoretical value. When implemented in arcgis, the sum zonal statistics returns 272

289, which makes more sense considering the actual MODIS pixel size is

What is ds=dr/cos(theta)

  • user355484
  • 27 minutes ago
  • Physics
  • Replies: 0

user355484 Asks: What is ds=dr/cos(theta)
I am currently learning about work applied to moving charges closer and have been able to follow so far, but towards the end of the section I was confronted by —Fds, ds=dr/cos(theta) and Fds=Fdr and I am unsure what ds is referring to. For reference, I am using «Electricity and Magnetism 3rd Edition» by Purcell and Morin

What’s happening to the potential energy of electrons after they left battery?

  • nam ko
  • 27 minutes ago
  • Physics
  • Replies: 0

nam ko Asks: What’s happening to the potential energy of electrons after they left battery?
friends. I am new in the electrical field so I must show my guided point of sides that related to my question before I ask it, for understanding how I think. first, let’s begin with the battery, I learned that after chemical interactions the battery will produce electrons so these electrons will be get accumulated in the same wherein negative terminal of the battery so after that and because they have the same charge so, therefore, they will get energy(electric potential energy ) because that the charged particle they will get electric potential energy if they are in electric field that produced by other charged particle so because the electrons are accumulated then they will get a lot of electric potential energy because they are in an electric field that created by other electrons at the same place so they will try to use this energy to push other electrons and so electrons will use this energy to push other electrons to the circuit but after they do this I heard that electric potential energy will convert to the kinetic energy but how this will work because (the kinetic energy=mass0.5velocity^2) and because these electrons have constant drift velocity. and its thermal velocity is affected by the thermal energy of the substance nor the voltage. so haw the electric potential energy will convert to the kinetic energy and there is the velocity of electrons is not changing cause voltage and the velocity of electrons are called by the thermal velocity that caused by the thermal energy nor the voltage so what happens to this electric potential energy?

I learned that the speed of electrons is very high but are random and we call it thermal velocity because it is caused by thermal energy(temperature of material) and is affected by temperature

also drift velocity is just moving electrons(electrons are moving randomly and the electric field are push them but the electrons still in random motion) toward the positive terminal(depending on the electric field). so the electrons are in random motions and because the electric field makes them go toward the positive terminal and the moving electrons toward positive we call it drift velocity and it is constant

now, what happens to these electrons’ electric potential energy after they leave the battery? it is converted to kinetic energy but how and the speed of electrons isn’t depending on the voltage(thermal velocity..)

does it remain electric potential energy because of the other electrons in the conductor? but after the electrons go through the loads then they lost the energy and there are still electrons in a conductor because there are electrons there and I mentioned that if a charged particle is in the electric field of another charged particle then it has electric potential energy but here they lost the energy and the electric field still here

sorry for my English(I am not English). I searched a lot about this but I didn’t get anything. I hope u understand what I am meaning also there are many things in my head but I can’t translate them to English because there is no translation yet for my native language

Источник

Sql Logic Error Incomplete Input Best Recipes

Recently Recipes

Cute chocolate «cauldrons» hold a cool, creamy orange-flavored yogurt in this recipe. The unfilled cups.

Provided by Taste of Home

Provided by Catherine McCord

This is my technique for veal demi-glace, and there’s not much to it. I’m going for a pure veal stock.

Provided by Chef John

OMG. I had to make this cake this past Sunday for my Mary Kay party.. It was a huge hit. It was also.

Provided by vicky hunt

Good food doesn’t always have to cost a fortune! Your family will love this. Full of flavor and easy.

Provided by Melissa Baldan

This is a very good potato dish , I stem baby red potatoes and smother them in real butter and parsley.

Provided by Karla Everett

Provided by á-174942

Try this Instant Pot®-friendly variation of a traditional bean stew from the Portuguese region of Azores.

Provided by Ryan C Mathews

Provided by Florence Fabricant

A unique twist on a classic white chocolate fudge recipe! While quick and easy to prepare, Bruce’s®.

Provided by Bruce’s Yams

Sure you can make a quick Chicken Pot Pie using already made pie crust, canned soups, vegetables and.

Provided by Julia Ferguson

This delicious red velvet pound cake is the perfect combination of flavors. Make sure the cake has cooled.

Provided by Taste of Home

Dis is da toe curlin Texicajun hybrid of a classic dish. This will put a smile on everyone’s face that’s.

Provided by Lupe Boudreaux

Provided by Kemp Minifie

This is a tender and delicious baked pork chop recipe, with an Italian flair.

Источник

Answer by Braylee Hughes

This is the error I am getting:,

Electrical reason for the minimum altitude (-50 feet) in the computer specs?

,Asking for help, clarification, or responding to other answers.,Traceback (most recent call last): File «/Users/My
Documents/Independent Learning/BBA Coding Related Work/Creating a
Database with SQLite3 for Python/MarketCo1.py», line 89, in
»’); sqlite3.OperationalError: incomplete input

You are missing a closing brace, as mentioned by glibdud in the comments:

cursor.execute('''CREATE TABLE ContactEmployee(
  ContactEmployeeID INTEGER PRIMARY KEY, 
  ContactID INTEGER, EmployeeID INTEGER, 
  ContactDate NUMERIC, 
  Description TEXT,  
  FOREIGN KEY(ContactID) REFERENCES Contact(ContactID), 
  FOREIGN KEY(EmployeeID) REFERENCES Employee(EmployeeID))
  ''')
db.commit()

Answer by Giovanna Howard

What’s the right syntax to execute any SQL query? Is it db.exec?,I have loaded a custom function TESTFUNC and used db.exec() to execute a SQL query using it.
I have an exception on this line, which is basically the only line I have using the API after loading the func.,@baptistapedro I was under the assumption that TESTFUNC was a custom function. How can you execute a custom function from the sqlite3 shell?,Please try load an extension yourself. Im not sure if I need to register the function as said in custom function api?
That’s all that I have:

incomplete input
SqliteError: incomplete input
    at /home/nasa/sql1te/compiledshit/myapp/routes/index.js:9:8
    at Layer.handle [as handle_request] (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/layer.js:95:5)
    at /home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:335:12)
    at next (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:174:3)
    at router (/home/nasa/sql1te/compiledshit/myapp/node_modules/express/lib/router/index.js:47:12)

Answer by Cash Stevenson

These are the two lines where the error is shown I did read an answer here on stackoverflow but the error wasnt rectified., Save my name, email, and website in this browser for the next time I comment.,Your email address will not be published. Required fields are marked *

c.execute("SELECT * FROM addresses WHERE oid = " + record_id)


c.execute("DELETE from addresses WHERE oid = " + delete_box.get)

Answer by Ethan Wilkinson

def _DetectApplicationUsageTable(self, conn):
    """Detect whether the application usage table exists.

    Args:
      conn: sqlite3.Connection object
    Returns:
      True if the table exists, False if not.
    Raises:
      sqlite3.Error: if error occurs
    """
    try:
      conn.execute(APPLICATION_USAGE_TABLE_DETECT)
      exists = True
    except sqlite3.OperationalError, e:
      if e.args[0].startswith('no such table'):
        exists = False
      else:
        raise 

Answer by Zachary Vazquez

What is it that I am getting wrong? The following is the code:,I am fairly new to python and am writing a code to read imagery and insert them into an SQLite database but I get the following error ,First, the name index is reserved by SQLite ( SQLite: create Index ). ,Connect and share knowledge within a single location that is structured and easy to search.

It’s not %s in your SQL prepared statements, it’s ?.

statement = "INSERT INTO %s (%s) VALUES (?, ?, ?);" % (table,columns)

Answer by Anderson Alvarado

Currently, I am trying to create a program that allows the user to input customer information (First Name, Last Name, Address, and Post Code). I am completely confused on how to enter variables/lists into the database.,This takes care of the auto-incremented id and has everything you need to create/read/update/delete any customer you need to.,I am not sure on how to enter the data from the list into the database or whether I should create variables and enter them. That is the reason as to why I have variables and the list. I was trying out both ways and neither worked for me.,EDIT:I finally fixed it thanks to /u/behold_the_j by using the variable enterCustomer and then using enterCustomer.first_name.

Old Code:

import csv

class customer:
    def __init__(self, first_name, last_name, address, post_code):
        self.first_name = first_name
        self.last_name = last_name
        self.address = address
        self.post_code = post_code

    def __str__(self):
        return '{},{},{},{}'.format(
            self.first_name,
            self.last_name,
            self.address,
            self.post_code
        )


customer_list= []

def enterInfo():
    customer_list.append(customer(
        input("First Name: "),
        input("Last Name: "),
        input("Address (<NUMBER> <STREET NAME>): "),
        input("Post Code: ")
    ))

addInfo = input("Add info? ")
if addInfo == "y":
    enterInfo()

for each_line in customer_list:
    print(each_line)

customer_file = open("Customer Info.csv", "a")
writeInfo = 'n'.join([str(line) for line in customer_list])+'n'
customer_file.write(writeInfo)
customer_file.close()

New Code (NOT WORKING):

import sqlite3

def deleteTable():
    # Delete 'Customer_Info' Table if it exists
    cursorVariable.execute("DROP TABLE IF EXISTS Customer_Info")
    connectDatabase.commit()
    print("Database deleted")

connectDatabase = sqlite3.connect("test.db")
print("Database opened")

# Cursor used to edit the records
cursorVariable = connectDatabase.cursor()

askDeleteTable = input("Delete the table? ")
if askDeleteTable in "Yy":
    deleteTable()

# Create 'Customer_Info' Table if it doesn't exist
cursorVariable.execute("CREATE TABLE IF NOT EXISTS Customer_Info('ID' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
                       "'First Name' TEXT NOT NULL, 'Last Name' TEXT, 'Address' TEXT, 'Post Code' TEXT);")

# Do whatever it says in the closest 'execute' command that came before this 'commit' command
# Use Database Connection variable
connectDatabase.commit()

print("Table created")


class customer:
    def __init__(self, first_name, last_name, address, post_code):
        self.first_name = first_name
        self.last_name = last_name
        self.address = address
        self.post_code = post_code

    def __str__(self):
        return '{},{},{},{}'.format(
            self.first_name,
            self.last_name,
            self.address,
            self.post_code
        )


customer_list= []

def enterInfo():
    customer_list.append(customer(
        input("First Name: "),
        input("Last Name: "),
        input("Address (<NUMBER> <STREET NAME>): "),
        input("Post Code: ")
    ))


addInfo = input("Add info? ")
if addInfo == "y":
    enterInfo()

firstName = input("First Name: ")
lastName = input("Last Name: ")
Address = input("Address (<NUMBER> <STREET NAME>): ")
postCode = input("Post Code: ")

cursorVariable.execute("INSERT INTO Customer_Info(First Name, Last Name, Address, Post Code) VALUES (?, ?, ?, ?)", 
                       (firstName, lastName, Address, postCode))

connectDatabase.commit()

for each_line in customer_list:
    print(each_line)

writeInfo = "n".join([str(line) for line in customer_list])+"n"


while False:
    # Close database
    cursorVariable.close()
    print("Database closed")

The part I am not understanding:

customer_list= []

def enterInfo():
    customer_list.append(customer(
        input("First Name: "),
        input("Last Name: "),
        input("Address (<NUMBER> <STREET NAME>): "),
        input("Post Code: ")
    ))


addInfo = input("Add info? ")
if addInfo == "y":
    enterInfo()

firstName = input("First Name: ")
lastName = input("Last Name: ")
Address = input("Address (<NUMBER> <STREET NAME>): ")
postCode = input("Post Code: ")

cursorVariable.execute("INSERT INTO Customer_Info(First Name, Last Name, Address, Post Code) VALUES (?, ?, ?, ?)", 
                       (firstName, lastName, Address, postCode))

EDIT:I finally fixed it thanks to /u/behold_the_j by using the variable enterCustomer and then using enterCustomer.first_name.

def enterInfo():
    global enterCustomer

    enterCustomer = customer(input("First Name: "),
                             input("Last Name: "),
                             input("Address (<NUMBER> <STREET NAME>): "),
                             input("Post Code: ")
                             )


addInfo = input("Add info? ")
if addInfo == "y":
    enterInfo()

cursorVariable.execute("INSERT INTO Customer_Info('First Name', 'Last Name', 'Address', 'Post Code') VALUES (?, ?, ?, ?)",
                       (enterCustomer.first_name, enterCustomer.last_name,
                        enterCustomer.address, enterCustomer.post_code)

Понравилась статья? Поделить с друзьями:
  • Sql error near table syntax error
  • Sql error mysqli connection refused 2002
  • Sql error message oracle
  • Sql error library routine called out of sequence
  • Sql error invalid cursor