Solved

Insert unformated data with SQL into Database

Posted on 2004-04-13
8
216 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

770 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