I have this code working for coldfusion, but when i port it to lucee it fails, i know that macromedia does not work in lucee, how can i make this a possibility in lucee and want to remove the connection string, but the result should be exactly like the how the function is returning me
// open a connection to the database
Class = createObject("java", "java.lang.Class");
Class.forName("macromedia.jdbc.sqlserver.SQLServerDriver");
manager = createObject("java", "java.sql.DriverManager");
connectionURL = "jdbc:macromedia:sqlserver://"& SESSION.USER.dbServer &":"& SESSION.USER.dbPortNumber & ";EncryptionMethod=SSL;ValidateServerCertificate=false;";
connection = manager.getConnection(connectionURL, SESSION.USER.dbUser, SESSION.USER.dbPass);
You might define this data source in the Admin instead of in the application code. One thing that screams "big red flag" in your existing code is that the database server name is defined in a cookie. Makes me wonder what other things are in cookie values that need to be refactored.
Read the documentation for defining a data source:
this.datasources["myds"] = {
class: 'org.gjt.mm.mysql.Driver'
, connectionString: 'jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=true'
, username: 'root'
, password: "encrypted:5120611ea34c6123fd85120a0c27ab23fd81ea34cb854"
};
The example is for MySQL, but you need to find the correct driver name for SQL Server used by Lucee. Go to the admin and create the DSN there to find the driver name.
Related
If have multiple databases defined on a particular ArangoDB server, how do I specify the database I'd like an AQL query to run against?
Running the query through the REST endpoint that includes the db name (substituted into [DBNAME] below) ie:
/_db/[DBNAME]/_api/cursor
doesn't seem to work. The error message says 'unknown path /_db/[DBNAME]/_api/cursor'
Is this something I have to specify in the query itself?
Also: The query I'm trying to run is:
FOR col in COLLECTIONS() RETURN col.name
Fwiw, I haven't found a way to set the "current" database through the REST API. Also, I'm accessing the REST API from C++ using fuerte.
Tom Regner deserves primary credit here for prompting the enquiry that produced this answer. I am posting my findings here as an answer to help others who might run into this.
I don't know if this is a fuerte bug, shortcoming or just an api caveat that wasn't clear to me... BUT...
In order for the '/_db/[DBNAME/' prefix in an endpoint (eg full endpoint '/_db/[DBNAME/_api/cursor') to be registered and used in the header of a ::arangodb::fuerte::Request, it is NOT sufficient (as of arangodb 3.5.3 and the fuerte version available at the time of this answer) to simply call:
std::unique_ptr<fuerte::Request> request;
const char *endpoint = "/_db/[DBNAME/_api/cursor";
request = fuerte::createRequest(fuerte::RestVerb::Post,endpoint);
// and adding any arguments to the request using a VPackBuilder...
// in this case the query (omitted)
To have the database name included as part of such a request, you must additionally call the following:
request->header.parseArangoPath(endpoint);
Failure to do so seems to result in an error about an 'unknown path'.
Note 1: Simply setting the database member variable, ie
request->header.database = "[DBNAME]";
does not work.
Note 2: that operations without the leading '/_db/[DBNAME]/' prefix, seem to work fine using the 'current' database. (which at least for me, seems to be stuck at '_system' since as far as I can tell, there doesn't seem to be an endpoint to change this via the HTTP REST Api.)
The docs aren't very helpful right now, so just incase someone is looking for a more complete example, then please consider the following code.
EventLoopService eventLoopService;
// adjust the connection for your environment!
std::shared_ptr<Connection> conn = ConnectionBuilder().endpoint("http://localhost:8529")
.authenticationType(AuthenticationType::Basic)
.user(?) // enter a user with access
.password(?) // enter the password
.connect(eventLoopService);
// create the request
std::unique_ptr<Request> request = createRequest(RestVerb::Post, ContentType::VPack);
// enter the database name (ensure the user has access)
request->header.database = ?;
// API endpoint to submit AQL queries
request->header.path = "/_api/cursor";
// Create a payload to be submitted to the API endpoint
VPackBuilder builder;
builder.openObject();
// here is your query
builder.add("query", VPackValue("for col in collections() return col.name"));
builder.close();
// add the payload to the request
request->addVPack(builder.slice());
// send the request (blocking)
std::unique_ptr<Response> response = conn->sendRequest(std::move(request));
// check the response code - it should be 201
unsigned int statusCode = response->statusCode();
// slice has the response data
VPackSlice slice = response->slices().front();
std::cout << slice.get("result").toJson() << std::endl;
We are trying to create a cookie in the PeopleSoft Peoplecode by using the %Response object.
However, the code we tried is failing.
&YourCookie = %Response.AddCookie("YourCookieName", "LR");
Another snippet we tried to create the cookie
Local object &Response = %Response;
Local object &YourCookie;
&YourCookie = &Response.CreateCookie("YourCookieName");
&YourCookie.Domain = %Request.AuthTokenDomain;
&YourCookie.MaxAge = -1; /* Makes this a session cookie (default) */
&YourCookie.Path = "/";
&YourCookie.Secure = True; /* Set to true if using https (will still work with http) */
&YourCookie.Value = "Set the cookie value here. Encrypt sensitive information.";
The document reference points to IScript functions called CreateCookie methods etc.
http://docs.oracle.com/cd/E15645_01/pt850pbr0/eng/psbooks/tpcr/chapter.htm?File=tpcr/htm/tpcr21.htm
However, these don't work in Peoplecode. We don't have the knowledge to create IScript or use it. Any insight with the People code API for cookies or IScript is much appreciated.
I just tested on PeopleTools 8.54.11 and was able to create a cookie using the snippet you provided above.
I did find I had an issue if I set
&YourCookie.Secure = True;
in an environment where I was using HTTP.
If you set Secure to False the cookie will be available in both HTTP and HTTPS
if you set Secure to True the cookie is only available in HTTPS
PeopleTools 8.54 Documentation showing the CreateCookie method
I have been trying to do this (same code snippet) from within signon peoplecode, tools release is 8.54.09. I can execute the first two lines of code, but as soon as the line of code executing the CreateCookie() method executes, I get tossed out / end up on the signon error page.
This seems to support the previous answer saying that the API has removed the method, but the answer before that says it has been successful on tools 8.54.11 -- does that mean they removed it, then put it back, and I happen to be stuck with a release where it was removed? :-/
I am trying to access our AS400 database with Ruby on Rails, using the "dbi" gem and the "dbd-odbc" gem.
I have found this code to build off of. When I pass in the server address...
It seems that the original code uses an DSN, but I wanted to pass in the IP, database name, and library in the code to prevent any DSN being needed.
require 'dbi'
dbh = DBI.connect('DBI:ODBC:SYSTEM=<ip_address>;DBQ=<db_name>;DFTPKGLIB=<library_name>;LANGUAGEID=ENU', 'UID=<user_name>', 'PWD=<password>')
sth = dbh.prepare('select count(*) from my_table')
sth.execute
# Print out each row
while row=sth.fetch do
p row
end
sth.finish
dbh.disconnect
it gives me an error of...
DBI::InterfaceError: Unable to load driver 'ODBC'
what would be the correct syntax?
This works for me - also, just put your authentication portion inside of the first argument to the DBI.connect function:
First install the gems: dbi, dbd-odbc, ruby-odbc. I was getting the same error without the ruby-odbc gem
Then:
require 'odbc'
require 'dbi'
dbh = DBI.connect('DBI:ODBC:SYSTEM=MYAS400;DBQ=TABLE_NAME;DFTPKGLIB=SCHEMA_NAME;DRIVER=Client Access ODBC Driver (32-bit);LANGUAGEID=ENU;USERID=SUPERADMIN;PWD=SUPERSECURE')
I don't know exactly how that works in Ruby, but in the connection string I don't see where you mention the driver your trying to use to connect.
Seems like this line:
dbh = DBI.connect('DBI:ODBC:SYSTEM=<ip_address>;DBQ=<db_name>;DFTPKGLIB=<library_name>;LANGUAGEID=ENU', 'UID=<user_name>', 'PWD=<password>')
needs to be something like this to indicate the driver ODBC should use to connect:
dbh = DBI.connect('DBI:ODBC:Driver=iSeries Access ODBC Driver;SYSTEM=<ip_address>;DBQ=<db_name>;DFTPKGLIB=<library_name>;LANGUAGEID=ENU', 'UID=<user_name>', 'PWD=<password>')
It seems that c++ drivers doesn't accept mongodb connection uri format.
There's no documentation on how i should create connection string, any guess?
I need to connect to a replica set with 3 servers, and set readPreference options.
Create a connection to a replica set in MongoDB C++ client
Until the problems explained in #acm's answer are resolved, I have found a workaround to the bad Connection Strings of the C++ driver. You can create a DBClientReplicaSet using a vector of hosts and ports this way:
//First create a vector of hosts
//( you can ignore port numbers if yours are default)
vector<HostAndPort> hosts;
hosts.push_back(mongo::HostAndPort("YourHost1.com:portNumber1"));
hosts.push_back(mongo::HostAndPort("YourHost2.com:portNumber2"));
hosts.push_back(mongo::HostAndPort("YourHost3.com:portNumber3"));
//Then create a Replica Set DB Client:
mongo::DBClientReplicaSet connection("YourReplicaSetName",hosts,0);
//Connect to it now:
connection.connect();
//Authenticate to the database(s) if needed
std::string errmsg;
connection.auth("DB1Name","UserForDB1","pass1",errmsg);
connection.auth("DB2Name","UserForDB2","pass2",errmsg);
Now, you can use insert, update, etc. just as you did with DBClientConnection. For a quick fix, you can replace your references to DBClientConnection with DBClientBase (which is a parent to both DBClientConnection and DBClientReplicaSet)
Last pitfall: if you are using getLastError(), you must use it with the aimed database name like this:
connection.getLastError(std::string("DBName"));
cause otherwise it will always return "command failed: must log in" as described in this JIRA ticket.
Set the read preferences for every request
You have two ways to do that:
SlaveOK option
It lets your read queries be directed to secondary servers.
It takes place in the query options, which are at the end of the parameters of DBClientReplicaSet.query(). The options are listed in Mongo's official documentation
The one you would look for is mongo::QueryOption_SlaveOk, which will allow you to have reads made on secondary instances.
This is how you should call query();
connection.query("Database.Collection",
QUERY("_id" << id),
n,
m,
BSON("SomeField" << 1),
QueryOption_SlaveOk);
where n is the number of documents to return (0 if you don't want any limit), m the number to skip (defaults to 0), the next field is your projection and the last your query option.
To use several query option, you can use bitwise or | like this :
connection.query("Database.Collection",
QUERY("_id" << id),
n,
m,
BSON("SomeField" << 1),
QueryOption_SlaveOk | QueryOption_NoCursorTimeout | QueryOption_Exhaust);
Query::readPref option
The Query object has a readPref method which sets read preferences for a special query. It should be called for each query.
You can pass different arguments for more control. They are listed here.
So here's what you should do (I did not test that one cause I can't right now but it should work just fine)
/* you should pass an array for the tags. Not sure if this is required.
Anyway, let's create an empty array using the builder. */
BSONArrayBuilder bab;
/* if any, add your tags here */
connection.query("Database.Collection",
QUERY("_id" << id).readPref(ReadPreference_SecondaryPreferred, bab.arr()),
n,
m,
BSON("SomeField" << 1),
QueryOption_NoCursorTimeout | QueryOption_Exhaust);
Note: if any readPref option is used, it should override the slaveOk option.
Hope this helped.
Please see the connection string documentation for details on the connection string format.
(code links below are to 2.2.3 files)
To use a connection string with the C++ driver, you should use the ConnectionString class. You first call the ConnectionString::parse static method with a connection string to obtain a ConnectionString object. You then call ConnectionString::connect to obtain a DBClientBase object which you can then use to send queries.
As for read preference, at the moment I do not see a way to set the read preference in the connection string for the C++ driver, which would preclude a per-connection setting.
However, the implementation of DBClientBase returned by calling ConnectionString::parse with a string that identifies a replica set will return you an instance of DBClientReplicaSet. That class honors $readPreference in queries, so you can set your read preference on a per-query basis.
Since the current C++ drivers still do not accept the standard mongodb connection URIs, I've opened a ticket:
https://jira.mongodb.org/browse/CXX-2
Please vote for it to help get this fixed.
it seems like you can set read Preference before send a read request by call "readPref" method of your Query object. I'v not found a way to set read Preference on mongo collection object yet.
So I found some code
<cfset x509 = GetPageContext().getRequest().getAttribute("javax.servlet.request.X509Certificate") />
<cfoutput>not before = #x509[1].getNotBefore()#</cfoutput><br/>
<cfoutput>not after = #x509[1].getNotAfter()#<br></cfoutput>
<cfoutput>#ToBase64(x509[1].getEncoded())#<br></cfoutput>
<cfoutput>#x509[1].getIssuerDN()#<br></cfoutput>
<cfoutput>#x509[1].getIssuerX500Principal()#<br></cfoutput>
What I want this code to do is display the information from the CAC, instead I am getting an error Variable X509 is undefined...
Edit
An alternate solution seems to be to use CGI.CERT_SUBJECT however I am not exacly sure how to get this variable to be anything other than an empty string. FWIW I am try to get this to work on a standalone coldfusion server.
The getAttribute() method returns a NULL variable when the attribute is not found, which is what's happening in this case. You have to see if it's defined before you can display it.
<cfif StructKeyExists( variables, "x509" )>
{ Code }
</cfif>
On how to get the attribute you're after, I couldn't tell you, but this will prevent the error from occuring.
Depending on your web server (I know Apache does this if you set SSLOptions +StdEnvVars +ExportCertData), you can get the PEM-encoded cert as an environment variable (i.e., cgi.ssl_client_cert) and you can get other info (DN, issuer's DN, etc) as well. Here's a list of the environment variables.