FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

use DDBI in mysql runtime error!

 
Post new topic   Reply to topic     Forum Index -> DDBI
View previous topic :: View next topic  
Author Message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Sat Aug 12, 2006 3:36 am    Post subject: use DDBI in mysql runtime error! Reply with quote

I use dbi in mysql,windowsXP,MySql5.01,DMD163.

execute mysql function OK,but exec a query,select * from table1, return an error:"Error: Access Violation" please give me a help! thanks!

Code:

module testdbi;

import dbi.Row;
import dbi.mysql.MysqlDatabase;

import std.stdio;
import std.c.stdio;
import std.file;

version(build)
{   
   pragma(link, "dbi.lib");
}


void main(char[][] args)

   // PgDatabase db = new PgDatabase(); 
   MysqlDatabase db = new MysqlDatabase(); 
   db.connect("dbname=test","test1","abc"); 
      
   writefln("\ndump ...");
   Row[] rows;
   
   try{
      rows = db.queryFetchAll("select ID,CITY from sample2");
   }
   catch(Object e)
   {
      printf("SysEROR: ?.*s\n", e.toString());
   }   
   
   
   foreach (Row row; rows)
   {   
      writefln("ID: ?s CITY: ?s", row["ID"], row["CITY"]); 
   } 
   
   db.close();

   writefln("\npress ENTER key to continue");
   std.c.stdio.getchar();
}


________
medical marijuana patient


Last edited by ideage on Wed Feb 02, 2011 5:00 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Kwi



Joined: 11 Aug 2006
Posts: 5

PostPosted: Sat Aug 12, 2006 7:10 am    Post subject: Reply with quote

DBI isn't very robust at the moment and lacks proper error handling in many places.

One possible cause for an access violation is an error in your SQL statement.

You should try to produce the smallest program that still causes an access violation, or insert some writefln() statements here and there, to pin-point the exact location where the problem occurs.
Back to top
View user's profile Send private message Send e-mail
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Sun Aug 13, 2006 3:54 am    Post subject: Reply with quote

Thanks!

this error possible is D language,I paste all code at top topic.

pleae compile top code!
________
EXTREME VAPORIZER


Last edited by ideage on Tue Mar 15, 2011 2:43 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Kwi



Joined: 11 Aug 2006
Posts: 5

PostPosted: Sun Aug 13, 2006 1:03 pm    Post subject: Reply with quote

I cannot compile the above code, as I'm not on a Windows machine.

However, could I compile it, I'd indeed get an error, as the MySQL credentials are incorrect for my machine, I have no database "test", and even if I had, it wouldn't contain a table called "sample2". Any of these problems would probably cause an access violation.

As I said, to figure out where exactly the problem occurs, please either:

  • Reduce the program to the smallest one that still causes an access violation. I hardly suspect that the call to std.c.stdio.getchar(); is the culprit, so there's at leaste one line that can be cut.

  • Insert some writefln() statements in the code, allowing you to figure out how far the program runs before crashing. For instance, tell us whether the program gets to print "dump ..." to the screen before crashing, and insert your own writefln statements.

If you have a problem with the console window disappearing when the program exits, start Command Prompt and run the program from there.
Back to top
View user's profile Send private message Send e-mail
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Mon Aug 14, 2006 2:21 am    Post subject: Reply with quote

Thanks Kwi, I try you method, I find it.

Code:

override Row fetchRow () {
      MYSQL_ROW mrow = mysql_fetch_row(m_res);
      if (mrow is null) {
         return null;
      }
      MYSQL_FIELD* field;
      int fieldCount = mysql_num_fields(m_res);
      printf("FieldCount: ?.*s\n",std.string.toString(fieldCount));
      Row r = new Row();
      for (int idx = 0; idx < fieldCount; idx++) {
         //printf("CurField: ?.*s\n",std.string.toString(idx));
         printf("FetchFieldDirect: ?.*s\n",std.string.toString(idx));
         field = mysql_fetch_field_direct(m_res, idx); //error
         printf("AddField: ?.*s\n",std.string.toString(idx));
         printf("AddFieldName: ?s\n",field.name);
         r.addField(std.string.toString(field.name), std.string.toString(mrow[idx]), "", field.type);
         
      }
      return r;
   }



