Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

0.3.0 Usage Examples

Setup

MssqlDatabase db = new MssqlDatabase()
db.connect("mssql://localhost:1433/testdb?user=test&pass=test");

Notes

  • Data in Row object is in void[] for each field
  • Result object overhauled
    • contains Row m_currentRow
    • Can do something like Row[] m_rows for a CachedResultSet in future
    • contains ColInfo[] m_fields
  • ColInfo object is new, contains properties of fields
    • name
    • declaration
    • type
    • varlen
    • precision
    • scale
  • ColInfo could also contain properties (borrowed from JTDS jdbc driver for MSSQL):
    • different name for actual field in db vs. label used in D code
    • table
    • catalog
    • schema
    • nullable
    • isCaseSensitive
    • isWriteable
    • isIdentity
    • isKey
    • isHidden
    • collation (MSSQL-specific?)
    • charsetInfo
    • displaySize
    • bufferSize

Example

Note: this works on my local, I want to get thoughts before proceeding

  • doesn't yet have connect string in URL format like above
  • needs testing for other data types
  • ColInfo type information can be used in Result to warn/throw based on method used to retrieve data
  • getXxxx methods need to accept char[] fieldname
    • keep an AA of the fields in Result?
import dbi.mssql.MssqlDatabase;
import dbi.Result, dbi.Row;
import tango.io.Stdout;

void main() {

	MssqlDatabase db = new MssqlDatabase();
	db.connect("sqlvs1 1433","test","test");
  
	char[] sql = "USE admin; SELECT * FROM test;";
	Result rs = db.query(sql);

	while ( rs.next() ) {
	  Stdout (rs.getString(0)) (", ") (rs.getInt(1)).newline;	  
	}

	db.close();
}

result:

hello world, 42
yo, wutup?, 43