sqldata/sqldb.cpp
// Get IDENTITY clause to be added to column definition
Get IDENTITY clause to be added to column definition
Get IDENTITY clause to be added to column definition
int SqlDb::GetInlineIdentityClause(const char *s_table, char *column, std::string &identity_clause)
{
	if(s_table == NULL || column == NULL)
		return -1;
	if(target_type != SQLDATA_SQL_SERVER && target_type != SQLDATA_MYSQL)
		return 0;
	std::list<SqlColMeta> *table_columns = _metaSqlDb->GetTableColumns(SQLDB_SOURCE_ONLY);
	if(table_columns == NULL)
		return 0;
	std::string schema;
	std::string table;
	SqlApiBase::SplitQualifiedName(s_table, schema, table);
	for(std::list<SqlColMeta>::iterator i = table_columns->begin(); i != table_columns->end(); i++)
	{
		if((*i).identity == false)
			continue;
		char *col = (*i).column;
		char *tab = (*i).table;
		char *sch = (*i).schema;
		if(col == NULL || tab == NULL || sch == NULL)
			continue;
		if(_stricmp(col, column) == 0 && _stricmp(tab, table.c_str()) == 0 &&
			_stricmp(sch, schema.c_str()) == 0)
		{
			char int1[21];
			if(target_type == SQLDATA_SQL_SERVER)
			{
				identity_clause += "IDENTITY(";
				identity_clause += Str::IntToString((*i).id_next, int1);
				identity_clause += ",";
				identity_clause += Str::IntToString((*i).id_inc, int1);
				identity_clause += ")";
			}
			else
			if(target_type == SQLDATA_MYSQL)
				identity_clause += "AUTO_INCREMENT PRIMARY KEY";
			break;
		}
	}
	return 0;
}
int SqlDb :: GetInlineIdentityClause ( const char * s_table , char * column , std :: string & identity_clause ) { if ( s_table == NULL || column == NULL ) return -1 ; if ( target_type != SQLDATA_SQL_SERVER && target_type != SQLDATA_MYSQL ) return 0 ; std :: list < SqlColMeta > * table_columns = _metaSqlDb -> GetTableColumns ( SQLDB_SOURCE_ONLY ) ; if ( table_columns == NULL ) return 0 ; std :: string schema ; std :: string table ; SqlApiBase :: SplitQualifiedName ( s_table , schema , table ) ; for ( std :: list < SqlColMeta > :: iterator i = table_columns -> begin ( ) ; i != table_columns -> end ( ) ; i ++ ) { if ( ( * i ) . identity == false ) continue ; char * col = ( * i ) . column ; char * tab = ( * i ) . table ; char * sch = ( * i ) . schema ; if ( col == NULL || tab == NULL || sch == NULL ) continue ; if ( _stricmp ( col , column ) == 0 && _stricmp ( tab , table . c_str ( ) ) == 0 && _stricmp ( sch , schema . c_str ( ) ) == 0 ) { char int1 [ 21 ] ; if ( target_type == SQLDATA_SQL_SERVER ) { identity_clause += " " ; identity_clause += Str :: IntToString ( ( * i ) . id_next , int1 ) ; identity_clause += " " ; identity_clause += Str :: IntToString ( ( * i ) . id_inc , int1 ) ; identity_clause += " " ; } else if ( target_type == SQLDATA_MYSQL ) identity_clause += " " ; break ; } } return 0 ; }
Get IDENTITY clause to be added to column definition
Get IDENTITY clause to be added to column definition
// Find mapping record for this table and column // Not an identity column // MySQL and MariaDB require auto_increment to be a key