mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 19:37:03 +00:00
[10311] Prevent lost sql update content at git_id -s use in some cases.
To devs: please update git_id binaries
This commit is contained in:
parent
8aaf32798f
commit
a48fdd8620
2 changed files with 23 additions and 12 deletions
|
|
@ -536,12 +536,13 @@ bool convert_sql_updates()
|
||||||
|
|
||||||
FILE * fin = fopen( src_file, "r" );
|
FILE * fin = fopen( src_file, "r" );
|
||||||
if(!fin) return false;
|
if(!fin) return false;
|
||||||
FILE * fout = fopen( dst_file, "w" );
|
|
||||||
if(!fout) { fclose(fin); return false; }
|
std::ostringstream out_buff;
|
||||||
|
|
||||||
// add the update requirements
|
// add the update requirements
|
||||||
fprintf(fout, "ALTER TABLE %s CHANGE COLUMN required_%s required_%s bit;\n\n",
|
out_buff << "ALTER TABLE " << db_version_table[info.db_idx]
|
||||||
db_version_table[info.db_idx], last_sql_update[info.db_idx], new_name);
|
<< " CHANGE COLUMN required_" << last_sql_update[info.db_idx]
|
||||||
|
<< " required_" << new_name << " bit;\n\n";
|
||||||
|
|
||||||
// skip the first one or two lines from the input
|
// skip the first one or two lines from the input
|
||||||
// if it already contains update requirements
|
// if it already contains update requirements
|
||||||
|
|
@ -551,25 +552,35 @@ bool convert_sql_updates()
|
||||||
if(sscanf(buffer, "ALTER TABLE %s CHANGE COLUMN required_%s required_%s bit", dummy, dummy, dummy) == 3)
|
if(sscanf(buffer, "ALTER TABLE %s CHANGE COLUMN required_%s required_%s bit", dummy, dummy, dummy) == 3)
|
||||||
{
|
{
|
||||||
if(fgets(buffer, MAX_BUF, fin) && buffer[0] != '\n')
|
if(fgets(buffer, MAX_BUF, fin) && buffer[0] != '\n')
|
||||||
fputs(buffer, fout);
|
out_buff << buffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fputs(buffer, fout);
|
out_buff << buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the rest of the file
|
// copy the rest of the file
|
||||||
char c;
|
while(fgets(buffer, MAX_BUF, fin))
|
||||||
while( (c = getc(fin)) != EOF )
|
out_buff << buffer;
|
||||||
putc(c, fout);
|
|
||||||
|
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
|
|
||||||
|
FILE * fout = fopen( dst_file, "w" );
|
||||||
|
if(!fout) { fclose(fin); return false; }
|
||||||
|
|
||||||
|
fprintf(fout, "%s",out_buff.str().c_str());
|
||||||
|
|
||||||
fclose(fout);
|
fclose(fout);
|
||||||
|
|
||||||
// rename the file in git
|
// rename the file in git
|
||||||
snprintf(cmd, MAX_CMD, "git add %s", dst_file);
|
snprintf(cmd, MAX_CMD, "git add %s", dst_file);
|
||||||
system_switch_index(cmd);
|
system_switch_index(cmd);
|
||||||
snprintf(cmd, MAX_CMD, "git rm --quiet %s", src_file);
|
|
||||||
system_switch_index(cmd);
|
// delete src file if it different by name from dst file
|
||||||
|
if(strncmp(src_file,dst_file,MAX_PATH))
|
||||||
|
{
|
||||||
|
snprintf(cmd, MAX_CMD, "git rm --quiet %s", src_file);
|
||||||
|
system_switch_index(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
// update the last sql update for the current database
|
// update the last sql update for the current database
|
||||||
strncpy(last_sql_update[info.db_idx], new_name, MAX_PATH);
|
strncpy(last_sql_update[info.db_idx], new_name, MAX_PATH);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10310"
|
#define REVISION_NR "10311"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue