0

I have a 2 databases

1.db_temporary

2.db_primary

in db_temporary I have a table which contain bunch of data that I want to keep without overwrite it but update it from imported MYSQL file

I dump db_primary and import backup to db_temporary with this command

D:\mysql4.0.27\bin\mysqldump.exe --add-drop-table db_primary tb_wantomodify > "backupfile.sql"
D:\mysql4.0.27\bin\mysql.exe db_temporary < "backupfile.sql"

I have tried This Solution yeah it not overwrited , but what I want is update (addition) recent field of db_temporary with new value of backup.

Technicaly similiar to update set curvalue=curvalue+ 'newvaluefrombackup' like

Is it possible todo this?

Thank You

1 Answer 1

1

Firstly you can put both of those tables in the same database. There's no reason to create two seperate files. Secondly what you want here is the SQL UPDATE command. First create a database object and set it to your database.

SQLiteDatabase dataBase = SQLiteDatabase.openDatabase(myPath,
            null, SQLiteDatabase.OPEN_READWRITE);
database.execSQL("UPDATE " +yourTableNameHere+ " SET " +theColumnYouWantToUpdate+ "='" +theNewValue+ "' WHERE " +theColumnNametoUpdate+ "='" +theNewValue+ "'");

This may seem confusing at first but what you need to understand is that SQL commands read as strings. This example assumes you're using String constants for your table data, as you should. The + sign before and after is a concatenation command. Make sure you add spaces. And don't forget the commas after the values you want checked. There's a pretty good SQL commands tutorial here: [http://www.1keydata.com/sql/sqlselect.html]

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

4 Comments

thank you Mr. Brandon firstly it was "designed" as is as, I understand about normalization term, I worked 2 database because of company term, for safe way without modify master database, secondly I understand what your point is, but I wanted todo this on this mysql command line based, I could solve this with workoaround with php or other language but I wanted to know is it possible to do update from backup file, if it can I need a clue Thank You for answering :)
I'm sorry are you trying to use the android sql helper class?
No, sir I tried to using mysql console, but now I found the solution, it is based on your Idea, I don't know that mysql can export > to sql file, I think only mysqldump can do that job, FINAL CODE : D:\mysql4.0.27\bin\mysql.exe -e "SELECT CONCAT('UPDATE tb_name SET field1=field1+''',field1,''';') AS '' FROM tb_name;" db_primary > "backupfile.sql" Through miss a communication, but your answer give me an idea :D Thanks again
glad it helped, I learned something too, since I didn't know what MySQL was. After reading your first comment I went and looked it up. Don't know why my mind read right over that as just SQL though. Have a happy holiday.

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.