Reputation: 11678
In my application i have 3 Sqlite tables with some foreign keys and inner join queries.
I've created DatabaseSqlHelper class which saves all my tables and columns name.
I've tried to use this line in order to create a table
Create Table If Not Exists Users(
Users.User_Id Varchar(50) Primary Key Not Null,
Users.Name Varchar(50) Not Null,
Users.First_Name Varchar(50),
Users.Profile_Picture Blob);
I've been testing this in mySql and and it has no problem but when running it on Android i get:
09-09 17:58:30.350: E/Database(12973): Failure 1 (near ".": syntax error) on 0x1cf850 when preparing 'Create Table If Not Exists Users(Users.User_Id Varchar(50) Primary Key Not Null,Users.Name Varchar(50) Not Null,Users.First_Name Varchar(50),Users.Profile_Picture Blob);'.
The reason i'm using TableName.ColumnName is because i saved does name in Strings like that so later in the inner join it will be easier for me to do Inner Join TableName on Users.Id = TableName.Id
Is there a way to fix it ?
Upvotes: 0
Views: 274
Reputation: 22306
Get rid of the table name and period in front of each column.
Ex.
Create Table If Not Exists Users(
User_Id Varchar(50) Primary Key Not Null,
Name Varchar(50) Not Null,
First_Name Varchar(50),
Profile_Picture Blob);
Your inner joins will be fine using Users.id. You don't need to specify that when creating the table for that to work.. Just specify the table names when doing the joins
ex. select Id as Tablename.Id from Tablename inner join Users as U on U.user_id = Tablename.Id
Upvotes: 1