Is there a function like _compile_select or get_compiled_select()? - codeigniter

Looks like _compile_select is deprecated and get_compiled_select is not added to 2.1.0. Are there any other functions like those two? And also I am curious. Is there any particular reason to not adding get_compiled_select() to Active Record and removing _compile_select?

I've added get_compiled_select() to DB_active_rec.php and it seems to work without problem, but i wouldn't remove _compile_select() since it's used in many other methods.
The pull request for adding this method is here, with some other useful methods like:
get_compiled_select()
get_compiled_insert()
get_compiled_update()
get_compiled_delete()
https://github.com/EllisLab/CodeIgniter/pull/307
if you want just the method, it's just this:
/**
* Get SELECT query string
*
* Compiles a SELECT query string and returns the sql.
*
* #access public
* #param string the table name to select from (optional)
* #param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
* #return string
*/
public function get_compiled_select($table = '', $reset = TRUE)
{
if ($table != '')
{
$this->_track_aliases($table);
$this->from($table);
}
$select = $this->_compile_select();
if ($reset === TRUE)
{
$this->_reset_select();
}
return $select;
}

Related

Cannot create async method which return ElementArrayFinder for E2E tests

I have a class where I want to make a async method which will return ElementArrayFinder. I need exactly this type, not ElementFinder[] because my waiters based on it and I can wait element which isn't present now in DOM. Below you can find a simple example of the structure. At row 'return this.collection;' i have an error:
[ts]
Type 'any[]' is not assignable to type 'ElementArrayFinder'.
Property 'browser_' is missing in type 'any[]'.
I tried to cast result in a different way and tried to use Promise.resolve, but no success. Could somebody help me with this case?
export class Test {
private grid1: ElementFinder;
private grid2: ElementFinder;
get collection1(): ElementArrayFinder {
return this.grid1
.element(by.css('tbody'))
.all(by.tagName('tr'));
}
get collection2(): ElementArrayFinder {
return this.grid2
.element(by.css('tbody'))
.all(by.tagName('tr'));
}
public async getCollection(): Promise<ElementArrayFinder> {
if (await this.collection.count() === 0) {
return this.collection1;
}
return this.collection2;
}
}
Bug report
Node Version: v8.2.1
Protractor Version: 5.2.0
I found the answer in file element.d.ts file.
/**
* Retrieve the elements represented by the ElementArrayFinder. The input
* function is passed to the resulting promise, which resolves to an
* array of ElementFinders.
*
* #alias element.all(locator).then(thenFunction)
* #view
* <ul class="items">
* <li>First</li>
* <li>Second</li>
* <li>Third</li>
* </ul>
*
* #example
* element.all(by.css('.items li')).then(function(arr) {
* expect(arr.length).toEqual(3);
* });
*
* // Or using the shortcut $$() notation instead of element.all(by.css()):
*
* $$('.items li').then(function(arr) {
* expect(arr.length).toEqual(3);
* });
*
* #param {function(Array.<ElementFinder>)} fn
* #param {function(Error)} errorFn
*
* #returns {!webdriver.promise.Promise} A promise which will resolve to
* an array of ElementFinders represented by the ElementArrayFinder.
*/
then<T>(fn?: (value: ElementFinder[] | any[]) => T | wdpromise.IThenable<T>, errorFn?: (error: any) => any): wdpromise.Promise<T>;
Based on this documentation ElementArrayFinder type is resolved by .then to the ElementFinder[]. That's why I cannot create method which return ElementArrayFinder type in promise, but can create method which simply return ElementArrayFinder type.

Generate composite hbase rowkey using Flume Serializer

I have GIS data which looks like this -
'111, 2011-02-01 20:30:30, 116.50443, 40.00951'
'111, 2011-02-01 20:30:31, 116.50443, 40.00951'
'112, 2011-02-01 20:30:30, 116.58197, 40.06665'
'112, 2011-02-01 20:30:31, 116.58197, 40.06665'
First column is driver_id, second is timestamp, third is longitude & fourth is latitude.
I am ingesting this type of data using Flume & my sink is HBase (type - AsyncHBaseSink).
By default the HBase assigns rowkey as first column (like 111). I want to create a composite rowkey (like combination of first two columns 111_2011-02-01 20:30:30).
I tried putting the required changes in 'AsyncHbaseLogEventSerializer.java' but they were not reflected.
Please suggest how can I do the same.
Composite key should work in AsyncHbaseSerializer
Below is the sample code snippet.
Declare at class level privae List<PutRequest> puts = null;
/**
* Method joinRowKeyContent. (with EMPTY string separation)
*
* Joiner is google guava class
* #param objArray Object...
*
* #return String
*/
public static String joinRowKeyContent(Object... objArray) {
return Joiner.on("").appendTo(new StringBuilder(), objArray).toString();
}
/**
* Method preParePutRequestForBody.
*
* #param rowKeyBytes
* #param timestamp
*/
private void preParePutRequest(final byte[] rowKeyBytes, final long timestamp) {
// Process
LOG.debug("Processing ..." + Bytes.toString(rowKeyBytes));
final PutRequest putreq = new PutRequest(table, rowKeyBytes, colFam, Bytes.toBytes("yourcolumn"), yourcolumnasBytearray, timestamp);
puts.add(putreq);
}
Your get actions method looks like...
#Override
public List<PutRequest> getActions() {
//create rowkey like this
final String rowKey = joinRowKeyContent(driver_id, timestamp, longitude , latitude);
// call prepare put requests method here
final byte[] rowKeyBytes = Bytes.toBytes(rowKey);
puts.clear();
preParePutRequest(rowKeyBytes ,<timestamp>)
return puts;
}