when i run my test, screen display:

D:\D\DB\DDBI\test>testdbi

dump ...
FieldCount: 3
FetchFieldDirect: 0
AddField: 0
AddFieldName: ID
FetchFieldDirect: 1
SysEROR: Access Violation

press ENTER key to continue


this error in DDBI. I want fix it.
________
Medical Cannabis


Last edited by ideage on Tue Mar 15, 2011 2:43 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Kwi



Joined: 11 Aug 2006
Posts: 5

PostPosted: Tue Aug 15, 2006 4:02 am    Post subject: Reply with quote

This is a very odd problem.

First (assuming you didn't change the query), mysql_num_fields() returns the wrong result: 3 instead of 2.

But instead of crashing trying to access the third field (which isn't there), mysql_fetch_field_direct crashes trying to access the second field (which is, or should be).

I've tried out your code (with the appropriate modifications), and failed to reproduce the problem, it runs fine for me.

I'm inclined to believe that this is not a fault in D DBI, but either a fault in your MySQL client library (are you using the latest version of mysql.dll/mysqlclient.dll/whatever?), or an incompatibility in your version of dbi.lib.

Try recompiling the program without using the precompiled dbi.lib, instead just pulling in the dbi source files directly (via build). You'd have to change the link pragma to... uh, "mysqlclient.lib" or something like that. (My Windows programming skills are quite rusty, I'm afraid.)
Back to top
View user's profile Send private message Send e-mail
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Tue Aug 15, 2006 8:07 pm    Post subject: Reply with quote

aha,I test DDBI use PostgreSQL 8.1.4 on WinXP, occur same error.

but I use Sqlite3,it work very fine.

this is a odd problem truly.

DMD 1.0 will release,all dsource projects slow down. DDBI'Row discuss a long time.
________
Ford Gyron picture


Last edited by ideage on Wed Feb 02, 2011 5:00 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
MarkD



Joined: 18 Jul 2005
Posts: 8

PostPosted: Mon Sep 18, 2006 7:34 pm    Post subject: Reply with quote

Not quite on topic, but...

I just setup the latest version (Windows, ODBC, Access Driver) and got this generic error as well. In my case, the error originates from the Northwind database - where they use spaces in field names. Unfortunately a lot of Windows users might attempt this and not realize that their code is fine. God save the newbies!

For what it's worth, this doesn't work:
Code:
rows = db.queryFetchAll("SELECT * FROM Employees WHERE City = 'Seattle'");


but this does:
Code:
rows = db.queryFetchAll("SELECT 'Employee ID', 'Last Name', 'First Name', Title, 'Title Of Courtesy', 'Birth Date', 'Hire Date', Address, City, Region, 'Postal Code', Country, 'Home Phone', Extension, Photo, Notes, 'Reports To' FROM Employees WHERE City = 'Seattle'");


I do get a seemingly pointless access violation on exit though - just for creating a new OdbcDatabase.
_________________
Mark Delano
Back to top
View user's profile Send private message
jpelcis



Joined: 09 Mar 2006
Posts: 40

PostPosted: Wed Sep 20, 2006 12:33 pm    Post subject: Reply with quote

Sorry all for the long time between the last two releases. My life has been a little hectic lately.

MarkD wrote:
I do get a seemingly pointless access violation on exit though - just for creating a new OdbcDatabase.


Nice to see you back. Try the new version of D DBI. I think it has the access violation fixed.

ideage wrote:
DDBI'Row discuss a long time.


The changes to Row.d won't be put in until 0.3.0. There are some other things I'd like to have done by that milestone, such as the Oracle DBD.
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Sat Sep 30, 2006 7:51 am    Post subject: Reply with quote

yeah,it fixed! Thanks!
________
girlfriends pics
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DDBI All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group