//////////////////////////////////////////////////////
// Member "text" is used to communicate with the above processXxx methods;
// the resulting string is returned to caller in parameter "fixed_data",
// not in "text" ("text" not used elsewhere).
// (Member "command" and the "pos/len" members -- same for them.)
//////////////////////////////////////////////////////
InputStmt::Option InputStmt::fix_string(const char * in_data,
					char * fixed_data,
					size_t data_maxlen)
{
  command = new char[data_maxlen + 1];
  command_pos = 0;
  text_pos = 0;

  text = fixed_data;
  text_maxlen = strlen(in_data);
#pragma nowarn(1506)   // warning elimination 
  str_pad(text, data_maxlen, ' ');
#pragma warn(1506)  // warning elimination 
#pragma nowarn(1506)   // warning elimination 
  str_cpy_all(text, in_data, strlen(in_data));
#pragma warn(1506)  // warning elimination 

  char c;
  Option option;

  cout << ">>" << in_data << endl;
  cout << "..";

#pragma nowarn(1506)   // warning elimination
  if (cin.peek() != '\n')
     cin.get(command, data_maxlen, '\n');
  else
     command[0] = '\0';
#pragma warn(1506)  // warning elimination
 
  if (cin.eof())
    {
      // Abort the "FC", not the whole SQLCI session
      CLEAR_STDIN_EOF;
      option = ABORT_O;
    }
  else
    {
      // consume the eol ('\n')
      cin.get(c);
      option = EMPTY_O;
    }

  while ((option != DONE_O) && (option != ABORT_O))
    {
      option = nextOption();

      switch (option)
	{
	case INSERT_O:
	  processInsert();
	  break;

	case REPLACE_O:
	  processReplace();
	  break;

	case EXPLICIT_REPLACE_O:
	  processReplace();
	  text_pos++;
	  break;

	case DELETE_O:
	  processDelete();
	  break;

	case ADVANCE_O:
	  text_pos += 1;
	  break;

	case END_O:
	  text_pos += 2;
	  break;

	case ABORT_O:
	  strncpy(text, in_data, strlen(in_data));
	  break;

	case DONE_O:
	  text[text_maxlen] = 0;
	  break;

	case AGAIN_O:
	  text[text_maxlen] = 0;
	  cout << ">>" << text << endl;
	  text[text_maxlen] = ' ';

	  cout << "..";
#pragma nowarn(1506)   // warning elimination 
          if (cin.peek() != '\n')
             cin.get(command, data_maxlen, '\n');
          else
             command[0] = '\0';
#pragma warn(1506)  // warning elimination 
	  if (cin.eof())
	    {
	      CLEAR_STDIN_EOF;
	      option = ABORT_O;
	    }
	  else
	    {
	      // consume the eol ('\n')
	      cin.get(c);
	      command_pos = 0;
	      text_pos = 0;
	    }
	  break;

	default:
	  break;

	}
    }

  delete [] command;
  command = 0;
  // delete text;    // text points to fixed_data, memory owned by caller!
  text = 0;

  return option;
}	// fix_string()
Example #2
0
void sqlimport::processSQL(QStringList sqlLines)
{
    QString sqlStatement;
    int nlines;
    QString tablename;
    int temp,temp2;

    for (nlines = 0; nlines <= sqlLines.count()-1;nlines++)
    {
        sqlStatement = sqlStatement + sqlLines[nlines].simplified() + " ";
    }

    //qDebug() << sqlStatement;

    if ((sqlStatement.toUpper().contains("CREATE TABLE ")) ||
            (sqlStatement.toUpper().contains("CREATE  TABLE ")))
    {
        //qDebug() << "CREATE:" << sqlStatement;
        sqlStatement = cleanSQL(sqlStatement);

        temp = sqlStatement.indexOf(" TABLE ");
        temp2 = sqlStatement.indexOf("(");


        tablename = sqlStatement.mid(temp+7,temp2-temp-8);

        processKeyIndexes(tablename,sqlStatement,0);
        processIndexes(tablename,sqlStatement,0);
        if (translateConstraints)
        {
            processConstraints(tablename,sqlStatement,0);
        }

        if (translateConstraints)
        {
            setNULLToForeignKeys(tablename,sqlStatement);
        }


        sqlStatement = sqlStatement.replace(" unsigned "," ",Qt::CaseInsensitive);

        sqlStatement = removeIndexes(sqlStatement);

        if (translateConstraints)
        {
            sqlStatement = removeConstraints(sqlStatement);
        }

        sqlStatement = sqlStatement + "\n";
        //outfile.write(sqlStatement.toAscii());
        writeToFile(sqlStatement.toAscii());
    }
    else
    {
        if (processInserts == true)
        {
            //qDebug() << "INSERT:" << sqlStatement;
            //processInsert(sqlStatement,0,"");
            processInsert(sqlStatement);
        }
    }
}