[android-developers] Insert data using SQLite Database with Insert + Where Clause after already entered data in next colums!

2012-07-26 Thread vikalp patel
I would like to Insert data in my next columns of TABLE with help of 
Signup2Activity which has been already inserted by SIgnup1Activity.java. 
HereBy i had attached all the necessary file to find the error.

ERROR: Database: near Where: near INSERT INTO+TABLE+ ( +columns+) 
VALUES (+first.getText().toString()+) WHERE +ID+ =+ id;

how can we insert data in next columns of database with already entered 
data in their first few columns??

ANy help is most welcome!! 

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=enpackage com.project.vikalp;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;



public class DatabaseHandler extends SQLiteOpenHelper {
	
	
	public static final String DATABASE_NAME=registerdb;
	public static final int  DATABASE_VERSION=1;
	public static final String TABLE=register;
	private static final String _ID=id;
	public static final String FIRST_NAME=firstname;
	public static final String LAST_NAME=lastname;
	public static final String EMAIL1=email1;
	public static final String PASSWORD=password;
	public static final String CONFIRM_PASSWORD=confirmpassword;
	public static final String SECURITY1=security1;
	public static final String ANSWER1=answer1;
	public static final String SECURITY2=security2;
	public static final String ANSWER2=answer2;
public static final String EMAIL2=email2;
public static final String UPLOAD=upload;
public static final String[] allColumns={_ID,FIRST_NAME,LAST_NAME,EMAIL1,PASSWORD,CONFIRM_PASSWORD
	,SECURITY1,ANSWER1,SECURITY2,ANSWER2,EMAIL2,UPLOAD};

public DatabaseHandler(Context context)   
{
super(context,DATABASE_NAME,null,DATABASE_VERSION);	
}


public  void onCreate(SQLiteDatabase database)
{
	String DATABASE_CREATE = create table
+ TABLE  
+( + _ID +  + integer primary key autoincrement, 
+ FIRST_NAME+  + text not null,
+ LAST_NAME + + text not null,
+ EMAIL1 + + text not null,
+ PASSWORD + + text not null,
+ CONFIRM_PASSWORD + + text not null,
+ SECURITY1 +  +text,
+ ANSWER1 + + text ,
+ SECURITY2 + + text,
+ ANSWER2 + + text,
+ EMAIL2 + +text,
+ UPLOAD +  +text
+ );

	
	database.execSQL(DATABASE_CREATE);
	Log.w(Create:,Creating Database...);

}
	
	public  void onUpgrade(SQLiteDatabase database,int oldversion,int newversion)
	{
		Log.w(SignupActivity.class.getName(),Upgrading Database Version
	+ oldversion + to +newversion );
		//database.execSQL(DROP TABLE IF EXISTS+ TABLE);
	onCreate(database);
	}

	public void addregister(Register register)
	{
 
		SQLiteDatabase db= this.getWritableDatabase();
		ContentValues values=new ContentValues();
		values.put(FIRST_NAME,register.getFName());
		values.put(LAST_NAME, register.getLName());
		values.put(EMAIL1,register.getEmail1());
		values.put(PASSWORD, register.getPass());
		values.put(CONFIRM_PASSWORD,register.getCPass());
		
		db.insert(TABLE, null, values);
		db.close();
		
	}
	public void addregister1(Register register)
	{
		SQLiteDatabase db=this.getWritableDatabase();
		String sec,ans1,sec2,ans2,mail2;
		sec=register.getSecurity1();
		ans1=register.getAnswer1();
		sec2=register.getSecurity2();
		ans2=register.getAnswer2();
		mail2=register.getEmail2();
		String[] wid={Integer.toString(register.getId())};
		String sql=INSERT INTO   + TABLE + ( 
+ SECURITY1 + ,
+ ANSWER1 + ,
+ SECURITY2 + ,
+ ANSWER2 + ,
+ EMAIL2 
+) VALUES( 
+ sec + ,
+ ans1 + ,
+ sec2 + ,
+ ans2 + ,
+ mail2 
+) 
+WHERE +_ID + = ?;
//		db.update(TABLE,values1, _ID + = ?,new String[]{(String.valueOf(register.getId())) });
		/*db.execSQL(INSERT INTO   + TABLE + ( 
+ SECURITY1 + ,
+ ANSWER1 + ,
+ SECURITY2 + ,
+ ANSWER2 + ,
+ EMAIL2 
+) VALUES( 
+ sec + ,
+ ans1 + ,
+ sec2 + ,
+ ans2 + ,
+ mail2 
+) 
+WHERE +_ID + = +register.getId());*/
		
		db.rawQuery(sql, wid);
		db.close();
	}

	public int getId(Register register)
	{
		SQLiteDatabase db= this.getReadableDatabase();
		Cursor cursor=db.query(TABLE,allColumns, null, null, null, null, null);
		cursor.moveToLast();
		int i=Integer.parseInt(cursor.getString(0));
		return i;
	}
	
/*public void 

Re: [android-developers] Insert data using SQLite Database with Insert + Where Clause after already entered data in next colums!

2012-07-26 Thread Mark Murphy
I do not believe that there is any SQL database that supports a WHERE
clause on INSERT.

For questions regarding SQLite SQL syntax, please use a SQLite support
resource, or a generic support resource (e.g., StackOverflow).

On Tue, Jul 24, 2012 at 9:06 AM, vikalp patel vikalppatel...@gmail.com wrote:
 I would like to Insert data in my next columns of TABLE with help of
 Signup2Activity which has been already inserted by SIgnup1Activity.java.
 HereBy i had attached all the necessary file to find the error.

 ERROR: Database: near Where: near INSERT INTO+TABLE+ ( +columns+)
 VALUES (+first.getText().toString()+) WHERE +ID+ =+ id;

 how can we insert data in next columns of database with already entered data
 in their first few columns??

 ANy help is most welcome!!

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.8 Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Insert data using SQLite Database with Insert + Where Clause after already entered data in next colums!

2012-07-26 Thread Michael Banzon
As Mark writes the syntax is not valid. You should use update.
Please refer to the SQLite documentation for specific syntax questions
- to the best of my knowledge the official documentation of standard
SQLite also covers the features available on Android:
http://www.sqlite.org/lang_update.html

On Tue, Jul 24, 2012 at 3:06 PM, vikalp patel vikalppatel...@gmail.com wrote:
 I would like to Insert data in my next columns of TABLE with help of
 Signup2Activity which has been already inserted by SIgnup1Activity.java.
 HereBy i had attached all the necessary file to find the error.

 ERROR: Database: near Where: near INSERT INTO+TABLE+ ( +columns+)
 VALUES (+first.getText().toString()+) WHERE +ID+ =+ id;

 how can we insert data in next columns of database with already entered data
 in their first few columns??

 ANy help is most welcome!!

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en



-- 
Michael Banzon
http://michaelbanzon.com/

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en