Skip to main content

connect_database 1.0.0 copy "connect_database: ^1.0.0" to clipboard
connect_database: ^1.0.0 copied to clipboard

discontinued

A Flutter package for ODBC database connectivity with support for SQL Server, PostgreSQL, and Sybase Anywhere. Features connection pooling, bulk operations, query metrics, and automatic SELECT interce [...]

example/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:result_dart/result_dart.dart';

import 'package:connect_database/connect_database.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await selectExemplo();
  exit(0);
}

Future<void> selectExemplo() async {
  final config = DatabaseConfig.sqlServer(
    driverName: 'SQL Server Native Client 11.0',
    username: 'sa',
    password: '123abc.',
    database: 'NSE',
    server: 'CESAR_CARLOS\\DATA7',
    port: 1433,
  );

  final query = SqlCommand(config);
  var recordCount = 0;

  final result = await query.connect().flatMap((_) async {
    final metadata = TableMetadata(query.odbc);
    final safeBuilder = SafeSelectBuilder(metadata);

    final safeColsResult = await safeBuilder.getSafeColumns('Cliente');
    if (safeColsResult.isError()) throw safeColsResult.exceptionOrNull()!;

    query.commandText = '''
      SELECT *
      FROM Produto
    ''';

    return await query.open();
  });

  try {
    result.fold(
      (success) {
        while (!query.eof) {
          recordCount++;
          //debugPrint('Record: ${query.field('CodProduto').asInt}');
          //debugPrint('Record: ${query.field('Nome').asString}');
          //debugPrint('Record: ${query.field('Email').asString}');
          //debugPrint('Record: ${query.field('DataCadastro').asString}');
          query.next();
        }

        debugPrint('Total records in recordCount: $recordCount');
        debugPrint('Total records in query: ${query.recordCount}');
      },
      (failure) {
        debugPrint('Error in SELECT: $failure');
        debugPrint('Stack trace: ${failure.toString()}');
      },
    );
  } catch (e, stackTrace) {
    debugPrint('Fatal error during processing: $e');
    debugPrint('Stack trace: $stackTrace');
  } finally {
    await query.close();
    debugPrint('Connection closed.');
  }
}
1
likes
140
points
39
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for ODBC database connectivity with support for SQL Server, PostgreSQL, and Sybase Anywhere. Features connection pooling, bulk operations, query metrics, and automatic SELECT interception with CAST.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dart_odbc, flutter, flutter_dotenv, result_dart, uuid

More

Packages that depend on connect_database