Check google reCaptcha service is on or off

I am using simple google recaptcha.
My requirement is that if google api is not available (i.e. if google server is down, know its not usual case) means not getting any reply from google server then while loding the form I will hide the google reCaptcha wrapper and while submitting the form I don't want to validate google recaptcha.
Please suggest How can I achieve this.
Google does not provide that data (assuming they are always up).
But you could go about it this way. Dynamically load the script and check for the event existence in the callback. If no event is available then it failed.
Check out the #example comment for usage.
var setAttributes = function (el, attrs) {
/**
* #method simple for in loop to help with creating elements programatically
* #param {object} el - HTMLElement attributes are getting added to
* #param {object} attrs - object literal with key/values for desired attributes
* #example setAttributes(info,{
* 'id' : 'info'
* 'class' : 'my-class-name'
* });
*/
'use strict';
var key;
for (key in attrs) {
if (attrs.hasOwnProperty(key)) {
el.setAttribute(key, attrs[key]);
}
}
return el;
};
var getScript = function (url, fullPath) {
/**
* #method dynamically add script tags to the page.
* #param {url} string with relative path and file name - do not include extension
* #param {fullPath} string with absolute path
* #example getScript('FrameAdjustChild');
* #example getScript('','https://www.google-analytics.com/analytics.js');
*/
'use strict';
var setAtt, PATH = /js/, /* or wherever you keep your scripts */
el = document.createElement('script'),
attrs = {
defer: true,
src: null,
type: 'text/javascript'
};
/** look for a string based, protocol agnostic, js file url */
if (typeof fullPath === 'string' && fullPath.indexOf('http') === 0) {
attrs.src = fullPath;
}
/** look for any string with at least 1 character and prefix our root js dir, then append extension */
if (typeof url === 'string' && url.length >= 1) {
attrs.src = PATH + url + '.js';
}
setAtt = setAttributes(el,attrs);
el.addEventListener('load', function (event) {
if (event) {
/* status is good */
}
else {
/* status is bad */
}
}, false);
document.body.appendChild(el);
return el;
};

symfony 1.4 - doctrine save() method: how to identify success

Can someone please tell me how to know if the save() method was successful or not. I tried to find out if it returned true/false, but it returns null.
for example:
$contact_obj->save();
How to know that it worked?
If you use Doctrine, try trySave():
abstract class Doctrine_Record {
...
/**
* tries to save the object and all its related components.
* In contrast to Doctrine_Record::save(), this method does not
* throw an exception when validation fails but returns TRUE on
* success or FALSE on failure.
*
* #param Doctrine_Connection $conn optional connection parameter
* #return TRUE if the record was saved sucessfully without errors, FALSE otherwise.
*/
public function trySave(Doctrine_Connection $conn = null) {
try {
$this->save($conn);
return true;
} catch (Doctrine_Validator_Exception $ignored) {
return false;
}
}
}
you can check by $contact_obj->getId() function, it will return the inserted id on success.

How come I cannot access the public enum of another class as a static field?

I have an enum in a file:
goog.provide('animals.Fish');
animals.Fish = function(obj) {
this.name_ = obj[animals.Fish.Properties.NAME];
this.awesomenessLevel_ = obj[animals.Fish.Properties.AWESOMENESS];
}
/**
* Public list of properties.
* #enum {string}
*/
animals.Fish.Properties = {
NAME: 'name',
AWESOMENESS: 'awesomenessLevel',
}
How come I can't access this enum as a static field of Fish in another class like this?
goog.require('animals.Fish');
...
var tuna = new animals.Fish(
animals.Fish.NAME: 'tuna',
animals.Fish.AWESOMENESS: '100'
)
...
Closure enumeration types are based on the concept of Enum Types from languages such as Java and C++. In Java, enum types are defined as follows:
An enum type is a type whose fields consist of a fixed set of constants. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.
In your example above, animals.Fish.Properties should probably be represented as a record type, since the assigned values are not constants. In the example below, animals.Fish.Properties has been renamed animals.Properties so that it could be applied to any type of animal (not just fish).
fish.js
goog.provide('animals.Fish');
goog.provide('animals.Properties');
/** #typedef {{name: string, awesomeness: string}} */
animals.Properties;
/**
* #param {animals.Properties} properties Animal properties.
* #constructor
*/
animals.Fish = function(properties) {
/** #type {string} */
this.name_ = properties.name;
/** #type {string} */
this.awesomenessLevel_ = properties.awesomeness;
};
/**
* #return {string} The name of the fish.
*/
animals.Fish.prototype.getName = function() {
return this.name_;
};
animals_app.js
goog.provide('animals.app');
goog.require('animals.Fish');
animals.app.tuna = new animals.Fish({name: 'tuna', awesomeness: '100'});
alert(animals.app.tuna.getName()); // alerts 'tuna'
On a side note, in the original example there should not be a comma after: AWESOMENESS: 'awesomenessLevel' in the definition of animals.Fish.Properties. In addition, in your second file you need to use the fully qualified enum name. So instead of animals.Fish.NAME it would be animals.Fish.Properties.NAME.

Resources