Thread: How to convert this mysql syntax
I thought that SQL was nomalized but when I tried this wmysql code
With PostGreSQL it doesn’t work.
//Select database
m_pDb.Execute( "USE dbBornes;" );
// Create table
csSql.Format( "CREATE TABLE %s(", m_DbTable );
csSql += _T( "UserID INTEGER NOT NULL AUTO_INCREMENT," );
csSql += _T( "Time DATETIME NOT NULL," );
csSql += _T( "NumSerie INTEGER NOT NULL," );
csTmp.Format( "%s VARCHAR(64),", im->first );
csSql += _T( "PRIMARY KEY(UserID))" );
> I thought that SQL was nomalized but when I tried this wmysql code SQL is mostly normalized, but every database seems to bring in its own incompatibilities. > > With PostGreSQL it doesn't work. It is probably a MySQL extension. > > > > > > //Select database > > > > m_pDb.Execute( "USE dbBornes;" ); Try: m_pDb.Execute( "connect dbBornes;" ); > > > > // Create table > > csSql.Format( "CREATE TABLE %s(", m_DbTable ); > > csSql += _T( "UserID INTEGER NOT NULL AUTO_INCREMENT," ); > > csSql += _T( "Time DATETIME NOT NULL," ); > > csSql += _T( "NumSerie INTEGER NOT NULL," ); > > csTmp.Format( "%s VARCHAR(64),", im->first ); > > csSql += _T( "PRIMARY KEY(UserID))" ); > >
--- markw@mohawksoft.com wrote: > > I thought that SQL was nomalized but when I tried > this wmysql code > > SQL is mostly normalized, but every database seems > to bring in its own > incompatibilities. > > > > With PostGreSQL it doesn't work. > > It is probably a MySQL extension. > > > > > > > > > > > > > //Select database > > > > > > > > m_pDb.Execute( "USE dbBornes;" ); > > Try: > m_pDb.Execute( "connect dbBornes;" ); > > > > > > > > > // Create table > > > > csSql.Format( "CREATE TABLE %s(", m_DbTable ); > > > > csSql += _T( "UserID INTEGER NOT NULL > > AUTO_INCREMENT," ); csSql += _T( "UserID SERIAL NOT NULL," ); > > > > csSql += _T( "Time DATETIME NOT NULL," ); csSql += _T( "Time TIMESTAMP NOT NULL," ); > > > > csSql += _T( "NumSerie INTEGER NOT NULL," ); > > > > csTmp.Format( "%s VARCHAR(64),", im->first ); > > > > csSql += _T( "PRIMARY KEY(UserID))" ); http://www.postgresql.org/docs/8.0/interactive/datatype.html > > > > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: you can get off all lists at once with the > unregister command > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) > __________________________________ Do you Yahoo!? Take Yahoo! Mail with you! Get it on your mobile phone. http://mobile.yahoo.com/maildemo
> > > csSql += _T( "UserID INTEGER NOT NULL > > > AUTO_INCREMENT," ); > > csSql += _T( "UserID SERIAL NOT NULL," ); > or, csSql += _T( "UserID SERIAL PRIMARY KEY," ); Primary keys get the not null automatically. Serial, by the way, is just shorthand for defaulting the primary key to a value pulled from a sequence. It as a non standard extension just like AUTO_INCREMENT is, but it is a *much* better abstraction of an incrementing key. Merlin