retrieve the value of a timestamp field with adodb - how to read a byte array from classic asp - asp-classic

I'm working with asp and adodb, querying a database (ms sql 2005)
I have a field named stamp, of type timestamp
in asp I get the following
field.ActualSize: 8
field.DefinedSize:
field.Name: Stamp
field.Type: adBinary (128)
field.Attributes: 528 (adFldFixed (16) + adFldRowVersion (512) )
(so adFldLong is NOT turned on, so I can't use getchunk method!)
http://msdn.microsoft.com/en-us/library/ms676678(VS.85).aspx
At the debugger, if I type field.value I get the following
? field.value
{...}
(0): 0
(1): 0
(2): 0
(3): 0
(4): 0
(5): 35
(6): 163
(7): 124
That is what I want to GET!!!! but I don't know how to do it...
I can assign it to a variable, but I can't get each element
I tried with
? cstr( field.value )
""
? field.value(0)
Número de argumentos erróneo o asignación de propiedad no válida: 'field.value'
(wrong number of arguments)
? vartype( field.value )
8209 ( 8192-vbArray + 17-vbByte )
So, the problem is I have an array of bytes, well, how do I read it???

well, I've found it...
http://www.ureader.com/msg/16755039.aspx
I had to use
h = hex( ascb( midb( barray, c, 1 ) ) )
to convert it to hex...
so I made something like this
s = ""
for c = lbound( barray ) + 1 to ubound( barray ) + 1
h = hex( ascb( midb( barray, c, 1 ) ) )
h = padl( h, 2, "0" )
s = s & h & " "
next

Related

Calling PATCH API method returns 400 error?

I'm trying to call a PATCH Method API within ABAP, but i am always getting code 400 back with error message that content type is not supported, its needed application/json which i am setting already in the code.
cl_http_client=>create_by_url(
EXPORTING
url = lv_url
IMPORTING
client = lo_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
* Set request parameter (Authorization)
lo_client->request->set_header_field(
name = mc_param_name_authorization
value = mc_auth_type_bearer && | { mv_access_token }|
).
* Set request parameter (apiKey)
lo_client->request->set_header_field(
name = mc_param_name_apikey
value = CONV string( ms_access_settings-api_key )
).
* Set request parameter (realm)
lo_client->request->set_header_field(
name = mc_param_name_realm
value = get_realm( mc_api_call_approve )
).
lo_client->request->set_method( 'PATCH' ).
lo_client->request->set_content_type( 'application/json' ).
lo_http_client->request->set_cdata( lv_body_json ).
lo_client->send( ).
lo_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4 ).

Query filesystems and DB utilization using vi editor

I am currently monitoring multiple systems' OS (Unix) filesystem utilization and DB (Sybase) utilization. I would like to query those in one file using the vi editor. My script goes like this:
df -h
su - sybpg1
isql -Usapsa -SPG1 -PMaster4SID -w999 -X
declare #pagesize numeric(19,0)
select #pagesize=(select ##maxpagesize)
SELECT "Database Name" = CONVERT(char(30), db_name(D.dbid)),
"Data Size MB" = STR(SUM(CASE WHEN U.segmap != 4 THEN U.size*#pagesize/1048576 END),10,1),
"Used Data MB" = STR(SUM(CASE WHEN U.segmap != 4 THEN size - curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs)END)*#pagesize/1048576,10,1),
"Data Full%" = STR(100 * (1 - 1.0 * SUM(CASE WHEN U.segmap != 4 THEN curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs) END)/SUM(CASE WHEN U.segmap != 4 THEN U.size END)),9,1) ,
"Log Size MB" = STR(SUM(CASE WHEN U.segmap = 4 THEN U.size*#pagesize/1048576 END),10,1),
"Free Log MB" = STR(lct_admin("logsegment_freepages",D.dbid)*#pagesize/1048576,10,1),
"Log Full%" = STR(100 * (1 - 1.0 * lct_admin("logsegment_freepages",D.dbid) /
SUM(CASE WHEN U.segmap = 4 THEN U.size END)),8,1)
FROM master..sysdatabases D,
master..sysusages U
WHERE U.dbid = D.dbid
AND ((D.dbid != 2))
GROUP BY D.dbid
ORDER BY db_name(D.dbid)
go
but whenever i execute:
sh filename
It was able to enter sybase, however couldn't get pass through the isql line.
It goes something like this:
sybsid.sh: line 6: isql: command not found
Hope you could help me out.
Thanks!

symbols being printed when english alphabet wanted

I am writing this code and have recently come across an error. I have no idea why this is happening. In theory, the english alphabet should be being printed. However, instead of the english alphabet, symbols are being printed instead.
I can not paste the symbols for some reason, but if you ran the code yourself, you'll understand what I mean.
My full code is posted below.
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFHIJKLMNOPQRSTUVWXYZ0123456789"
choice = input("Would you like to encrypt or decrypt? [e/d]: ")
if choice == "e":
message = input("Please insert the message you would like to use: ")
keyword = input("Please insert the keyword you would like to use: ")
ik = len(keyword)
i = 0
string = ''
for A in message:
message1 = (ord(A)) - 96
key1 = (ord(keyword[i])) - 96
addition = message1 + key1
string += (chr(addition))
if i >= ik:
i = 0
else:
i += 1
print (string)
You need to add back the 96 you originally took away :) Alternatively, use the Caesar cipher formula as adding back 96 will still result in symbols appearing (I did the ocr coursework already)
addition = message1 + key1 + 96
your code will not work if the keyword is shorter than the message, so use the modulo operator (%) on i with the length of the keyword inside the line:
key1 = (ord(keyword[i])) - 96

Number pattern for checkboxes in asp.net?

I have a database table which contanis a field name Province bits and it adds up the count of the pattern like:
AB-1
BC-2
CD-4
DE-8
EF-16.... and so on.
Now in the table entry I have a value-13(Province bit), which implies checkboxes against entry AB,CD,DE(adds up to 13)should be checked.
I am not able to get the logic behind the same, how can check only those checkboxes whose sum adds up to the entry in the table?
You need to check to see if the value is in the bitwise total.
if( interestedInValue & totalValue == interestedInValue)
{
// this value is in the total, check the box
}
Documentation on & http://msdn.microsoft.com/en-us/library/sbf85k1c(v=vs.71).aspx
e.g. 13 = 1 + 4 + 8
13 & 1 == 1 // true
13 & 2 == 2 // false
13 & 4 == 4 // true
13 & 8 == 8 // true
13 & 16 == 16 // false
EDIT: for more clarification
ab.Checked = 1 && ProvinceBit == 1 // checkbox AB
bc.Checked = 2 && ProvinceBit == 2 // checkbox BC
...
The field is using bit flags.
13 is 1101 binary.
So convert the value to bits and assign one bit to each checkbox.
By converting your number to a string, you can convert to an array or just iterate through the string. A bit brute force, but will give you what you need.
var value = 13
string binary = Convert.ToString(value, 2);
//binary = "1101"

Generating complete SKUs in Classic ASP

Hi I have products that are made up of a couple of options. Each Option has a SKU Code. You can only select one option from each SKU Group and the options have to be concatenated in the order of the SKUGroup.
So for example i would have a list of options in a table in the DB that looked like
OptID PID SKU Price SKUGroup
156727 93941 C 171.00 1
156728 93941 BN 171.00 1
156729 93941 PN 171.00 1
156718 93940 W 115.20 2
156719 93940 CA 115.20 2
156720 93940 BA 115.20 2
156721 93940 BNA 115.20 2
156722 93940 BN 115.20 2
156723 93940 BS 115.20 2
156716 93939 CHR 121.50 3
156717 93939 NK 138.00 3
And a few finished product SKUs would look something like:
C-W-CHR 407.70
C-W-NK 424.20
C-CA-CHR 407.20
C-CA-NK 424.20
I am trying to make a script that will create a listing of every possible combination of SKU and the price of the combined options.
I need this done in Classic ASP (vbscript) and I'm not that familiar with it. So I'm looking for all the help I can get.
Thanks!
I would start by connecting to the database and creating three recordsets.
Set connection = CreateObject("ADODB.Connection")
connection.Open ConnectionString
Set rsOption1 = CreateObject("ADODB.recordset")
Set rsOption2 = CreateObject("ADODB.recordset")
Set rsOption3 = CreateObject("ADODB.recordset")
rsOption1.Open "SELECT * FROM TableName WHERE SKUGroup = 1", connection, 3,3
rsOption2.Open "SELECT * FROM TableName WHERE SKUGroup = 2", connection, 3,3
rsOption3.Open "SELECT * FROM TableName WHERE SKUGroup = 3", connection, 3,3
Then you can use nested loops to get the combinations. Something like this (Untested, this probably will not work as is, but it gives you an idea of how to do this) (Also this assumes that you have to select at least one option from each group)
for i = 0 to rsOption1.RecordCount
rsOption1.Move i, 1
for j = 0 to rsOption2.RecordCount
rsOption2.Move j, 1
for k = 0 to rsOption3.RecordCount
rsOption3.Move k, 1
'Write rsOption1.Fields(2).Value & "-" & rsOption2.Fields(2).Value & _
'"-" & rsOption3.Fields(2).Value & " " & _
'FormatCurrency((rsOption1.Fields(3).Value + rsOption2.Fields(3).Value + rsOption3.Fields(3).Value))
Next
Next
Next

Resources