public virtual async Task <IDbConnection> OpenDbConnectionStringAsync(string connectionString, CancellationToken token = default) { if (connectionString == null) { throw new ArgumentNullException(nameof(connectionString)); } var connection = new OrmLiteConnection(this) { ConnectionString = connectionString }; await connection.OpenAsync(token).ConfigAwait(); return(connection); }
public virtual IDbConnection OpenDbConnectionString(string connectionString) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } var connection = new OrmLiteConnection(this) { ConnectionString = connectionString }; connection.Open(); return(connection); }
/// <summary> /// 获取服务器当前时间 /// <para>1、Oracle已经验证</para> /// <para>2、PostgreSQL已经验证</para> /// <para>3、Sqlite已经验证</para> /// </summary> /// <param name="dbConn"></param> /// <returns>服务器上的当前时间</returns> public static DateTime ServerTime(this IDbConnection dbConn) { OrmLiteConnection conn = dbConn as OrmLiteConnection; switch (conn.DialectProvider.GetType().Name) { case "OracleOrmLiteDialectProvider": return(conn.Scalar <DateTime>("select sysdate from dual")); case "PostgreSQLDialectProvider": return(conn.Scalar <DateTime>("select now()")); case "SqliteOrmLiteDialectProvider": return(conn.Scalar <DateTime>("select datetime(current_timestamp,'localtime')")); case "SqlServerOrmLiteDialectProvider": return(conn.Scalar <DateTime>("select getdate()")); case "MySqlDialectProvider": return(conn.Scalar <DateTime>("select now()")); } return(DateTime.Now); }
public virtual IDbConnection OpenDbConnectionString(string connectionString) { if (connectionString == null) throw new ArgumentNullException("connectionString"); var connection = new OrmLiteConnection(this) { ConnectionString = connectionString }; connection.Open(); return connection; }
public OrmLiteCommand(OrmLiteConnection dbConn, IDbCommand dbCmd) { this.dbConn = dbConn; this.dbCmd = dbCmd; this.DialectProvider = dbConn.GetDialectProvider(); }
public virtual IDbConnection OpenDbConnection() { if (ConnectionString == ":memory:") { if (InMemoryDbConnection == null || DbFactory.AutoDisposeConnection) { InMemoryDbConnection = new OrmLiteConnection(DbFactory); InMemoryDbConnection.Open(); } return InMemoryDbConnection; } return DbFactory.OpenDbConnection(); }