Convert String to Octet lazarus / 62-General ---------------------------------------------------------------------- RedOctober · 2022-01-19 17:57 Platform: Windows Server 2016 - latest updates.  Lazarus 2.0.10,  FPC 3.2.0, Firebird 3x ADDED THE LINE BELOW TO THE DESCRIPTION OF THE PROBLEM-BEGIN The Account ID is a GUID, not a number stored as a string.  I need to ensure the customer didn't just make up a GUID like, GUID looking string of characters, that is not actually convertable to a GUID.  A real GUID is convertible to OCTET form. ADDED THE LINE ABOVE TO THE DESCRIPTION OF THE PROBLEM-END I have a "customer" table with an OCTET field as the unique identifier.  (CHAR(16) Character set OCTETS, Collation OCTETS.  The "customer" table also has a "Username" field that is a VARCHAR(50).  Customers can log in using either their Username (which is the normal way) or the Account ID (which is a string that converts to an OCTET, which is the "account recovery" mode if they forgot their Username. I did this so I'd have an unlimited number of non-sequentially issued unique identifiers to assign, even larger than a BIGINT, and yet maintain a lighting fast query speed, since an OCTET is handled like an integer. Goal:  I'm at the point where I need to validate that the Account ID string is a valid OCTET, before I try to use it in a query against the Firebird database.  Firebird will choke and error out if it cannot convert the queried string to an OCTET, so I want to ensure the string coming in the Username input from the web page is convertible to an OCTET in Pascal first. I can't find a function to do this, only a function to do the opposite conversion  (OctStr) which is not what I want.  Here is what I have at the moment: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...var login_id, login_id_oct, pwd, err_msg: String;begin    // Determine if the Login ID is an Account ID  if (Length(login_id) = 36) then    begin      if TryStrToOct(login_id, login_id_oct) then        begin        // Customer has entered their Account ID for lookup as an OCTET        end      else        begin          // Customer has entered something other than an Account ID, so treat it as an ordinary string        end;     end;  I need a "TryStrToOct" which doesn't seem to exist. Any suggestions? ---------------------------------------------------------------------- ASerge · 2022-01-19 18:52 Quote from: RedOctober on January 19, 2022, 06:57:01 pmI need a "TryStrToOct" which doesn't seem to exist. Any suggestions? Write it! ---------------------------------------------------------------------- Bart · 2022-01-19 21:49 I'm not sure what you mean by Octet. If that is a number in octal notation (since you mention you need the reverse of OctStr), then you can simply use Val() on it. Just prefix the string in question with a '&': Val('&10', V, Err) should set V to 8 and Err to 0. And since Val() understand octal notation, so do all the TryStrToInt versions. Bart ---------------------------------------------------------------------- RedOctober · 2022-01-19 21:55 I added the lines shown to describe the predicament better.  I shd have included that in the original post. ---------------------------------------------------------------------- winni · 2022-01-19 21:59 Hi! The confusion continues: * Octet is sometimes used as high-brow synonym for a byte * The Linux file rights are represented by an octal number:     chmod 644 ./ThisFile Winni ---------------------------------------------------------------------- Josh · 2022-01-19 22:16 I always thought an OCTET was always 8 bits (0-255), Nibble always 4 bits. a Byte does not have to be 8 bits its hardware/architecture dependent. So I to am confused. ---------------------------------------------------------------------- winni · 2022-01-19 22:49 Hi! But the most systems where a byte had a different  length than 8 bit are dead: * Telex * PDP * Univac * IBM 1401 (my uncle worked on it) .... ISO defines a byte with a minimum of 8 bits. But I think in the very most cases it is used as a synonyme for 8 bits. Winni ---------------------------------------------------------------------- Bart · 2022-01-19 23:00 I guess he's referring to firebirds chatset OCTETS. See https://www.firebirdsql.org/file/community/ppts/fbcon11/FbCon2011- Charsets-Heymann.pdf page 59. QuoteSpecial Character Sets ● NONE: Plain octets, no character set applied. With this character set setting, Firebird is unable to perform conversion operations like UPPER() correctly on anything other than the standard 26 latin letters. ● OCTETS: Same as NONE. Cannot be used as client connection character set. Space character is #x00 Basically no encoding on the characters. A bit like RawByteString. And I think an OCTET here means a byte, since QuoteOCTET_LENGTH: length of a string in bytes Quote from: RedOctober on January 19, 2022, 06:57:01 pmThe Account ID is a GUID, not a number stored as a string.  I need to ensure the customer didn't just make up a GUID like, GUID looking string of characters, that is not actually convertable to a GUID.  A real GUID is convertible to OCTET form. So, now IIUC, the question is if the inputstring represents a proper GUID? Bart ---------------------------------------------------------------------- RedOctober · 2022-01-19 23:34 Correct Bart.  That's a better way of putting it than I did. ---------------------------------------------------------------------- Josh · 2022-01-19 23:59 if its guid, sysutils has function TryStringToGUID(const S: string; out Guid: TGUID): Boolean; function StringToGUID(const S: string): TGUID; function GUIDToString(const GUID: TGUID): string; function IsEqualGUID(const guid1, guid2: TGUID): Boolean; function GuidCase(const GUID: TGUID; const List: array of TGuid): Integer;  would these work? ---------------------------------------------------------------------- RedOctober · 2022-01-20 00:09 Bingo!  I think Josh got the right answer based on Bart's investigative powers.  I figured it would be something simple. Sorry for making you all go the "long way around".  I'm sure these will work Josh, I did not know they existed and thought I had to do a conversion to an OCTET. ---------------------------------------------------------------------- MarkMLl · 2022-01-20 12:48 Quote from: josh on January 19, 2022, 11:16:00 pmI always thought an OCTET was always 8 bits (0-255), Nibble always 4 bits. a Byte does not have to be 8 bits its hardware/architecture dependent. ...But the OP's question was phrased in a way that implied that OCTET was a data type etc. understood by a particular variant of SQL. And I have a reasonable degree of confidence that nobody would capitalise OCTET thinking that it was an initialism (Ordered Content To Expedite Transfer?) :-) (Even though even in this forum there are people who insist on capitalising WEB and suchlike). MarkMLl