How to Avoid Data Corruption
Moderator: Rathinagiri
How to Avoid Data Corruption
Hi All,
I am facing problems regarding data corruption in .dbf files, both in multi-user and single-user mode. The corruption mainly occurs in my old VFP apps (here I am not asking help for another software tool). Is it due to .dbf files or the software tool I used.
I am asking for help because, I should know it before creating my future apps on .dbf files.
If I use MySql, will the data corruption be reduced? (I saw numerous databases with SQL Server have data corruption)
If the answer is Yes, then can my app easily create tables, indexes etc., and ability to change their structure on the fly (as they currently do with .dbf)?
With best regards.
Sudip
I am facing problems regarding data corruption in .dbf files, both in multi-user and single-user mode. The corruption mainly occurs in my old VFP apps (here I am not asking help for another software tool). Is it due to .dbf files or the software tool I used.
I am asking for help because, I should know it before creating my future apps on .dbf files.
If I use MySql, will the data corruption be reduced? (I saw numerous databases with SQL Server have data corruption)
If the answer is Yes, then can my app easily create tables, indexes etc., and ability to change their structure on the fly (as they currently do with .dbf)?
With best regards.
Sudip
With best regards,
Sudip
Sudip
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to Avoid Data Corruption
Data corruption, by saying, you mean because of power shutdown, program crash or what?
In my few years experience, MySQL is doing well. We can activate auto backup of critical data that would be stored in a separate place in regular intervals.
In my few years experience, MySQL is doing well. We can activate auto backup of critical data that would be stored in a separate place in regular intervals.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: How to Avoid Data Corruption
Hi Rathi,
I just expected your message
Thanks a lot!
I know very little about MySql. I tried 3 examples given with HMG 2.6.7. I liked 2nd one (1st example is thorough, but I don't know Spanish!!!). Now, I must have a serious try on MySql.
With best regards.
Sudip
I just expected your message
![Smile :)](./images/smilies/icon_e_smile.gif)
I really don't know from where those evils come. But, I see some junk characters inside my clients tables !!! ;( And they ruin the database temporarily! Whole system is halted and required "my" "VALUED" presence at client's site!!!Data corruption, by saying, you mean because of power shutdown, program crash or what?
Very goodIn my few years experience, MySQL is doing well. We can activate auto backup of critical data that would be stored in a separate place in regular intervals.
![Smile :)](./images/smilies/icon_e_smile.gif)
With best regards.
Sudip
With best regards,
Sudip
Sudip
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to Avoid Data Corruption
If you want I can give some udfs used by me to run all the queries and get the resulting table as an array.
1. connect2db(host,user,password,dbname) This is to connect to the database.
2. sql(dbo1,qstr) While running a SQL query. In this, dbo1 is the database object for connecting to the current database, qstr is the query string. This can be used to get data from the database via 'select' query. The table is returned as an array.
3. miscsql(dbo,qstr) For insert, delete, update commands. Returns .t. or .f.
3. While closing the db.
Note: We can not use all the types of variables as such inside a MySQL query. We have to parse the harbour value to MySQL type, by using a function called c2sql(value) (clipper to sql). This is already in the sql sample. Let this also been added to the user defined functions.
So, our insert query may be like this.
Select query may be like this.
1. connect2db(host,user,password,dbname) This is to connect to the database.
Code: Select all
//dbo is a public variable holding the database object
FUNCTION connect2db(host,user,password,dbname)
dbo := tmysqlserver():new(AllTrim(host),AllTrim(user),AllTrim(password))
IF dbo:NetErr()
msginfo(dbo:ERROR())
RETURN nil
ENDIF
dbo:selectdb(dbname)
IF dbo:NetErr()
msginfo(dbo:ERROR())
RETURN nil
ENDIF
//msginfo("Successfully Connected to the MySQL Server")
RETURN nil
Code: Select all
function sql(dbo1,qstr)
local table := nil
local currow := nil
local tablearr := {}
local rowarr := {}
local curdateformat := set(_SET_DATEFORMAT)
set date ansi
table := dbo1:query(qstr)
set(SET_DATEFORMAT,curdateformat)
if table:neterr()
msgstop(table:error())
table:destroy()
return tablearr
else
if table:lastrec() > 0
asize(tablearr,0)
for i := 1 to table:lastrec()
asize(rowarr,0)
currow := table:getrow(i)
for j := 1 to table:fcount()
aadd(rowarr,currow:fieldget(j))
next j
aadd(tablearr,aclone(rowarr))
next i
endif
table:destroy()
return tablearr
endif
return tablearr
Code: Select all
function miscsql(dbo,qstr)
local curdateformat := set( _SET_DATEFORMAT)
set date ansi
table := dbo:query(qstr)
set( _SET_DATEFORMAT,curdateformat)
if table:NetErr()
msgstop(table:ERROR())
table:destroy()
return .f.
endif
table:destroy()
return .t.
Code: Select all
dbo:destroy()
Code: Select all
function C2SQL(Value)
local cValue := ""
local cFormatoDaData := set(4)
do case
case Valtype(Value) == "N"
cValue := AllTrim(Str(Value))
case Valtype(Value) == "D"
if !Empty(Value)
// MySQL dates are like YYYY-MM-DD
if cFormatoDaData = 'mm-dd-yyyy' // USA
cValue := "'"+PadL(Month(Value), 2, "0") + '-'+ PadL(Day(Value), 2, "0") + "-" + Str(Year(Value), 4) + "'"
elseif cFormatoDaData = 'dd/mm/yyyy' // BRITISH ou FRENCH
cValue := "'"+PadL(Day(Value), 2, "0") + "/" + PadL(Month(Value), 2, "0") + "/" + Str(Year(Value), 4) + "'"
elseif cFormatoDaData = 'yyyy.mm.dd' // ANSI
cValue := "'"+Str(Year(Value), 4) + "." + PadL(Month(Value), 2, "0") + "." + PadL(Day(Value), 2, "0") + "'"
elseif cFormatoDaData = 'dd.mm.yyyy' //GERMAN
cValue := "'"+PadL(Day(Value), 2, "0") + "." + PadL(Month(Value), 2, "0") + "." + Str(Year(Value), 4) + "'"
elseif cFormatoDaData = 'dd-mm-yyyy' //ITALIAN
cValue := "'"+PadL(Day(Value), 2, "0") + "-" + PadL(Month(Value), 2, "0") + "-" + Str(Year(Value), 4) + "'"
elseif cFormatoDaData = 'yyyy/mm/dd' //JAPAN
cValue := "'"+Str(Year(Value), 4) + "/" + PadL(Month(Value), 2, "0") + "/" + PadL(Day(Value), 2, "0") + "'"
elseif cFormatoDaData = 'mm/dd/yyyy' // AMERICAN
cValue := "'"+Str(Year(Value), 4) + "/" + PadL(Month(Value), 2, "0") + "/" + PadL(Day(Value), 2, "0") + "'"
endif
else
cValue := "''"
endif
case Valtype(Value) $ "CM"
IF Empty( Value)
cValue="''"
ELSE
cValue := "'"
Value:=DATATOSQL(value)
cValue+= value+ "'"
ENDIF
case Valtype(Value) == "L"
cValue := AllTrim(Str(iif(Value == .F., 0, 1)))
otherwise
cValue := "''" // NOTE: Here we lose values we cannot convert
endcase
return cValue
Code: Select all
qsuccess := miscsql(dbo,"insert into table1 (name, address1,city) values ("+c2sql(form1.name1.value)+","+c2sql(form1.address1.value)+","+c2sql(form1.city.value)+")")
Code: Select all
tablearray := sql(dbo,"select * from table1 where city = "+c2sql(form1.city.value))
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: How to Avoid Data Corruption
Hi Rathi,
I don't know, how can I show my gratitude to you?
Thank you very much. Your code will be extremely helpful to me.
So, I am starting my MySql "mission" right now!!! (you know this is the busiest time for Indian programmers - end of the fiscal year and beginning of a new fiscal year!!!)
With my best regards.
Sudip
I don't know, how can I show my gratitude to you?
![Smile :)](./images/smilies/icon_e_smile.gif)
Thank you very much. Your code will be extremely helpful to me.
So, I am starting my MySql "mission" right now!!! (you know this is the busiest time for Indian programmers - end of the fiscal year and beginning of a new fiscal year!!!)
With my best regards.
Sudip
With best regards,
Sudip
Sudip
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to Avoid Data Corruption
With pleasure Sudip.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: How to Avoid Data Corruption
Hi,
I found an error during adding record in \Samples\Mysql\Demo_2
It shows following error message during insert.
With best regards.
Sudip
I found an error during adding record in \Samples\Mysql\Demo_2
It shows following error message during insert.
With best regards.
Sudip
With best regards,
Sudip
Sudip
Re: How to Avoid Data Corruption
Hi,
I solved the problem. The "code" column of Names table is AUTO_INCREMENT. So we should not pass value of "code" during insertion.
Previously code was:
I modified:
With best regards.
Sudip
I solved the problem. The "code" column of Names table is AUTO_INCREMENT. So we should not pass value of "code" during insertion.
Previously code was:
Code: Select all
If status == 1
cQuery := "INSERT INTO NAMES VALUES ( '"+cCode+"' , '"+ AllTrim(cName)+"' , '"+cEmail+ "' ) "
Else
cQuery := "UPDATE NAMES SET Name = '"+cName+"' , eMail = '"+cEMail+"' WHERE CODE = " + AllTrim(gCode)
Endif
Code: Select all
If status == 1
cQuery := "INSERT INTO NAMES (Name, eMail) VALUES ( '"+AllTrim(cName)+"' , '"+cEmail+ "' ) "
Else
cQuery := "UPDATE NAMES SET Name = '"+cName+"' , eMail = '"+cEMail+"' WHERE CODE = " + AllTrim(gCode)
Endif
Sudip
With best regards,
Sudip
Sudip
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: How to Avoid Data Corruption
Yes. And you can get the automatically incremented number by "select last_insert_id()" query for further processing.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: How to Avoid Data Corruption
Hi Rathi,
I am sharing Sudip's sentiments, me too am very thankful to all your valuable contributions, guidances and helps.
This your MySQL guidance will be a good starting way for me too.
Thanks a lot.
Regards
--
Esgici
sudip wrote:
I don't know, how can I show my gratitude to you?![]()
Thank you very much. Your code will be extremely helpful to me.
I am sharing Sudip's sentiments, me too am very thankful to all your valuable contributions, guidances and helps.
This your MySQL guidance will be a good starting way for me too.
Thanks a lot.
Regards
--
Esgici
Viva INTERNATIONAL HMG ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)