1 /** 2 * DDBC - D DataBase Connector - abstraction layer for RDBMS access, with interface similar to JDBC. 3 * 4 * Source file ddbc/drivers/mysqlddbc.d. 5 * 6 * DDBC library attempts to provide implementation independent interface to different databases. 7 * 8 * Set of supported RDBMSs can be extended by writing Drivers for particular DBs. 9 * 10 * JDBC documentation can be found here: 11 * $(LINK http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/package-summary.html)$(BR) 12 * 13 * This module contains misc utility functions which may help in implementation of DDBC drivers. 14 * 15 * Copyright: Copyright 2013 16 * License: $(LINK www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 17 * Author: Vadim Lopatin 18 */ 19 module ddbc.drivers.utils; 20 21 import std.datetime; 22 23 string copyCString(T)(const T* c, int actualLength = -1) if (is(T == char) || is (T == ubyte)) { 24 const(T)* a = c; 25 if(a is null) 26 return null; 27 28 if(actualLength == -1) { 29 T[] ret; 30 while(*a) { 31 ret ~= *a; 32 a++; 33 } 34 return cast(string)ret; 35 } else { 36 return cast(string)(a[0..actualLength].idup); 37 } 38 39 } 40 41 TimeOfDay parseTimeoid(const string timeoid) 42 { 43 import std.format; 44 string input = timeoid.dup; 45 int hour, min, sec; 46 formattedRead(input, "%s:%s:%s", &hour, &min, &sec); 47 return TimeOfDay(hour, min, sec); 48 } 49 50 Date parseDateoid(const string dateoid) 51 { 52 import std.format: formattedRead; 53 string input = dateoid.dup; 54 int year, month, day; 55 formattedRead(input, "%s-%s-%s", &year, &month, &day); 56 return Date(year, month, day); 57 }