Restriciting Number of Characters entered into SQLite3
up vote
1
down vote
favorite
I'm trying to create an SQL database with the following fields:
connection= sqlite3.connect('Main Database')
crsr = connection.cursor()
#Creates a table for the teacher data if no table is found on the system
crsr.execute("""CREATE TABLE IF NOT EXISTS Teacher_Table(Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL,
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL);""")
connection.commit()
connection.close()
But when I input values, the gender field accepts more than one value
Database View
How can I make sure it only accepts one character for that field
python tkinter sqlite3
New contributor
add a comment |
up vote
1
down vote
favorite
I'm trying to create an SQL database with the following fields:
connection= sqlite3.connect('Main Database')
crsr = connection.cursor()
#Creates a table for the teacher data if no table is found on the system
crsr.execute("""CREATE TABLE IF NOT EXISTS Teacher_Table(Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL,
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL);""")
connection.commit()
connection.close()
But when I input values, the gender field accepts more than one value
Database View
How can I make sure it only accepts one character for that field
python tkinter sqlite3
New contributor
1
SqlLite ignores the length constraints sqlite.org/datatype3.html
– Willem Van Onsem
2 days ago
What do you want to happen if an attempt is made to insert more than one character: get an error or silently truncate to one character?
– varro
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to create an SQL database with the following fields:
connection= sqlite3.connect('Main Database')
crsr = connection.cursor()
#Creates a table for the teacher data if no table is found on the system
crsr.execute("""CREATE TABLE IF NOT EXISTS Teacher_Table(Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL,
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL);""")
connection.commit()
connection.close()
But when I input values, the gender field accepts more than one value
Database View
How can I make sure it only accepts one character for that field
python tkinter sqlite3
New contributor
I'm trying to create an SQL database with the following fields:
connection= sqlite3.connect('Main Database')
crsr = connection.cursor()
#Creates a table for the teacher data if no table is found on the system
crsr.execute("""CREATE TABLE IF NOT EXISTS Teacher_Table(Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL,
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL);""")
connection.commit()
connection.close()
But when I input values, the gender field accepts more than one value
Database View
How can I make sure it only accepts one character for that field
python tkinter sqlite3
python tkinter sqlite3
New contributor
New contributor
New contributor
asked 2 days ago
Osasenaga Emokpae
61
61
New contributor
New contributor
1
SqlLite ignores the length constraints sqlite.org/datatype3.html
– Willem Van Onsem
2 days ago
What do you want to happen if an attempt is made to insert more than one character: get an error or silently truncate to one character?
– varro
2 days ago
add a comment |
1
SqlLite ignores the length constraints sqlite.org/datatype3.html
– Willem Van Onsem
2 days ago
What do you want to happen if an attempt is made to insert more than one character: get an error or silently truncate to one character?
– varro
2 days ago
1
1
SqlLite ignores the length constraints sqlite.org/datatype3.html
– Willem Van Onsem
2 days ago
SqlLite ignores the length constraints sqlite.org/datatype3.html
– Willem Van Onsem
2 days ago
What do you want to happen if an attempt is made to insert more than one character: get an error or silently truncate to one character?
– varro
2 days ago
What do you want to happen if an attempt is made to insert more than one character: get an error or silently truncate to one character?
– varro
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
How can I make sure it only accepts one character for that field
SQLite does not check the length constraints defined at type level, as is specified in the documentation on types:
(...) Note that numeric arguments in parentheses that following the type name (ex: "
VARCHAR(255)
") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large globalSQLITE_MAX_LENGTH
limit) on the length of strings, BLOBs or numeric values.
So you can not enforce this at the database level. You will thus need to enforce this through your views, etc.
We can however, like @Ilja Everilä says, use a CHECK
constraint:
CREATE TABLE IF NOT EXISTS Teacher_Table(
Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL CHECK (length(Gender) < 2),
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL
)
Would aCHECK
constraint work in SQLite?
– Ilja Everilä
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignoresCHECK
, making the "SQL landscape" quite chaotic :s.
– Willem Van Onsem
2 days ago
1
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
How can I make sure it only accepts one character for that field
SQLite does not check the length constraints defined at type level, as is specified in the documentation on types:
(...) Note that numeric arguments in parentheses that following the type name (ex: "
VARCHAR(255)
") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large globalSQLITE_MAX_LENGTH
limit) on the length of strings, BLOBs or numeric values.
So you can not enforce this at the database level. You will thus need to enforce this through your views, etc.
We can however, like @Ilja Everilä says, use a CHECK
constraint:
CREATE TABLE IF NOT EXISTS Teacher_Table(
Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL CHECK (length(Gender) < 2),
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL
)
Would aCHECK
constraint work in SQLite?
– Ilja Everilä
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignoresCHECK
, making the "SQL landscape" quite chaotic :s.
– Willem Van Onsem
2 days ago
1
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
add a comment |
up vote
2
down vote
How can I make sure it only accepts one character for that field
SQLite does not check the length constraints defined at type level, as is specified in the documentation on types:
(...) Note that numeric arguments in parentheses that following the type name (ex: "
VARCHAR(255)
") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large globalSQLITE_MAX_LENGTH
limit) on the length of strings, BLOBs or numeric values.
So you can not enforce this at the database level. You will thus need to enforce this through your views, etc.
We can however, like @Ilja Everilä says, use a CHECK
constraint:
CREATE TABLE IF NOT EXISTS Teacher_Table(
Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL CHECK (length(Gender) < 2),
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL
)
Would aCHECK
constraint work in SQLite?
– Ilja Everilä
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignoresCHECK
, making the "SQL landscape" quite chaotic :s.
– Willem Van Onsem
2 days ago
1
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
add a comment |
up vote
2
down vote
up vote
2
down vote
How can I make sure it only accepts one character for that field
SQLite does not check the length constraints defined at type level, as is specified in the documentation on types:
(...) Note that numeric arguments in parentheses that following the type name (ex: "
VARCHAR(255)
") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large globalSQLITE_MAX_LENGTH
limit) on the length of strings, BLOBs or numeric values.
So you can not enforce this at the database level. You will thus need to enforce this through your views, etc.
We can however, like @Ilja Everilä says, use a CHECK
constraint:
CREATE TABLE IF NOT EXISTS Teacher_Table(
Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL CHECK (length(Gender) < 2),
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL
)
How can I make sure it only accepts one character for that field
SQLite does not check the length constraints defined at type level, as is specified in the documentation on types:
(...) Note that numeric arguments in parentheses that following the type name (ex: "
VARCHAR(255)
") are ignored by SQLite - SQLite does not impose any length restrictions (other than the large globalSQLITE_MAX_LENGTH
limit) on the length of strings, BLOBs or numeric values.
So you can not enforce this at the database level. You will thus need to enforce this through your views, etc.
We can however, like @Ilja Everilä says, use a CHECK
constraint:
CREATE TABLE IF NOT EXISTS Teacher_Table(
Teacher_ID INTEGER PRIMARY KEY,
TFirst_Name VARCHAR(25) NOT NULL,
TLast_Name VARCHAR (25) NOT NULL,
Gender CHAR(1) NOT NULL CHECK (length(Gender) < 2),
Home_Address VARCHAR (50) NOT NULL,
Contact_Number VARCHAR (14) NOT NULL
)
edited 2 days ago
answered 2 days ago
Willem Van Onsem
139k16131221
139k16131221
Would aCHECK
constraint work in SQLite?
– Ilja Everilä
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignoresCHECK
, making the "SQL landscape" quite chaotic :s.
– Willem Van Onsem
2 days ago
1
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
add a comment |
Would aCHECK
constraint work in SQLite?
– Ilja Everilä
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignoresCHECK
, making the "SQL landscape" quite chaotic :s.
– Willem Van Onsem
2 days ago
1
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
Would a
CHECK
constraint work in SQLite?– Ilja Everilä
2 days ago
Would a
CHECK
constraint work in SQLite?– Ilja Everilä
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignores
CHECK
, making the "SQL landscape" quite chaotic :s.– Willem Van Onsem
2 days ago
@IljaEverilä: yes, funny enough, MySQL ignores
CHECK
, making the "SQL landscape" quite chaotic :s.– Willem Van Onsem
2 days ago
1
1
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
Thank you so much! This worked for me
– Osasenaga Emokpae
2 days ago
add a comment |
Osasenaga Emokpae is a new contributor. Be nice, and check out our Code of Conduct.
Osasenaga Emokpae is a new contributor. Be nice, and check out our Code of Conduct.
Osasenaga Emokpae is a new contributor. Be nice, and check out our Code of Conduct.
Osasenaga Emokpae is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239175%2frestriciting-number-of-characters-entered-into-sqlite3%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
SqlLite ignores the length constraints sqlite.org/datatype3.html
– Willem Van Onsem
2 days ago
What do you want to happen if an attempt is made to insert more than one character: get an error or silently truncate to one character?
– varro
2 days ago