0

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 ?

2
  • Are you also using the fully qualified names in mysql? Without being sure I don't think you can use the full names inside the create statement. You haven't created the table yet and it's trying to fetch the table names from a table that hasn't been created... It's like sitting on a branch trying to it saw it over, while sitting on it ;-) Commented Sep 9, 2013 at 15:14
  • i've tried this in mySql and it works.. that why i'm asking and that why i used it.. Commented Sep 9, 2013 at 15:15

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

thanks. the inner join wasn't the problem. i wanted to be efficient and save all my column names Strings as Table_Name.Column_Name in order to avoid don't TABLE_NAME_STRING + "." + TABLE_COLUMN_STRING for each inner join...
Well, think about it.. If it were legal and the column was named "Users.Name".. you still aren't providing a table name for your join. You'd still need to do "Users.Users.Name" to specify table AND column on the inner join
you're right... but after testing it in mySql i thought maybe the sql system knows that if the table name == the name before the column name - don't use it
MySql and SQLite don't always conform to the same rules. MySQL is a bit "smarter" in some respects.
0

Just try to remove all User. in the sql.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.