Solved

Insert unformated data with SQL into Database

Posted on 2004-04-13
8
213 Views
Last Modified: 2008-02-01
Hi,
I’m working on a small thing where I have to save an encrypted string in a Database.
I’m using an Access database at the moment, but want to be able to change database engine later if necessary.

(What I'm trying to do is to break down a structure and save it in a database instead of on file as we do it today.)

The actual problem:
I can successfully store all data extracted from the structure in my database except for the encrypted string below.

/********* Encrypted String ***********/

ã‚[Á‚T ú             0  ÿÐ 0  ÿÐ  ÿÐ 0 0 0 0ÿÐÿÐÿеkã+‰! TZ8½1ùcÐŐ$Þq¿¬žkÌ¿(¯Rõ<•&>kIŽ—cÞz43¡[îùVœdqýHcáÙH@öK@Ô±ËÔJ•Ô†¹ó«¾í'Æã—;¦o+׎$’“ô3AÇ ,Š±h(!ŸW4˜6~;%¦>׆7”Õí6 ìNMÙiÍÆÚºæÔÑMj +‰=ÌV]8„1ed¯ÅµPØ؁¼]eé<)óÜVu@”V>oH
½gQz4 Zšp;‰)ãg͸”ÁÖt¿µ ëÈ~,ªv#Ó00kšâ7Ÿ      žêN‚¨«Åo„wÕƒÐйÕd¼%é1LP=tŒ=i%A'FÔ~µ¿Û{QÆâ¯îL‡éI¼š¸õÐKj*ŽÁK·¢r¸|ð›_Å…p%&òL]
y6ì`*5<‹×Ñs¸Â²‡äÒˏ¢›ñÛ~MúËsÐ&ô£6R˜“      ð<ë©V ¬ñ@X­Ñ¼¶a_µqæ¶;€]’÷-b÷(gҍ°k7À­tÁÊd1vÚ3D™ˆþ0$–q«?îz\Kgå
Ðs‰Èú°}™“Õÿ›Òúø#‹ËVâè–¤À1 B°ª,™Ùé'ºXRup3Ñ{ú¢XÁ+i6@¶ Áq+ ZmY;ÌÃòºòPÓU(–¿Œ«½'„0¥°{¥“;Þ±D;²£ç-qNÜKr¡{ÑW~S`ü)†ÇÌCd:v©œ¬W&*•
-¯m
+ª•à+vÁ §¥Èü>›¯åµŸ%%Ž| ¬è³~¹ UÊ¿t(!lwM™f81¥eðË…QœhMúOlÀ)tÃ:UP7@èAPR9 d  ÿ     f¨´y¸$}ÌX”ίÔXkÖtsÚÄfæ” ^èÄ
ãêÈö$J U
      K ‰@u—|)刅… ™ ¤z¾…
                                                            Â)
/**********************************************/

The problem is that when I try to store the encrypted data, I only succeed to save the first 11 characters for some reason.
(The field in the database is set as PM to be able to take anything very long.)

The encrypted data is stored in a structure that looks like this:
typedef struct bioapi_hrs_bir
{
      BioAPI_BIR_HEADER  Header;
      BioAPI_BIR_BIOMETRIC_DATA_PTR BiometricData; /* length indicated in */
                                                                           /* header                    */
      BioAPI_DATA_PTR Signature;      /* NULL if no signature; length is inherent */
                                            /* in this type                                            */
} BioAPI_BIR, *BioAPI_BIR_PTR;

The encrypted biometric string is stored in pBIR->BiometricData (in my code)

If I save the whole structure into a file with fwrite it works, but when I want to create a string in SQL to save the same information in my database it doesnt.
(I would guess that it has to do with sprintf that stops at the next NULL.)

I create the string with sprintf (I know that sprintf stops at the next NULL, but I have also tryed to override this by specifying the precision)
sprintf(strSqlQuery,"INSERT INTO fingerprint(fID, fBIR, fhLength, fhType, fhfFormatId, fhfFormatOwner, fhQuality, fhPurpose, fhFactorsMask, fsLength, fsData) VALUES('%s', '%s', %d, %d, %d, %d, %d, %d, %d, %d, '%s')",strName, pBir->Biostring, pBIR->Header.Length, pBIR->Header.Type, pBIR->Header.Format.FormatID, pBIR->Header.Format.FormatOwner, pBIR->Header.Quality, pBIR->Header.PurposeMask, pBIR->Header.FactorsMask, 0, "");

If i print the result of the abowe, it looks like this:
INSERT INTO fingerprint(fID, fBIR, fhLength, fhType, fhfFormatId, fhfFormatOwner, fhQuality, fhPurpose, fhFactorsMask, fsLength, fsData) VALUES('Tomas Nilsson4', 'ã‚[Á‚T', 879, 4, 1, 11, 91, 1, 8, 0, '')

Anyway, the problem is (as I wrote before) that only the first 11 characters gets stored in the database (ã‚ [Á‚ T  ú)
Is there any way to do this without binding my self to a specific database?
I solved this problem before in VB by using ADO instead of writing the whole sql string, but I can’t bind towards Access this time.

Does anyone have any ideas?
( I understand if you don't understand what I'm trying to explain, but just post me and I'll try to do it better ;-)  )

Thanks in advance!

Kind Regards, Tomas
0
Comment
Question by:tnson
  • 4
  • 2
8 Comments
 
LVL 12

Expert Comment

by:stefan73
ID: 10812968
Hi tnson,
The problem usually is with binary zeroes and proper escaping of characters.
Use the chr() function for your special characters (Oracle example, might need '+' instead of '||'):

select 'Hello World' || chr(13) || chr(10) || 'Next line' from dual

Cheers,
Stefan
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10813044
tomas,
I'm not sure if your DB can handle SQL statements containing characters with ASCII code > 128 (such as 'ÄÖÜ') directly. It should (maybe even with unicode), but don't bet on it.


Stefan
0
 

Author Comment

by:tnson
ID: 10813359
Hi,
Maybee the only way is to convert all characters in the string to their respective character code!?
What I would really like to do is to just dump the whole string in the table and read it back when necessary...... the easy way ;-)

if I should convert all characters in the string then..... what's the best way to go?
The string is over 800 characters long, so it might take some time to make the conversion, and time is something I have to be carefull with in this case.


Regards, Tomas
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Accepted Solution

by:
stefan73 earned 200 total points
ID: 10813486
tomas,
The easiest way is probably to convert it into a BLOB. Access supports some "binary data type", if I remember correctly.
Stefan
0
 

Author Comment

by:tnson
ID: 10813950
Ok, sounds like a good idea.
Do you have any ideas of how to do the conversion as well? =)



// Tomas
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10823644
tnson,
> Do you have any ideas of how to do the conversion as well?
Unfortunately not... I don't have MS Access here.

Stefan
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now