1

I have created my table using sqlite for my android project. It was working just fine before. Initially, I created 3 fields to make sure the connection will work and it did so I added all the other fields I will need but I was getting an error with the cursor. After reading similar problems here, i figured it will be an issue with the onUpgrade so i uninstalled the app and reinstalled but now it keeps crashing and I am getting a syntax error.

Here is my code

public void onCreate(SQLiteDatabase db){

        db.execSQL("CREATE TABLE " + DATABASE_TABLE_SITE_INFO + " ("
                + ROW_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                + SYSAID_ID + " TEXT, "
                + SITE_ID + " TEXT, "
                + LINK_ID + " TEXT, "
                + CUSTOMER_NAME + " TEXT, "
                + SITE_CONTACT + " TEXT, "
                + TASK_TYPE + " TEXT, "
                + ADDRESS + " TEXT, "
                + REGION + " TEXT, "
                + PHONE + " TEXT, "
                + FAX + " TEXT, "
                + MOBILE + " TEXT, "
                + EMAIL + " TEXT, "
                + LANDLORD_NAME + " TEXT, "
                + RENT_STATUS + " TEXT, "
                + LOCATION + " TEXT, "
                + ENGINEER_NAME + " TEXT, "
                + ENGINEER_SIGN + " BLOB, "
                + POWER_STATUS + " TEXT, "
                + VOLTAGE_MEASUREMENT + " TEXT, "
                + AIRCON + " TEXT, "
                + SERVER_ROOM_STATUS + " TEXT, "
                + LOCATION_IDU + " TEXT, "
                + EARTHING + " TEXT, "
                + DISTANCE_IDU + " TEXT, "
                + SECURITY_CABLES + " TEXT, "
                + DUCTS + " TEXT, "
                + UNIT_TYPE + " TEXT, "
                + INST_TYPE + " TEXT, "
                + HAVE_ISP + " TEXT, "
                + RADIO + " TEXT, "
                + ISP_TYPE + " TEXT, "
                + ISP_NAME + " TEXT, "
                + SNR_RX + " TEXT, "
                + BS + " TEXT, "
                + REMARKS + " TEXT);");

And this is the error code i am getting

01-14 10:22:28.429  24406-24406/com.example.sweetiean.stlfieldinstallation1 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.sweetiean.stlfieldinstallation1, PID: 24406
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sweetiean.stlfieldinstallation1/com.example.sweetiean.stlfieldinstallation1.MainActivity}: android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: CREATE TABLE site_info_table(_id INTEGER PRIMARY KEY AUTOINCREMENT, sysaid_id TEXT, site_id TEXT, link_id TEXT, customer_name TEXT, site_contact_name TEXT, task_type TEXT, address TEXT, region TEXT, phone TEXT, fax TEXT, mobile TEXT, email TEXT, landlord_name TEXT, rent_status TEXT, location TEXT, engineer_name TEXT, engineer_sign BLOB, power_status TEXT, voltage_measure TEXT, aircon TEXT, server_room_status TEXT, location_of_idu TEXT, earthing TEXT, distance_idu TEXT, security_of_cables TEXT, ducts TEXT, unit_to_be_installed TEXT, inst_type TEXT, isp TEXT, radio_type TEXT, isp_type TEXT, isp_name TEXT, snr(rx) TEXT, bs TEXT, remarks TEXT);

1 Answer 1

3

snr(rx) is not a valid column name because of the parentheses. Rename it to e.g. snr_rx.

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

5 Comments

Added "is not " before "a valid column name"
or if want to create column name as snr(rx) in table then use [snr(rx)] TEXT instead of snr(rx) TEXT
I dont have enough reputation points to upvote your answer but I need you to know that it worked. kudos!!
@DerGolem Thanks, writing while distracted by a coworker is not always a good idea.
ρяσѕρєяK, true, or "snr(tx)" or the same in backticks. But that would likely cause problems when using the column name in other constructs, so renaming it is better.

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.