Guest User

Untitled

a guest
Jun 8th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
  2. E/flutter ( 4789): 'package:sqljocky5/src/buffered_socket.dart': error: Not a constant expression: unexpected kernel tag InvalidExpression (19)
  3. E/flutter ( 4789): #0 Connection.connect (package:sqljocky5/src/connection.dart:124:20)
  4. E/flutter ( 4789): <asynchronous suspension>
  5.  
  6. I/flutter ( 4789): opening connection
  7. I/flutter ( 4789): connection open
  8. I/flutter ( 4789): running example
  9. I/flutter ( 4789): dropping tables
  10. I/flutter ( 4789): 'package:sqljocky5/src/buffered_socket.dart': error: Not a constant expression: unexpected kernel tag InvalidExpression (19)
  11.  
  12. class Example {
  13. ConnectionPool pool;
  14.  
  15. Example(this.pool);
  16.  
  17. Future run() async {
  18. // drop the tables if they already exist
  19. await dropTables();
  20. print("dropped tables");
  21. // then recreate the tables
  22. await createTables();
  23. print("created tables");
  24. // add some data
  25. await addData();
  26. // and read it back out
  27. await readData();
  28. }
  29.  
  30. Future dropTables() {
  31. print("dropping tables");
  32. var dropper = new TableDropper(pool, ['pets', 'people']);
  33. return dropper.dropTables();
  34. }
  35.  
  36. Future createTables() {
  37. print("creating tables");
  38. var querier = new QueryRunner(pool, [
  39. 'create table people (id integer not null auto_increment, '
  40. 'name varchar(255), '
  41. 'age integer, '
  42. 'primary key (id))',
  43. 'create table pets (id integer not null auto_increment, '
  44. 'name varchar(255), '
  45. 'species text, '
  46. 'owner_id integer, '
  47. 'primary key (id),'
  48. 'foreign key (owner_id) references people (id))'
  49. ]);
  50. print("executing queries");
  51. return querier.executeQueries();
  52. }
  53.  
  54. Future addData() async {
  55. var query =
  56. await pool.prepare("insert into people (name, age) values (?, ?)");
  57. print("prepared query 1");
  58. var parameters = [
  59. ["Dave", 15],
  60. ["John", 16],
  61. ["Mavis", 93]
  62. ];
  63. await query.executeMulti(parameters);
  64.  
  65. print("executed query 1");
  66. query = await pool
  67. .prepare("insert into pets (name, species, owner_id) values (?, ?, ?)");
  68.  
  69. print("prepared query 2");
  70. parameters = [
  71. ["Rover", "Dog", 1],
  72. ["Daisy", "Cow", 2],
  73. ["Spot", "Dog", 2]
  74. ];
  75. // ["Spot", "Du0000og", 2]];
  76. await query.executeMulti(parameters);
  77.  
  78. print("executed query 2");
  79. }
  80.  
  81. Future readData() async {
  82. print("querying");
  83. var result =
  84. await pool.query('select p.id, p.name, p.age, t.name, t.species '
  85. 'from people p '
  86. 'left join pets t on t.owner_id = p.id');
  87. print("got results");
  88. return result.forEach((row) {
  89. if (row[3] == null) {
  90. print("ID: ${row[0]}, Name: ${row[1]}, Age: ${row[2]}, No Pets");
  91. } else {
  92. print(
  93. "ID: ${row[0]}, Name: ${row[1]}, Age: ${row[2]}, Pet Name: ${row[3]}, Pet Species ${row[4]}");
  94. }
  95. });
  96. }
  97. }
  98.  
  99. main() async {
  100. // OptionsFile options = new OptionsFile('connection.options');
  101. String user = "root";
  102. String password = "gashina";
  103. int port = 3306;
  104. String db = "db1";
  105. String host = "localhost";
  106.  
  107. // create a connection
  108. print("opening connection");
  109. var pool = new ConnectionPool(
  110. host: host, port: port, user: user, password: password, db: db, max: 1);
  111. print("connection open");
  112. // create an example class
  113. var example = new Example(pool);
  114. // run the example
  115. print("running example");
  116. await example.run();
  117. // finally, close the connection
  118. print("K THNX BYE!");
  119. pool.closeConnectionsNow();
  120. }
Add Comment
Please, Sign In to add comment